Microbot Activity
Estimated Time: 1 Hour
This lab enables students to learn about communication interception through a hands on approach with Micro:Bots. We will demonstrate the use of radio technology as a means for remote control and the potential for radio wave hijacking. Students will learn the fundamentals of Bluetooth and radio waves through implementation by using one micro:bit as a controller for another micro:bit embedded in a robot.
Step 0: The Basics
- Micro::Bit Coding Options
- [Click here to code with JavaScript/Blocks] (https://makecode.microbit.org)
- Click here to code with MicroPython
- Microbot Basics
Step 1: Gather Materials
- Micro::Bit (1 per person / 2 per team)
- Micro-USB Cable
- Battery Pack (Equivalent to two AA batteries)
- Microbot
Step 2: Get Familiar With Microbots
Radios work by sending and receiving messages over different channels. This allows you to use on Micro:Bit to send messages and another to receive them. In this lab, you will use a Micro:bit as a controller to get user input and then send messages based on those inputs. Then, you will use a second Micro:bit to receive messages from the controller and then control the robot based on those received messages.
Start this lab by going over this basic programming example.
The first set of code is for the Micro:Bit controller. This controller waits for the user to press the A button or the B button. When the user presses the A button, the controller sends the message "left" to the robot. When the user presses the B button, the controller sends the message "right" to the robot.
The second set of code is for the Micro:Bot robot. This Micro:Bit waits to receive a message. If they receive a "left" message, it tells the robot to go left. If they receive a "right" message, it tells the robot to go right.
Step 3: Download The Files
-
Download (click on) the following file to get started: MicroBotLab.zip
-
Unzip MicrobotLab.zip (right click on the MicrobotLab.zip and select "extract all". Then, just pick where you want to save your copy of these files). Notice there are three folders/directories in MicrobotLab: * Attackers: This directory holds code to simulate an attack that jams the radio channel and makes the robots behave chaotically.
- HexFiles: This folder/directory holds all of the .hex files, or files that are ready to be run on a Micro::Bit.
- JavaScript: This folder/directory holds all of the JavaScript code for the labs. This includes base code and completed code. The base code is code that you can start with instead of creating new projects from scratch. Completed code is code that members of the CEDAR lab completed that you can look at if you get stuck.
- Python: This folder/directory holds all of the Python code for the labs. This also includes base code and completed code.
Step 4: Open your editor.
- For JavaScript/Blocks, you will use the Micro::Bit online editor: MakeCode. Here, you can switch back and forth between JavaScript and Blocks by clicking on the button/slider in the top center of the screen.
- For Python, you can use Mu (click here to see Mu) or the online editor (click here to get to the online editor).
Step 5: Get Moto-Bit library.
- For JavaScript/Blocks, start by selecting the "Advanced" drop down box in the libraries toolbar.
Then, scroll down to the bottom of the advanced packages. Select the "Add Package" button.
In the packages pop-up, search for "Motobit". Select the moto-bit library in the results section.
You can check to make sure that you have the library by searching for the library in your libraries toolbar.
Step 6: Programming!
- Partner up
- Open the robot base code by: 1.
- Complete the robot code. Add:
1.
#. Set the radio group to your assigned group - Generate your robot .hex file
- Open the the controller base code
- Complete the controller robot code. Add:
1.
#. Set the radio group to your assigned group - Generate your controller .hex file
- Flash the robot hex file to one Micro::Bit and the controller hex file to the other. 1.
- Test your code. Your robot should: 1.
- Now try to intercept other robots
Step 7: Further Exploration
- Can you think of a way to incorporate a reverse function for the microbot? What if you needed to push and hold a+b to make it move in a direction? How would you select between forward and reverse? Spend some time exploring with your Micro::Bit and see what kind of improvements you can make.
Potential Python Solution (Click to Expand)
from microbit import * import radioradio_group = 0 #number of radio frequency to use forward = False group_set = False #has the radio group been set? radio.on() radio.config(power=7)
stop_sign = Image( "09990:" "90099:" "90909:" "99009:" "09990")
while True:# do forever if group_set is False: display.show(str(radio_group))
if button_a.is_pressed() and button_b.is_pressed(): if group_set is False: group_set = True radio.config(channel = radio_group) display.show(Image.HAPPY) forward = False else: if reverse == False: radio.send("reverse") reverse = True display.show(Image.ARROW_S) else: radio.send("stop") forward = False display.show(stop_sign) elif button_a.is_pressed(): if group_set == False and radio_group > 0 : radio_group = radio_group - 1 else: radio.send("left") display.show(Image.ARROW_W) elif button_b.is_pressed(): if group_set is False and radio_group < 255: radio_group = radio_group + 1 else: radio.send("right") display.show(Image.ARROW_E) sleep(200)
- Are you able to control another group's robot?
- Does your control work with their robot?
- How about after you play with the code?
The GenCyber Wyoming COWPOKES program is supported by the National Security Agency and the National Science Foundation through Award #H98230-18-1-0095. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation, the National Security Agency, or the U.S. government.