The main.py file includes the modules to control micro:bit. The sphero.py file includes the modules to program your RVR+/RVR with micro:bit. You are ready to create your first program.
The micro:bit Python editor has lots of great features designed to help programmers learn Python, including a reference section, drag and drop code snippets, auto-complete, and more. Reference micro:bit’s getting started materials to learn more about the editor.
For now, let’s create our first program. Delete the existing code in the project. Then copy and paste the following code into the editor.
# Imports go at the top
from microbit import *
from sphero import *
# Code to run when program starts
# Wake up RVR and pause for 2 seconds
# Set all LEDS to yellow
RVRLed.set_all_leds(255, 255, 0)
# Run through a loop four times to drive forwards and backwards for 2 seconds
for i in range(4):
IMPORTANT: You probably noticed that some features of the editor like the reference section only apply to micro:bit library. Refer to the Sphero SDK for micro:bit page for documentation about the commands available in the Sphero SDK.
Flash the Program to your micro:bit
Like MakeCode, the micro:bit Python editor has two ways to flash—or transfer—a program to your micro:bit.
Drag and drop - Select the “Save” button to download the .hex file to your device. Connect your micro:bit to your computer. Then find the file and drag and drop it onto the micro:bit.
Direct flashing - Connect your micro:bit to your computer. Then select the “Send to micro:bit” button and follow the instructions to connect to your micro:bit using web USB. Direct flashing is only available in the recent Chrome and Edge browsers.
For more information on flashing programs from micro:bit’s Python editor, refer to their support site.
Run the Program on RVR+/RVR
Now that your program is downloaded onto the micro:bit, it’s time to run it on your RVR+ or RVR.
Disconnect the micro:bit from your computer, then plug it into your powered-off RVR+/RVR.
Press the RVR+/RVR power button and watch the program run!
See more examples of what you can accomplish with your RVR+ or RVR and the micro:bit SDK.