Rather than programming the micro:bit on the bit:bot I decided to use the
Bluetooth profile for the micro:bit
to control the pins remotely from a Raspberry Pi.
I did a little video demo of it at:
Thanks to Bitty Software this is very easy as they have done a hex file for the micro:bit that exposes all of the Bluetooth services we need. This was created for their micro:bit blue app (you should check the app out as it is very good). You can download the hex file from their webiste. You will need to look for "Main Bluetooth services, pairing not required" link for the download. The loading of the hex file is standard for the micro:bit.
First time you start the micro:bit with this hex file it will get you to draw a circle. This is to calibrate the magnetometer. Once that is done you are done on the micro:bit.
This is a little bit more involved as you will require a newer version of BlueZ (the Linux Bluetooth stack) than comes as default with the Raspberry Pi. The full instruction are available in the Bluezero repository.
Make sure you take care to follow the instructions in the note if you have a Raspberry Pi 3
You will need to get the source of the library from https://github.com/ukBaz/python-bluezero
Command | Description |
---|---|
connect | Connect to the specified microbit for this instance |
disconnect | Disconnect from the microbit |
spin_right | Spin right wheel forward and left wheel backwards so bit:bot spins |
spin_left | Spin left wheel forward and right wheel backwards so bit:bot spins |
forward | Spin both wheels forward |
reverse | Spin both wheels backwards |
stop | Stop both wheels of the bit:bot |
buzzer_on | Play the buzzer |
buzzer_off | Stop the buzzer |
from time import sleep
from bluezero import microbit
bitbot = microbit.BitBot(name='micro:bit')
bitbot.connect()
bitbot.buzzer_on()
sleep(0.5)
bitbot.buzzer_off()
sleep(0.5)
bitbot.spin_right()
sleep(1)
bitbot.spin_left()
sleep(1)
bitbot.forward()
sleep(1)
bitbot.reverse()
sleep(0.5)
bitbot.stop()
bitbot.disconnect()