The excellent Python MU editor makes it so easy to get BBC micro:bits talking to each other using simple radio data communication. No magic required, just physics.
After attending a brilliant talk / demo about the MU editor by Nicholas Tollervey, I came away feeling inspired. I thought I would have a go myself and in no time I had 2 microbits sending data to each other wirelessly.
I wrote some simple code based on an example by Nicholas Tollervey. First to send an image when pressing button ‘A’ between micro:bits.
- from microbit import display, button_a, Image
- import radio
- radio.on()
- while True:
- message = radio.receive()
- if message:
- display.show(Image.DUCK)
- if button_a.was_pressed():
- display.clear()
- radio.send("hello")
I present my magical teleporting duck, prepare to be amazed. #bbcmicrobit pic.twitter.com/9CG0CkhYdw— Thomas Stratford (@MrTomsWorld) 26 October 2016
Next I thought it would be fun to add some neopixels. When button A is pressed the neopixels show red then amber on the sending microbit and green plus the image on the receiving microbit.
- from microbit import *
- import radio
- import neopixel
- np = neopixel.NeoPixel(pin0, 1)
- green = (0, 255, 0)
- red = (255, 0, 0)
- orange = (255, 153, 0)
- radio.on()
- while True:
- # Read any incoming messages.
- message = radio.receive()
- if message:
- np[0] = (green)
- np.show()
- display.show(Image.DUCK)
- sleep(3000)
- np.clear()
- # Button A sends a "flash" message.
- if button_a.was_pressed():
- np [0] = (red)
- np.show()
- sleep(1000)
- np [0] = (orange)
- np.show()
- sleep(1000)
- np.clear()
- display.clear()
- radio.send("hello")
New and improved magical teleporting duck, complete with neopixels... #microbit #bbcmicrobit pic.twitter.com/PHqdaML9qD— Thomas Stratford (@MrTomsWorld) 27 October 2016
To connect the neopixels you’ll need to attach them to the micro:bit as below.
You will need:
2 x BBC micro:bits
2 x Neopixels ( I used Crumble Sparkles )