This is a simple tethered application where you type in left and right wheel speeds, and run time in milliseconds, into a terminal. When you press Enter, your text gets parsed and executed by the micro:bit, which then makes the cyber:bot execute the maneuver.
Hardware Setup
- 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.
Software Setup
- 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).
Example Script: terminal_controlled_bot_tethered_intro
- Set the project's name to terminal_controlled_bot_tethered_intro, enter the script below, and then click Save.
(See Save & Edit Scripts and Flash Scripts with Python Editor.) - Click Send to micro:bit.
(See Flash Scripts with Python Editor.) - Set the cyber:bot board's PWR switch to 2.
Example Script: terminal_controlled_bot_tethered_intro
# terminal_controlled_bot_tethered_intro from cyberbot import * sleep(1000) print("\nSpeeds are -100 to 100\n") while(True): text = input("Enter left speed: ") vL = int(text) text = input("Enter right speed: ") vR = int(text) text = input("Enter ms to run: ") ms = int(text) bot(18).servo_speed(vL) bot(19).servo_speed(-vR) sleep(ms) bot(18).servo_speed(None) bot(19).servo_speed(None) print()
Since your cyber:bot is currently tethered, it’s best to use low speeds and short run times. Otherwise, your cyber:bot might try to roll beyond the tether length. In other words, it’ll try to unplug itself from the USB cable, or maybe roll off the table.
- Click Show serial to open the serial monitor.
(See Use the Serial Monitor.) - Click in the serial monitor and type 25 in response to the Enter right speed: prompt, then press Enter.
- Type 25 in response to the Enter left speed: prompt, then press Enter.
- Type 750 in response to the Enter ms to run: prompt, and press Enter.
- Verify that your cyber:bot rolled forward for about ¾ of a second.
- Next, try -25, -25, and 750. Did it roll backwards?
- Now, try 25, -25, 750. Did it pivot to the right?
- Try 25, 10, 750 for a curving motion.
- Can you make it turn in place left and right?
- Try causing an exception by typing non-digits in response to one of the prompts.
For example, what happens if you type abc and press enter? For now, you can press/release the reset button to restart the app. You will add some exception handling in the your turn section to prevent this from happening.
Setting PWR switch to 0 vs. Unplugging Battery Holder
Taking a break, building a circuit, or writing a script?
- Just set the cyber:bot board's PWR switch to 0 until it's time to test the next script.
If you are done for the day, always follow these steps.
- Set PWR to 0.
- Unplug the battery holder's barrel plug from the cyber:bot board's barrel jack.