Third party cookies may be stored when visiting this site. Please see the cookie information.

Home Family Days Out Raspberry Pi & Electronics Blog

Stewart's Blog

Stewart Watkiss website to the world ...

(Children, computing, first aid and other ramblings ...)

Controlling a Raspberry Pi robot using the micro:bit accelerometer

The BBC micro:bit includes an accelerometer which allows you to track the movement of the micro:bit. This means that it can be used to as a controller similar to how the Wii remote control tracks it’s movement through the air. For this project I used the micro:bit as a wired device to control my existing Raspberry Pi robot. In theory it should be possible to have it communicating via the built-in bluetooth v4 controller (also known as Bluetooth Low Energy / BLE).

As I didn’t want to be physically tethered to the robot I used another computer to act as a proxy / relay server to receive the status of the micro:bit and then pass it on to the Raspberry Pi on the robot. This computer could be any Linux computer, such as another Raspberry Pi (or a PiZero, but that will require a USB hub).

The messages between the micro:bit and the Raspberry Pi were passed using a serial connection. I had already included a web interface on the Raspberry Pi robot, I had the relay perform a url-get against the web page of the Robot using the python urllib module.

BBC Micro:bit running MicroPython controlling a Raspbhttp://erry Pi robot

Most of the code to read the status of the accelerometer and convert that into something the Raspberry Pi could understand has been written in MicroPython on the micro:bit. It may have been slightly easier to have the proxy computer perform that, but this was more of an exercise in programming the micro:bit.

There is little to no error checking in this, which is something that should be considered in future. The serial communication did work OK most of the time, but would occasionally drop some of the information resulting in an error message.

The source code is available from github at: penguintutor github MicroPython on the BBC micro:bit. There are two files, microbit-webrobot.py which should be installed on the micro:bit (converted to a hex file first) and pc-webrobot-proxy.py which runs on the Linux computer (may need to be run as root using sudo – or setup appropriate dialout permissions).

Please leave comments using the facebook comments below.


UK days out, children and holiday information is also available on the Days Out Diary web site
Linux, LPI and the Quiz / Test Program posts are also available on the Penguin Tutor website
First Aid Information, first aid games and first aid practice test / quiz entries are also available on the First Aid Quiz Web site