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