Basic Bluetooth bit:bot

Overview

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:

Equipment

Setting Up The micro:bit

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.

Setting Up the Raspberry Pi

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

Getting the Bluezero microbit library

You will need to get the source of the library from https://github.com/ukBaz/python-bluezero

Commands

CommandDescription
connectConnect to the specified microbit for this instance
disconnectDisconnect from the microbit
spin_rightSpin right wheel forward and left wheel backwards so bit:bot spins
spin_leftSpin left wheel forward and right wheel backwards so bit:bot spins
forwardSpin both wheels forward
reverseSpin both wheels backwards
stopStop both wheels of the bit:bot
buzzer_onPlay the buzzer
buzzer_offStop the buzzer

Example

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()

license