Simple radio data communication using BBC micro:bits

The excellent Python Mu editor makes it a doddle to get micro:bits talking to each other wirelessly – check out the awesome firefly project on this page.

I thought I’d have a go myself, and in no time at all turned 3 Microbits into little glowing, wirelessly-communicating bugs.

Next I had a go at writing some code of my own, first just to send ‘A’ and ‘B’ button presses between micro:bits:

import radio
from microbit import display, button_a, button_b

radio.on()

while True:
    # Buttons send letters
    if button_a.was_pressed():
        radio.send('A')
    if button_b.was_pressed():
        radio.send('B')
    # Read incoming messages
    incoming = radio.receive()
    if incoming == 'A':
        display.show('A')
    if incoming == 'B':
        display.show('B')

Then I had a go at sending Morse code – here the A button sends dots, the B button sends dashes. There’s a bit of a delay (300 milliseconds) before the screen blanks so you can see discrete dots and dashes. Next step is to mash this up with a wired morse code project so it will automatically decode messages and display them!

import radio
from microbit import display, button_a, button_b, sleep

radio.on()

while True:
    # Buttons sends a message.
    if button_a.was_pressed():
        display.show('.')
        radio.send('.')
    if button_b.was_pressed():
        display.show('-')
        radio.send('-')
    # Read any incoming messages.
    incoming = radio.receive()
    if incoming == '.':
        display.show('.')
    if incoming == '-':
        display.show('-')
    sleep(300)
    display.show(' ')
This entry was posted in computers, education, ICT and tagged , , . Bookmark the permalink.

Leave a Reply