Upgrade your Raspberry Pi 3 with a BBC Micro:bit
If you have used a Raspberry Pi, you will know how powerful of development board it is. So how does it compare with the BBC Micro:bit? The short answer is that the Raspberry Pi is way out the league compared to the Micro:bit.
Raspberry Pi vs BBC Micro:bit
If the Raspberry Pi is a proper computer, then the BBC Micro:bit teaches the raw building blocks of coding. The Raspberry Pi 3 is a much more advanced and practically useful device, but if you or your kid is starting at the very beginning of your programming journey, the BBC Micro:bit looks hard to beat.
Even though the Raspberry Pi is the clear winner in terms of performance and connectivity, the micro:bit has many input and output onboard peripherals, unlike the Raspberry Pi. The micro:bit comes with LED Matrix Display, Push Buttons, Capacitive Touch Buttons, Accelerometer, Magnetometer, Light Sensor and Radio Communication. In this blog, we are going to look at how to interface the micro:bit with a Raspberry Pi and get the best of both the worlds.
Let’s Upgrade our Raspberry Pi 3
Reading from and writing to the micro:bit from a Raspberry Pi is really simple, as the Mu MicroPython editor for the microbit is supported in Raspberry Pi. What it means is that you can program the microbit, using the Raspberry Pi just like how you program it on a PC.
To install the Mu editor in your Raspberry Pi, open the terminal and type the following command
sudo apt-get update && sudo apt-get -y install mu
The micro:bit can be connected to the USB port of the Raspberry Pi and now be programmed using Mu editor. To read data from the BBC micro:bit, you need to have it running its own program and sending the results to the raspberry pi via serial communication. For that, you need to set up the BBC micro:bit, so it’s constantly taking readings from one of its sensors or pins. The microbit uses the serial USB port to send results to the REPL of the Mu editor. Thus, just printing the values in the REPL is enough for the sensor data to flow to the Raspberry Pi. The next step is to collect this data directly from the serial device. To get started, you first need to find out the device name the BBC micro:bit is using. Open the terminal and type the following
dmesg | tail -20 | grep ttyACM
This will return the microbit’s serial device name as shown here:
Now, to collect the data from the microbit: Type the following command in the terminal
screen /dev/ttyACM0 115200
Make sure you change the device name to your own serial device name. Here the number 115200 is the baud rate at which the microbit is sending the data.
What can you do with this data you might ask? You can send this data to the cloud by using the Raspberry Pi as a Gateway. Furthermore, you may utilize the Radio functionality of the micro:bit to connect to other micro:bits in its range, and form a mesh network with Raspberry Pi as a Gateway Hub to the cloud. Thus the possibilities are endless.