Bluetooth and the Micro:bit
When I experimented with the first version of the Micro:bit a while
ago, it had a primitive Micro:bit-to-Micro:bit version of Bluetooth.
Enter the following Python code into one of your devices, to
transmit its orientation to the other:
from microbit import *
import radio
radio.on()
#display.show('go')
#radio.config(channel=19) # Set the channel number to 19
radio.config(power=1) # Set the power level to 1
while True:
readingy = accelerometer.get_y()
readingx = accelerometer.get_x()
#print(readingx)
#sleep(100)
if readingy > 550:
display.show(Image.ARROW_S)
radio.send('b')
sleep(50)
elif readingy < -550:
display.show(Image.ARROW_N)
radio.send('f')
sleep(50)
elif readingx < -550:
display.show(Image.ARROW_W)
radio.send('l')
sleep(50)
elif readingx > 550:
display.show(Image.ARROW_E)
radio.send('r')
sleep(50)
else:
display.show("S")
radio.send('o')
sleep(50)
Enter this code into the other one to receive it
from microbit import *
import radio
radio.on()
#radio.config(channel=19) # Set the channel number to 19
#radio.config(power=1) # Set the power level to 1
while True:
msgin = radio.receive()
if msgin is not None:
if msgin == 'f':
display.show(Image.ARROW_N)
elif msgin == 'b':
display.show(Image.ARROW_S)
elif msgin == 'l':
display.show(Image.ARROW_W)
elif msgin == 'r':
display.show(Image.ARROW_E)
elif msgin == 'o':
display.show("O")
else:
display.show("R")
sleep(50)
Well it is not elegant and does not tell you much about the
communication, except that it exists.
But in the meantime, groups have been busy developing fully fledged
Bluetooth communication that can pair with any gadget.
Have a look at Bluetooth
(microbit.org) to see much more.