Wednesday, 9 August 2017

BitIO Blog 6: 'Touching pins....takes you places'


Part 2: Touching pins.....takes you places.



This takes the basic 'touched.py' demo from David Whales BitIO master available here:

As ever if you have not quite noticed may playground is Minecraft. This version builds on from the previous blog about 'touching pins'
(http://warksjammy.blogspot.co.uk/2017/08/bitio-blog-5-touch-pins.html)

In this version you will touch a Micro:bit pin 0-2 and either:

  • pin 0- build the world map in Minecraft.
  • pin 1- teleport to England.
  • pin 2- teleport to the USA.



To "touch a pin" you will need to touch pin 0 for example with one finger and complete the circuit by touching the 'gnd' pin and then the code will work. 

Here is a link to a video of what touching pins basic code does:
https://twitter.com/Warksraspijam/status/895355608404242436

Here is a photo of how it will look:

Here is the link to the simple version code:
Teleportation and pin reading code

Build world code:

Data file:

Credit Damien Mooney's world building code:
https://damianmooney.wordpress.com/2016/02/16/raspberry-pi-minecraft-iss-tracker/

Instructions:
1. Plug your Micro:bit into the Pi/PC.
2.   Ensure that you have read blog 1:
http://warksjammy.blogspot.co.uk/2017/07/blog-1-getting-started-with-bitio.html
and downloaded the BitIO master files from David Whales github

3. Go into the 'Bitio master' folder, find the 'src' folder 
4. Create a new Python 3 script.
5. Call it "touching pins takes you places.py"
6. Type in the following code:

Code
# touched.py - demonstrates using pin touch

import microbit

from mcpi import minecraft as minecraft
from mcpi import block as block
from datetime import datetime
import time
import serial
import random
import BuildWorldDM as bw

WoolList =[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
EngX = 1.0
EngZ = 50.0

UsaX = 53.8
UsaZ = 39.7
 
mc = minecraft.Minecraft.create()
  
def Teleport(x,z,Country):
    mc.player.setPos(x,20,z)
    mc.camera.setFollow()
    mc.setBlock(x,1, z,35,random.choice(WoolList))
    mc.postToChat(Country)


while True:
    time.sleep(1)
    if microbit.pin0.is_touched():
        print("Pin 0 touched, build world")
        bw.Build()
    elif microbit.pin1.is_touched():
        print("Pin 1 touched, teleport to England")
        Teleport(EngX,EngZ,"England")
    elif microbit.pin2.is_touched():
        print("Pin 2 touched, teleport to the USA") 
        Teleport(UsaX,UsaZ,"USA")



8. Open Minecraft, create a new world.
9. Run the code by pressing f5.
10. Try touching pin 0, what happens. Now try pin 1 and 2.

Extension:
Try adding in extra countries.


You can now download a pdf version of these tutorials as part of the updated #hackpack resource booklet here:
https://github.com/ncscomputing/HpAnthologyV2/raw/master/Hackpack%20Anthology%20V2%200.3.pdf




If you like this blog check out all the others here


BitIO blog 5: Touch the pins......

Part 1: Touching pins.....dropping blocks



This takes the basic 'touched.py' demo from David Whales BitIO master available here:

As ever if you have not quite noticed may playground is Minecraft. So in this simple version you will drop different wool blocks according to the pin that you touch. To "touch a pin" you will need to touch the metal end of the cable attached to the pin and then touch the ground pin to complete the circuit and for the code to work. It took me ten minutes to figure this out.


Here is a link to a video of what touching pins basic code does:

Here is a photo of how the pins were set up during the video:

Here is the link to the simple version code:

Instructions:
1. Set up the 3 cables as above on the Micro:bit
2. Plug your Micro:bit into the Pi/PC.
3.   Ensure that you have read blog 1:
http://warksjammy.blogspot.co.uk/2017/07/blog-1-getting-started-with-bitio.html
and downloaded the BitIO master files from David Whales github

4. Go into the 'Bitio master' folder, find the 'src' folder 
5. Create a new Python 3 script.6. Call it "touched_simple.py"
7. Type in the following code:

Code
# touched.py - demonstrates using pin touch

import microbit
from mcpi import minecraft as minecraft
from mcpi import block as block
import time
import random

WoolList = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]

 
mc = minecraft.Minecraft.create()
 

while True:
    
    time.sleep(1)
    if microbit.pin0.is_touched():
        msg = "Pin 0 touched, Wool block colour 0"
        print(msg)
        mc.postToChat(msg)
        pos = mc.player.getTilePos()
        mc.setBlock(pos.x, pos.y-1, pos.z,35,0)
    if microbit.pin1.is_touched():
        msg = "Pin 1 touched, Wool block colour 1"
        print(msg)
        mc.postToChat(msg)
        pos = mc.player.getTilePos()
        mc.setBlock(pos.x, pos.y-1, pos.z,35,1)
    if microbit.pin2.is_touched():
        msg = "Pin 2 touched, Wool block colour 2"
        print(msg)
        mc.postToChat(msg)
        pos = mc.player.getTilePos() 
mc.setBlock(pos.x, pos.y-1, pos.z,35,2)

8. Open Minecraft, create a new world.
9. Run the code by pressing f5.
10. Try touching pin 0, what happens.

Extension:
Try changing the block ID's


You can now download a pdf version of these tutorials as part of the updated #hackpack resource booklet here:
https://github.com/ncscomputing/HpAnthologyV2/raw/master/Hackpack%20Anthology%20V2%200.3.pdf


If you like this blog check out all the others here

Sunday, 6 August 2017

BitIO tutorial 4:Tilt me ‘Around the World’



This takes the basic 'tilt_mc.py' demo from David Whales BitIO master available here:
https://github.com/whaleygeek/bitio


Credit to Damien Mooney for the world rendering script:
https://damianmooney.wordpress.com/2016/02/16/raspberry-pi-minecraft-iss-tracker/

In the second blog and third blog I extended the basic demo to drop random wool blocks where ever you tilted the Micro:bit and in tutorial three I extended this to lay a road of sorts. 


                                                                           
Blog 2   
(http://warksjammy.blogspot.co.uk/2017/07/blog-2-extending-accelerometer-demo.html) 


Blog 3



In this blog post we will hike up the challenge to combine both push buttons in addition to the accelerometer.

Section 1 of the code:

If you press the a button on the Micro:bit then a data file is read and world map is then rendered into the Minecraft world. You can then use the accelerometer to navigate the character around the map by tilting the Micro:bit.

Here is a video to show this in action:

https://twitter.com/ncscomputing/status/885213278007328772


Section 2 of the code:
If you press the B button then the character teleport's to predetermined locations on the map. Here is a video of this in action:

https://twitter.com/Warksraspijam/status/894492363330113540

Here are some static images:








The files you will need are here should you not want to code the BitIO python file:
Files:
World map data file:

Build world library:

BitIO file:
https://github.com/ncscomputing/HpAnthologyV2/blob/master/blog4AWACC.py

If you do want to have a go at making the BitIO file then here are your instructions:

This is what the code will do:

Instructions
1. Ensure that you have read blog 1:
http://warksjammy.blogspot.co.uk/2017/07/blog-1-getting-started-with-bitio.html
and downloaded the BitIO master files from David Whales github

2. Go into the 'Bitio master' folder, find the 'src' folder and save 'World map data file' and  'Build world library' from the links above into that folder.

3. Create a new Python 3 script and type out the following:
  


Code


#“Written by : @ncscomputing /@warksraspijam”
 
from mcpi import minecraft as minecraft
from mcpi import block as block
from datetime import datetime
import time
import random
import BuildWorldDM as bw

###
"""
Written by @ncscomputing on top of the bitio produced by David Whale
https://github.com/whaleygeek/bitio

world building code imported library from Damien Mooney's blog:
https://damianmooney.wordpress.com/2016/02/16/raspberry-pi-minecraft-iss-tracker/

"""
import serial
from mcpi.minecraft import Minecraft
import time
from mcpi import block as block
import random


mc = Minecraft.create()


# button.py - demonstrates using a button

import microbit

print("micro:bit connected - press button A to test")
WoolList = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
 
EngX = 1.0
EngZ = 50.0
 
UsaX =  53.8
UsaZ = 39.7
 
CanadaX = 59.0
CanadaZ = 61.3
 
IceLandX = 10.0
IceLandZ = 61.1



def Teleport(x,z,Country):
    mc.player.setPos(x,20,z)
    mc.camera.setFollow()
    mc.setBlock(x,1, z,35,random.choice(WoolList))
    mc.postToChat(Country)

while True:
    time.sleep(0.25)
    #=======buildworld call when a button pressed
    if microbit.button_a.was_pressed():
        mc.postToChat("Button A pressed: build world")    
        print("Button A pressed: build world")

        bw.Build()
        time.sleep(2)
 
        microbit.display.show("build world")


    # manual teleport using acceleromter readings
    pos = mc.player.getTilePos()
    x = microbit.accelerometer.get_x()/300 # -ve=left/+ve=right
    y = microbit.accelerometer.get_y()/300 # -ve=forward/+ve=backward

    pos.x += x # east/west
    pos.z += y # north/south

    mc.player.setTilePos(pos.x, pos.y, pos.z) # set player position

    #time.sleep(0.5)
    #=========
    if microbit.button_b.was_pressed(): 
        print ("Button B pressed: Manual teleport")
        mc.postToChat("Button B pressed: Teleport")  
        time.sleep(0.5)
        Teleport(EngX,EngZ,"England")
        time.sleep(8)
        Teleport(UsaX,UsaZ,"USA")
        time.sleep(8)
        Teleport(CanadaX,CanadaZ,"Canada")
        time.sleep(8)
        Teleport(IceLandX,IceLandZ,"Iceland")
        time.sleep(8)

4. Save it as something.py in the same 'src' folder as the previous files.
5. Open Minecraft, create a new world.
6. Make sure your Micro:bit is plugged in to your PC/Pi.
7. Run the python file that you created above.
8. Try pressing the 'a' button let it build the world map.
9. Try using tilting the Micro:bit to see if you can navigate around the world map.
10. Now try and press the 'b' button and see if the teleportation works.

Extension:

Try extending the teleportation code to go to extra countries on the word tour.

Enjoy :)


You can now download a pdf version of these tutorials as part of the updated #hackpack resource booklet here:







If you like this blog check out all the others here





Monday, 24 July 2017

BitIO Blog 3: Extending the accelerometer 'Tilting Rainbow Road'



This takes the basic 'tilt_mc.py' demo from David Whales BitIO master available here:
https://github.com/whaleygeek/bitio

In the second blog the 'tilt_mc.py' demo was extended to:

1. Use a list to randomly select a wool block.
2. Drop this block underneath the player the end result is a colourful mess. :) (See below)

The code was saved in the 'src' folder to work and did this >>>


This third blog will extend this further to drop a roads worth of blocks each time the character is moved from a tilt of the Micro:bit. The end result will look like this:



Again you will use the accelerometer to move player and it will drop the road to the left of the character. The code will need to be saved in the src folder. (This is all explained in blog 1)  Here is the code (a marginally more complex version of the previous blog):

Code:
#Original written by David Whale located here as part of his BITIO library
#https://github.com/whaleygeek/bitio/blob/master/src/tilt_mc.py
#adapted by @ncscomputing 20/07/17


import mcpi.minecraft as minecraft
import mcpi.block as block
import microbit
import time
import random




mc = minecraft.Minecraft.create()

blocksList = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
time.sleep(7)
mc.postToChat("Rainbow Road 3.0 Micro:bit controlled")
while True:
    pos = mc.player.getTilePos()
    x = microbit.accelerometer.get_x()/300 # -ve=left/+ve=right
    y = microbit.accelerometer.get_y()/300 # -ve=forward/+ve=backward

    pos.x += x # east/west
    pos.z += y # north/south

    Count = 1
    while Count <=16 :
        mc.player.setTilePos(pos.x, pos.y, pos.z)
        mc.setBlock(pos.x-Count, pos.y-1, pos.z,35,Count)
        Count = Count+1
    time.sleep(0.25)

Download the code from here:
https://raw.githubusercontent.com/ncscomputing/HpAnthologyV2/master/Rainbow%20road%20tilt.py



You can now download a pdf version of these tutorials as part of the updated #hackpack resource booklet here:
https://github.com/ncscomputing/HpAnthologyV2/raw/master/Hackpack%20Anthology%20V2%200.3.pdf

Enjoy :)


If you like this blog check out all the others here

BitIO blogs in one place




All the BitIO blog in 1 place. 

This series started as a way of exploring what happened when you connected a micro:bit to Minecraft using BitIO. What began as a few simple experiments quickly grew into a collection of projects covering everything from moving around the Minecraft world with the accelerometer, to creating pixel art, visualising data and building interactive worlds through code.

Although BitIO is now a snapshot of a particular moment in the evolution of the micro:bit, the ideas behind these projects are still just as relevant. They show that coding doesn't have to be confined to a screen—it can be creative, playful and a brilliant way of learning programming by making things.

Hopefully these projects give you a few ideas of your own. If they do, don't stop here. Many of the ideas in this series evolved into later experiments with Raspberry Pi, LEGO, Minecraft Education Edition and, more recently, AI. Take a look at the 2026 onwards landing page where you'll find the complete collection of projects and experiments organised by topic.  



New adventures here >>> link

Here you will find a central resource to all blogs that are written about using BitIO over the next few weeks /months:

Blog 1: Getting Started with BitIO
http://warksjammy.blogspot.co.uk/2017/07/blog-1-getting-started-with-bitio.html

Blog 2: Extending the Accelerometer demo: Walking Rainbow Blocks
http://warksjammy.blogspot.co.uk/2017/07/blog-2-extending-accelerometer-demo.html

Blog 3: Extending the accelerometer 'Tilting Rainbow Road'
http://warksjammy.blogspot.co.uk/2017/07/bitio-blog-3-extending-accelerometer.html

Blog 4: 'Tilt me around the world'
http://warksjammy.blogspot.co.uk/2017/08/blo.html

Blog 5: 'Touching pins..... simple'
http://warksjammy.blogspot.co.uk/2017/08/bitio-blog-5-touch-pins.html

Blog 6: 'Touching pins takes you places'
http://warksjammy.blogspot.co.uk/2017/08/bitio-blog-6-touching-pinstakes-you.html

Blog 7: ''Minecraft CPU temperature graphing"
http://warksjammy.blogspot.co.uk/2017/09/bitio-blog-7-minecraft-cpu-temperature.html

Blog 8: Accelerometer in Space.
http://warksjammy.blogspot.co.uk/2017/12/virtual-jam-blog-3-bitio-blog-8space.html#!/2017/12/virtual-jam-blog-3-bitio-blog-8space.html

Blog 9: PixelCraft

http://warksjammy.blogspot.com/2018/01/bitio-blog-9-pixelcraft-this-uses-david.html

Blog 10: Micro:bit Transport

http://warksjammy.blogspot.co.uk/2018/01/bitio-blog-10-microbit-transport.html

Blog 11: Pixel Craft 2.0

http://warksjammy.blogspot.com/2018/01/bitio-blog-11-pixelcraft-20.html

Blog 12: Pixel Cakes(RPI big birthday weekend resource)
http://warksjammy.blogspot.com/2018/02/rpi-big-birthday-weekend-pixel-cakes.html

Blog 13: "Push button racing"
https://pi-resources.me/2018/03/04/racing/

Blog 14: Scalable Housing
http://warksjammy.blogspot.com/2018/04/bitio-blog-14-scalable-housing.html




Blog 15: Edublocks BitIO
link


16 Introduction to Scratchy:bit IO
link







If you like this blog check out all the others here









You can now download a pdf version of these tutorials as part of the updated #hackpack resource booklet here:
https://github.com/ncscomputing/HpAnthologyV2/raw/master/Hackpack%20Anthology%20V2%200.3.pdf

BitIO Blog 2: Extending the Accelerometer demo: Walking Rainbow Blocks



This takes the basic 'tilt_mc.py' demo from David Whales BitIO master available here:
https://github.com/whaleygeek/bitio

In the first blog the demo moves the character around the screen according to the direction you tilt the Micro:bit. The code below extends this to:

1. Use a list to randomly select a wool block.
2. Drop this block underneath the player the end result is a colourful mess. :) (See below)

The code will need to be saved in the 'src' folder to work.



Below is the code, you can download it here:
https://github.com/ncscomputing/HpAnthologyV2/raw/master/Walking%20tilt.py



Code:

#Original written by David Whale located here as part of his BITIO library
#https://github.com/whaleygeek/bitio/blob/master/src/tilt_mc.py
#adapted by @ncscomputing 19/07/17


import mcpi.minecraft as minecraft
import mcpi.block as block
import microbit
import time
import random




mc = minecraft.Minecraft.create()

blocksList = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]

while True:
    pos = mc.player.getTilePos()
    x = microbit.accelerometer.get_x()/300 # -ve=left/+ve=right
    y = microbit.accelerometer.get_y()/300 # -ve=forward/+ve=backward

    pos.x += x # east/west
    pos.z += y # north/south

    mc.player.setTilePos(pos.x, pos.y, pos.z)
    mc.setBlock(pos.x, pos.y-1, pos.z,35,random.choice(blocksList))
 


   # time.sleep(0.5)


Enjoy :)

You can now download a pdf version of these tutorials as part of the updated #hackpack resource booklet here:
https://github.com/ncscomputing/HpAnthologyV2/raw/master/Hackpack%20Anthology%20V2%200.3.pdf



If you like this blog check out all the others here

Sunday, 23 July 2017

Blog 1: Getting Started with BitIO




David Whale has developed the BitIO library. It essentially lets you code your Microbit in normal Python 3.

Last summer I created these resources for Micro:bit:

http://warksjammy.blogspot.co.uk/2017/04/cpc-ucreate-microbit-resources-all-in.html

These were a mostly micro python using MU IDE. Some involved using the serial connection from Micro:bit and a Raspberry Pi. This again built on top of the technical feats of David Whale.

Each program involved a Micro python program which sat on the Micro:bit and then a separate Python program that then interpreted the data sent by the Micro:bit. This was technically possible but elongated.

David has essentially stripped out much of the complexity. Now there is a generic hex file which sits on the Micro:bit. The only coding that you do is in Python 3.


Here are the steps to get a simple demo working:

1. Go to Davids github:
https://github.com/whaleygeek/bitio

2. Look on the far right of the webpage for a green box which says 'clone or download'. Then click 'Download Zip'. Then save the zip file to your Pi.

3.  Using the file manager find the downloaded Zip file and extract it.

4. Now plug in your Micro:bit to the Pi. Go into the Bitio master folder and you will find a hex file called 'bitio.hex'. Copy this and paste it onto the Micro:bit. This should now be flashed.

5.  Go to the Bitio master folder and find the src folder. You will see several examples. The one that we will test uses the accelerometer to control the position of the player in Minecraft.

6. The file is called 'tilt_mc.py' open this in Python 3.

7. Open Minecraft and create a new world. Press f5 to run it the Python script.

8. The following dialogue will display in the Python shell window:

No micro:bit has previously been detected
Scanning for serial ports
remove device, then press ENTER

9. So unplug the Micro:bit and press enter.

10. Next the following text will display:

scanning...
found 67 device(s)
plug in device, then press ENTER 

11. Now press enter and the following text will display:

scanning...
found 68 device(s)
found 1 new device
selected:/dev/ttyACM0
Do you want this device to be remembered? (Y/N)

12. Press enter to confirm and the following text will display:

Your micro:bit has been detected
Now running your program


13. If you pick up your Micro:bit then and open Minecraft you should see the player move according to the direction you are tilting the Micro:bit.


You can now download a pdf version of these tutorials as part of the updated #hackpack resource booklet here:
https://github.com/ncscomputing/HpAnthologyV2/raw/master/Hackpack%20Anthology%20V2%200.3.pdf



If you like this blog check out all the others here