Introduction: Micro:bit Remote Control to Drive Sphero RVR
When I discovered the Sphero RVR platform and found out it was compatible with the BBC Micro:bit I couldn't wait to see how well the the bit could 'drive' it. I had come across this YouTube video of a Micro:bit being used to steer a RVR. The bit is connected to the RVR with a long cable. Instead of using a long cable I wanted to send the RVR driving signals wirelessly from one Micro:bit to another. One Micro:bit is the remote control and sends signals to the second Micro:bit. The second Micro:bit is connected to the Sphero RVR and 'tells' it what to do. Those things include speed, turning and changing the colors of the headlights.
Supplies
One Sphero RVR with the top removed
Two Micro:bits
One battery pack
One USB Cable
And a device with access to the Microsoft MakeCode website
Step 1: Creating the Controller: Step 1
Create a new file in the MakeCode editor. Time to start writing the code that runs the remote controller Micro:bit. Add a 'radio set group' block to the 'on start' block. In order to communicate with each other wirelessly, all the Micro:bits need to be set to the same group number. You can use any number between 1 and 255 as your radio group number. A student who was working on a related micro:bit radio project noted that this step was like making sure all the walkie-talkies are on the same channel.
Step 2: Code Some Inputs That Will Send Strings
The remote control Micro:bit sends signals that tell the RVR what to do. We will use the built in A and B buttons to steer left and right. The tilt right/left will control if the RVR moves forwards or backwards. Congratulations, you have just completed the remote control portion of this project. Save and download it as rvrcontrol.hex and then upload it to one of the Micro:bits.
Step 3: Giving the Sphero RVR a Micro:bit Brain
Create a new project in Microsoft MakeCode, this is what will be running on the second Micro:bit controlling the Sphero RVR. The first task to accomplish is to download the Sphero RVR extensions available for the Microsoft MakeCode environment.
Step 4: Helpful Hint: USB Connection for RVR
Connect the Micro:bit's included USB cable to the RVR. You need to remove the RVR top and then slide open the little hatch that protects these ports. There is a sticker over the hatch that you can remove which may make things easier..
Step 5: Download the Sphero RVR Extensions for Microsoft MakeCode
Open the Advanced tab in the MakeCode editor and navigate down to 'Extensions'.
Step 6: Locate and Load Sphero RVR Extension for MakeCode
Once on the 'Extensions' page, search for Sphero RVR. You will notice a selection of extensions on the landing page, don't worry if you don't see the extension you are looking for, those are only a small selection of what is available. Searching for extensions is the best way to find them. Once the extension is located, click on it to add it to the MakeCode editor for the current project.
Browse the complete list of Micro:bit MakeCode Extensions available organized by category here.
Step 7: Your New Sphero RVR Extensions - Lights
You can now add code that will control the lights on the Sphero RVR. You can choose to control them separately or together. You can choose any RGB values you wish to set your light color. All colors of light can be made by combining Red, Blue and Green light together in different combinations. An online tool from w3schools will let you experiment with Red Green and Blue values to create different colors. You can get the Red/Green/Blue values for any color you create and plug them in to your code to make your RVR lights any color imaginable.
Step 8: Your New Sphero RVR Extensions - Movement
You can now move the RVR with your Micro:bit code. You can control the speed and the heading of the RVR.
- speed: 0 - 255 value that represents RVR's speed
- heading: 0 - 359 value that represents RVR's compass heading
You can also control each motor individually by setting raw motors. The mode allows you to choose stop, forward, reverse for a given motor. You can also control the speeds of each motor independently.
The 'reset the yaw' block, resets the RVR heading to 0. This will help you keep the RVR moving in the direction you want it to move in. You can find out more about the RVR's driving capabilities on the Sphero RVR site.
Step 9: Your New Sphero RVR Extensions - Sleep/Wake
These extensions allow you to control the sleep/wake state of the RVR through code.
Step 10: Set Radio Group
The code for the RVR's 'brain' will turn signals into actions. In order for the two Micro:bits to communicate with each other they need to be in the same radio group. Add this block to the on start block of your RVR driver code.
Step 11: Coding the RVR Driver Micro:bit
On the Micro:bit connected to the RVR with, add a block that looks for a received string and then carries out some task based on the one that's sent. On the other Micro:bit, the one we are using as the remote control, four different strings are being sent. They are left, right, forward and reverse. Adding movement blocks to our code on the RVR 'brain' side allows those signals to be interpreted as actions by the RVR. Code was added to change the lights as well.
Step 12: Resetting the Yaw
This block's was usefulness only became evident after I got my first code to move a RVR. It drove but it drove in a whacky way. Whatever direction it ended up pointed in became the new 'zero' or starting point. It was fun but frustrating, the RVR was sorta out of control. Adding the 'reset the yaw' block reset the heading to onboard magnetometer's zero and made a big change in the driving experience.
Step 13: A Quick Note on If/Then Statements
It is useful to note that the small plus sign at the bottom of the 'If/Then block' allows you to add more conditions to check for.
Step 14: Ready to Test - Remote Control Code
Load the rvrcontrol.hex file onto a Micro:bit.This will act as the remote control that will send signals to the 'brain' in order to control the RVR. Power that Micro:bit with the battery pack.
Step 15: Ready to Test - RVR Driving Interpreter Code
Load the rvrbrain.hex code onto the other Micro:bit. This Micro:bit will be connected to the Sphero RVR via the USB cable and act as the 'brain' or signal interpreter that will 'tell' the RVR what to do.
Step 16: Test Drive Your RVR
Power up and see how the controller/brain system works.
After testing the code, revise things that would improve the vehicle control and user experience. Testing things out and adjusting accordingly is the path to improving your code, experience and product.
Some things, like adding a stop function seemed to make a major difference in the driving experience. Others were small but incredibly useful like a beating heart indicator in the remote control code to indicate the bit was running the program. Showing the direction of the interpreted strings as graphic arrows on the led matrix was another visual indicator added to both Micro:bit l.e.d. displays. I also modified the headlight code during left/right turning to display color reverse of each other. Changing the label 'backward' to the much smarter sounding 'reverse' was also in order.
Experiment with the code, change stuff around. You can't break it... well you can but it is fun to solve the puzzle and fix it...right?...don't you agree? Even if you make a total mess of it, you can simply download a fresh version of the code and start anew.
A student switched what was happening on the buttons and the tilt controls and found a whole different (and better) driving experience. There is still much to explore here, the acceleration aspects alone seem intriguing. Can that value be used to create a better driving experience? The RVR now has access to the full range of sensors built in to the Micro:bit, how could that information be used to inform and improve the process. Would adding code that put the RVR to sleep after a lack of input from the Micro:bit help conserve battery life? Share your remix with the rest of us.
Step 17: The Final Code After a Few Rounds of Revisions - Remote Control
Download the latest code here:
Step 18: The Final Code After a Few Rounds of Revisions- RVR Driving Interpreter
Download the latest code here.