Looking at my distributed BBC micro:bit clock I got to thinking, could I make a display screen using a number of micro:bits, using the radio functionality to update the screens ?To see if the basic timing would work I created some very rudimentary code on 4 micro:bits. Initially I tried to use the ‘display.scroll’ function. After much fiddling I did get this to work after a fashion, but in truth it looked rubbish. On the point of giving up I thought I would see what it would look like using the ‘display.show’ function. This produced a much more readable result so I decided to go on and develop some ‘proper code’. I had previously looked at with David Whale’s python ‘microbit’ module and this seemed a great way to get the text strings ‘into’ the micro:bit. which solved the problem of how to front end the display. The remaining s/w built used in my distributed micro:bit clock.
The software for the scrolling display has 3 elements;
[the pink x in the names indicates the rev number where I plan to develop the s/w further]
1) The micro:bit display node application [node_scroll_showx.py]
This is a simple python app you need to download on to each of the micro:bits that form the message display. The s/w for each micro:bit is identical. The software listens using using the radio function for any messages addressed to it coming from the gateway micro:bit displaying any valid character using the display.show function. It will keep displaying this until it receives a new valid message. The address of each display node is set the first time the s/w is run (normally this would be directly after download). The micro:bit will display a ‘?’, to show the address needs to be configured. The address is set using button ‘a’ and once correct store it using button ‘b’ – the address is stored in non volatile memory. On subsequent restarts it will be automatically selected, but you can change it by holding down button ‘a’ and resetting the micro:bit.
2) the micro:bit scroll display gateway application [gate_scroll_rx.py]
This is a somewhat more complex python app, performing 4 functions receiving messages from the Pi, creating the scroll effect, segmenting the message and finally transmitting the individual character information to the display node micro:bits.
Information is received from the Pi via a USB connection, this is described further in the RPi gateway application section.
The basic message format is <type><message>. ‘type’ is either ‘1’ to display a static message or ‘2’ for a scrolling message. So for examples if the gateway micro:bit receives the following message ‘2HELLO WORLD’ you would see ‘HELLO WORLD’ scrolled across the display node micro:bits. This would be repeated until the next message is received.
Static messages are automatically truncated to the number of characters in the display. If you want to see how the scroll process works the best way is to look at the python code but in simple terms I create a shift register in s/w and simply cycle it.
Setting the number of nodes
The gateway micro:bit needs to know how many display nodes it is talking to, this is set the first time the s/w is run (normally this would be directly after download). The gateway micro:bit will display a ‘D’, to show the number of nodes needs to be configured. This is set using button ‘a’ and once correct stored using button ‘b’ – the number is stored in non volatile memory. On subsequent restarts it will be automatically selected, but you and change it by holding down button ‘a’ and resetting the micro:bit.
3) The RPi gateway applications
The gateway application running on the RaspberryPi communicates with the micro:bit gateway via a USB connection, using a python module called ‘microbit’ (thanks to David Whale) for telling me about this – here is a link to his github. To date I have just written a few demo applications using the microbit module. When you first run an application using the microbit module it will take you through a setup process to allow the s/w to identify USB connection name. It will attempt to use this name for future connections. If this fails you will need to go through the identification process again, you may also need to restart the Raspberry Pi. The 4 apps I have currently uploaded on to GitHub are;
- A simple program to display a user inputted string, [gateway1.py]
- A clock demo [gatewaytime_date.py]
- A Tweepy application which will scroll any messages with a specific prefix. [tweepy8a_microbitxx.py]
- A basic GUI that allows you to scroll / show strings or display time in a range of formats [scroll_GUIx.pyw]
The GUI app is my first real attempt to use Tkinter and I am sure I have broken a number of, but it seems to work and was interesting to code
One of my goals in developing the scrolling display was to avoid any extra hardware or the need for expensive sockets etc. To get the best effect the node micro:bits need to be mounted in a straight line as close together as possible. The mounting board I used is just a bit of fibre board I had spare. Having worked out the required spacing I drilled a series of 3mm hole, then used 2.5mm stand-offs and screws to mount using just the 0v and 3v ‘holes’. Using 3mm holes with 2.5mm screws gave a bit of ‘slop’ to get everything aligned neatly. You can find a copy of the dimensions I drilled to at the end of this post.
Initially I just used individual batteries to power each micro:bit. Once I was happy the with the mechanical arrangement I found a suitably rated 3.3v supply and changed to power the node micro:bits via the GND and 3v pins – if you go down this route you need to be very careful as an error here could end up destroying all the node micro:bits. Also most importantly you have to include a diode on the 3V line.
This stops a micro:bit ‘back powering’ all the others when you are downloading code to it via the USB line – I am guessing the USB supply on the micro:bit is not rated to drive 10 micro:bits ! You can see how it is wired up in the picture below
You can have a look at some short videos of the scroll display working on my YouTube channel