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

For best results:

  • Connect your cyber:bot to a second USB port (or to another computer).
  • Open a second python.microbit.org editor
  • If you are in a classroom, adjust the channel= in the script to your assigned channel.
  • Enter, save, and flash radio_tilt_receive_test into the cyber:bot that you will use to display the tilt data it’s receiving from the transmitter.
# 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.

  • Open the terminal in the editor that’s connected to the receiving cyber:bot.
  • 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 LEDs.
  • Verify that it 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 thesse test scripts work.