Radio-Receive Tilt
The radio_tilt_receive_test script is a modified version of countdown_receiver from the Cybersecurity: Radio Data’s Send and Receive Packets activity. To receive and display tilt, it is adjusted to parse x, y, and needle values from the packet it receives, and then use statements from display_tilt_down_with_leds to display the tilt with its LEDs and in the terminal.
Example script: radio_tilt_receive_test
- In the micro:bit Python Editor connected to the cyber:bot, set the project name to radio_tilt_receive_test.
- Enter radio_tilt_receive_test.
- If you are in a classroom, adjust the channel= in the script to your assigned channel.
- Click Save, and then click Send to micro:bit.
# radio_tilt_receive_test from microbit import * import radio radio.on() radio.config(channel=7, queue=1, length=64) sleep(1000) while True: packet = radio.receive() if packet: dictionary = eval(packet) x = dictionary.get('x') y = dictionary.get('y') needle = dictionary.get('needle') print("Receive:") print("x =", x, ", y =", y, ", needle =", needle) print() display.show(Image.ALL_CLOCKS[needle]) sleep(500)
The goal is to be able to tilt the transmitting micro:bit, and verify matching data in the receive terminal, and on the receiver micro:bit’s LEDs. So, you will be tilting the transmitter while monitoring the receiver.
- In the browser with the micro:bit Python Editor that’s connected to the receiving cyber:bot, click Show serial.
- Tilt the transmitter micro:bit in various directions.
- Verify that the micro:bit on the receiving cyber:bot displays the direction you are tilting with its 5×5 LED matrix display.
- Verify that the serial monitor connected to the cyber:bot displays the x, y, and needle measurements in the terminal.
- If you are just here to make your tilt-controlled cyber:bot work, skip to Radio Tilt Controlled cyber:bot App. Otherwise, keep going to the next page to see how these test scripts work.
- Set the cyber:bot board’s power (PWR) switch to Position 0.
- Make sure the battery holder is loaded with 5 AA batteries.
- Make sure the battery holder’s barrel plug is firmly plugged into the cyber:bot board’s barrel jack.
- Connect the cyber:bot to your computer with a USB cable.
Example script: radio_tilt_receive_test
- In the micro:bit Python Editor connected to the cyber:bot, set the project name to radio_tilt_receive_test.
- Enter radio_tilt_receive_test.
- If you are in a classroom, adjust the channel= in the script to your assigned channel.
- Click Save, and then click Send to micro:bit.
# radio_tilt_receive_test from microbit import * import radio radio.on() radio.config(channel=7, queue=1, length=64) sleep(1000) while True: packet = radio.receive() if packet: dictionary = eval(packet) x = dictionary.get('x') y = dictionary.get('y') needle = dictionary.get('needle') print("Receive:") print("x =", x, ", y =", y, ", needle =", needle) print() display.show(Image.ALL_CLOCKS[needle]) sleep(500)
The goal is to be able to tilt the transmitting micro:bit, and verify matching data in the receive terminal, and on the receiver micro:bit’s LEDs. So, you will be tilting the transmitter while monitoring the receiver.
- In the browser with the micro:bit Python Editor that’s connected to the receiving cyber:bot, click Show serial.
- Tilt the transmitter micro:bit in various directions.
- Verify that the micro:bit on the receiving cyber:bot displays the direction you are tilting with its 5×5 LED matrix display.
- Verify that the serial monitor connected to the cyber:bot displays the x, y, and needle measurements in the terminal.
- If you are just here to make your tilt-controlled cyber:bot work, skip to Radio Tilt Controlled cyber:bot App. Otherwise, keep going to the next page to see how these test scripts work.
- In a Google Chrome or Microsoft Edge browser, go to python.microbit.org to open the micro:bit Python Editor.
- Make sure the cyberbot.py module is added to the Project Files.
(See Add modules to your micro:bit). - If you have each micro:bit connected to a different computer, skip to Example script: radio_tilt_receive_test.
- If you have both micro:bit tilt controller and tilt controlled cyber:bot connected to USB Ports on the same computer:
- Click the three dots ⋮ by the Send to micro:bit button, then select Connect. Then, set up the connection to the transmitter micro:bit.
- If you accidentally connect the second browser to the micro:bit tilt controller, you will have to:
- Unplug them both from USB, then plug them back in.
- After that, retry connecting the micro:bit Python Editor in one browser to one micro:bit, and the micro:bit Python Editor in the other browser to the other micro:bit.
- You will have to choose between micro:bits in the python.microbit.org wants to connect popup.
Example script: radio_tilt_receive_test
- In the micro:bit Python Editor connected to the cyber:bot, set the project name to radio_tilt_receive_test.
- Enter radio_tilt_receive_test.
- If you are in a classroom, adjust the channel= in the script to your assigned channel.
- Click Save, and then click Send to micro:bit.
# radio_tilt_receive_test from microbit import * import radio radio.on() radio.config(channel=7, queue=1, length=64) sleep(1000) while True: packet = radio.receive() if packet: dictionary = eval(packet) x = dictionary.get('x') y = dictionary.get('y') needle = dictionary.get('needle') print("Receive:") print("x =", x, ", y =", y, ", needle =", needle) print() display.show(Image.ALL_CLOCKS[needle]) sleep(500)
The goal is to be able to tilt the transmitting micro:bit, and verify matching data in the receive terminal, and on the receiver micro:bit’s LEDs. So, you will be tilting the transmitter while monitoring the receiver.
- In the browser with the micro:bit Python Editor that’s connected to the receiving cyber:bot, click Show serial.
- Tilt the transmitter micro:bit in various directions.
- Verify that the micro:bit on the receiving cyber:bot displays the direction you are tilting with its 5×5 LED matrix display.
- Verify that the serial monitor connected to the cyber:bot displays the x, y, and needle measurements in the terminal.
- If you are just here to make your tilt-controlled cyber:bot work, skip to Radio Tilt Controlled cyber:bot App. Otherwise, keep going to the next page to see how these test scripts work.
- In the micro:bit Python Editor connected to the cyber:bot, set the project name to radio_tilt_receive_test.
- Enter radio_tilt_receive_test.
- If you are in a classroom, adjust the channel= in the script to your assigned channel.
- Click Save, and then click Send to micro:bit.
# radio_tilt_receive_test from microbit import * import radio radio.on() radio.config(channel=7, queue=1, length=64) sleep(1000) while True: packet = radio.receive() if packet: dictionary = eval(packet) x = dictionary.get('x') y = dictionary.get('y') needle = dictionary.get('needle') print("Receive:") print("x =", x, ", y =", y, ", needle =", needle) print() display.show(Image.ALL_CLOCKS[needle]) sleep(500)
The goal is to be able to tilt the transmitting micro:bit, and verify matching data in the receive terminal, and on the receiver micro:bit’s LEDs. So, you will be tilting the transmitter while monitoring the receiver.
- In the browser with the micro:bit Python Editor that’s connected to the receiving cyber:bot, click Show serial.
- Tilt the transmitter micro:bit in various directions.
- Verify that the micro:bit on the receiving cyber:bot displays the direction you are tilting with its 5×5 LED matrix display.
- Verify that the serial monitor connected to the cyber:bot displays the x, y, and needle measurements in the terminal.
- If you are just here to make your tilt-controlled cyber:bot work, skip to Radio Tilt Controlled cyber:bot App. Otherwise, keep going to the next page to see how these test scripts work.