Radio Tilt Controlled cyber:bot Code

This is the receiver script for your Radio Tilt Controlled cyber:bot.  You will also need to load the script on the next page into the tilt controller micro:bit (or cyber:bot) you will use to drive this receiver cyber:bot.

  • Set the receiver cyber:bot board PWR switch to 1.
  • If you are in a classroom, adjust the channel= in the script to your assigned channel.
  • Enter, save, and flash radio_tilt_controlled_cyberbot into the micro:bit that’s in the receiver cyber:bot.  
  • Disconnect the cyber:bot from the USB cable, and set it on the floor.
  • Continue to the Radio Tilt Controller section.
# radio_tilt_controlled_cyberbot

from cyberbot import *
import radio

radio.config(channel=7, queue=1, length=64)

while True:

    packet = radio.receive()

    if packet:


            dictionary = eval(packet)
            x = dictionary.get('x')
            y = dictionary.get('y')
            needle = dictionary.get('needle')
            fb = y / 10
            lr = x / 10

        except Exception as e:

            print("Exception e:", e)
            print("Type:", type(e))


            if abs(fb) > 8:
                vL = fb
                vR = -fb

                if(fb < 0): lr = -lr
                vL = vL - lr
                vR = vR - lr


                vL = None
                vR = None




How it Works

If you came straight here to run the application, this section only explains finishing touches.  You can start at the beginning of this tutorial and read through or actually do the activities that introduce one concept at a time and incrementally build the scripts.

The radio_tilt_controlled_cyberbot script started as radio_tilt_bot_fb_lr_with_stop_range from the Add Right/Left Tilt Control activity.  Along with How It Works sections in some of the earlier activities, it will allow you to take a closer look at the mechanics of the tilt control app.  

As mentioned earlier, exception handling helps prevent other radio messages on the same channel from causing your tilt controlled cyber:bot from throwing an exception in the middle of a maneuver.  The only change to the script is that try…except…else… and finally were added at key points, and the code below each was indented.  For details on how try…except…else…finally works, read or better still, try the activities in the Exception Handling Primer.