[2021] Start Up Guide for Valenta RC Car With Two (x2) Micro:bits V1/V2
by hummingworks in Circuits > Remote Control
1703 Views, 8 Favorites, 0 Comments
[2021] Start Up Guide for Valenta RC Car With Two (x2) Micro:bits V1/V2
If you've got Valenta micro:bit RC car and want to test drive, this is the "please read me first" guide. In this tutorial, you can download ready-to-play MakeCode sample files and play immediately.
Setting up the car is made simple. On your "transmitter" micro:bit, you could calibrate the steering of the car easily by pressing button A or B. Lighting up on-board LEDs is also simple by pressing button A and B together. Tilting your "transmitter" micro:bit down, up, right and left will let the car go forward, backward, right and left.
This tutorial does not require coding at all. However, what's really fun is to reverse-engineer how it's running under the hood. If you want to discover more, you can further continue reading the following steps to go deeper in the knowledge. Good luck and have fun!
If you want to control your car using iPad or iPhone, please review this tutorial instead.
Supplies
Micro:bits
We will need two (x2) micro:bits. One (x1) micro:bit is used for the transmitter. Another (x1) micro:bit is used for the receiver. We've tested and both micro:bit version 1 (V1) and version 2 (V2) are working correctly.
Batteries
We recommend using new, single-use 1.5V AA and AAA batteries. Two (x2) AAA batteries are needed for the battery case connected to "transmitter" micro:bit. Four (x4) AA batteries are needed for the car.
RC Car Kit
We will need one (x1) Valenta Off-Roader micro:bit RC car. It is Lego technic compatible and equipped with two (x2) micro gear motors on the rear wheels and one (x1) steering servo based on Roberval balance arm mechanism.
You can also refer to this instruction for assembling the car.
Copying Sample Files to Micro:Bits
We've prepared MakeCode sample files you can download to your computer. Since these sample files are ready to play, you can start playing immediately. These sample files can work with both micro:bit version 1 (V1) and version 2 (V2).
In this step, please download Transmitter.hex file and Receiver.hex file below. Connect your computer and a micro:bit via USB cable, and copy each file to each of your micro:bit one at a time.
First, drag and drop Transmitter.hex file to a micro:bit and use this as "transmitter" micro:bit.
Second, drag and drop Receiver.hex file to another micro:bit and use this as "receiver" micro:bit.
Once you've copied the sample file to your micro:bit, disconnect it from your computer. Connect the battery case to "transmitter" micro:bit and turn it on. (Alternatively, you can also provide the power to "transmitter" micro:bit by connecting it to the computer via USB cable.) Mount "receiver" micro:bit on your car and turn on the power switch on the motor controller. Once "transmitter" micro:bit and "receiver" micro:bit are properly powered on, you can control the car now.
By default, the steering of your car is not always straight by the servo equipped in the car. If the car's steering is not straight ahead, try to calibrate it by pressing "transmitter" micro:bit's button A or B. If the car's steering is a little too right, press button A several times to fix it to the left. If the car's steering is a little too left, press button B several times to fix it to the right. Pressing either button will fix the steering angle by 2 degrees to the opposite side.
You can also light up the LEDs on the motor controller. Pressing "transmitter" micro:bit's button A and B simultaneously will light up the built-in four (x4) LEDs. Pressing button A and B simultaneously one more time will turn them off.
Tilting your "transmitter" micro:bit down, up, right and left will let the car go forward, backward, right and left.
Now, you can control Valenta Off-Roader RC car! That's all for setup and play! If you want to discover how it's running under the hood, you can further read the following steps to understand MakeCode sample files.
Reviewing Transmitter.hex Sample File
Now we will examine Transmitter.hex sample file. Open MakeCode editor and click Import button. Open Transmitter.hex file you've copied to "transmitter" micro:bit.
on start block
radio set group 1
This block is called initially at once when "transmitter" micro:bit is turned on. In Radio extension, you can find the block radio set group and 1 is set for example. This number must be the same between "transmitter" micro:bit and "receiver" micro:bit, so they can be paired together for communication.
The file uses Accelerometer features. By tilting your "transmitter" micro:bit down, up, right or left, it will send the radio string of "goForward" "goBackward" "goRight" or "goLeft" to your "receiver" micro:bit.
on logo down block
radio send string "goForward"
In Input extension, you can find the block on logo down. This block is executed whenever you title "transmitter" micro:bit down or forward. In the block, you can also find radio send string "goForward" that will send the radio string "goForward" over the air when "transmitter" micro:bit is tilted down. When "receiver" micro:bit receives this string, the car will go forward.
on logo up block
radio send string "goBackward"
In Input extension, you can find the block on logo up. This block is executed whenever you title "transmitter" micro:bit up or backward. In the block, you can also find radio send string "goBackward" that will send the radio string "goBackward" over the air when "transmitter" micro:bit is tilted up. When "receiver" micro:bit receives this string, the car will go backward.
on tilt left block
radio send string "goLeft"
In Input extension, you can find the block on tilt left. This block is executed whenever you tilt "transmitter" micro:bit to the left. In the block, you can also find radio send string "goLeft" that will send the radio string "goLeft" over the air when "transmitter" micro:bit is tilted to the left. When "receiver" micro:bit receives this string, the car will turn left.
on tilt right block
radio send string "goRight"
In Input extension, you can find the block on tilt right. This block is executed whenever you tilt "transmitter" micro:bit to the right. In the block, you can also find radio send string "goRight" that will send the radio string "goRight" over the air when "transmitter" micro:bit is tilted to the right. When "receiver" micro:bit receives this string, the car will turn right.
By default, the steering of your car is not always straight by the servo equipped in the car. If the car's steering is not straight ahead, you could calibrate it by pressing "transmitter" micro:bit's button A or B.
on button A pressed block
radio send string "calibrateLeft"
If the car's steering is a little too right, you can press button A several times to fix it to the left. In the block, you can also find radio send string "calibrateLeft" that will send the radio string "calibrateLeft" over the air when "transmitter" micro:bit's button A is pressed. When "receiver" micro:bit receives this string, the car will fix the steering angle by 2 degrees to the left.
on button B pressed block
radio send string "calibrateRight"
If the car's steering is a little too left, you can press button B several times to fix it to the right. In the block, you can also find radio send string "calibrateRight" that will send the radio string "calibrateRight" over the air when "transmitter" micro:bit's button B is pressed. When "receiver" micro:bit receives this string, the car will fix the steering angle by 2 degrees to the right.
Pressing button A and B simultaneously will light up the LEDs on the motor controller. Pressing button A and B simultaneously one more time will turn them off. Each LED is equipped with the programmable chip for lighting up the RGB color of your choice.
on button A+B pressed block
radio send string "lightUp"
In the block, you can also find radio send string "lightUp" that will send the radio string "lightUp" over the air when "transmitter" micro:bit's button A and B are pressed simultaneously. When "receiver" micro:bit receives this string, the car's built-in LEDs on the motor controller will light up.
Adding Extensions to MakeCode Editor
Does your MakeCode editor include Servos and Neopixel extensions? Please open the editor and check if it includes these extensions in the left menu. We will use these extensions in Receiver.hex sample file. If you can't find these extensions, click Extensions in the bottom of the menu. Then, click to add these extensions to the menu one by one.
Servos extension will be used for calibrating the steering angle.
Neopixel extension will be used for lighting up the programmable RGB LEDs built on the motor controller.
Reviewing Receiver.hex Sample File (Part 1)
Now let's look at Receiver.hex sample file. Open MakeCode editor and click Import button. Open Receiver.hex file you've copied to "receiver" micro:bit.
on start block
radio set group 1
This block is called initially at once when "receiver" micro:bit is powered on.
In Radio extension, you can find the block radio set group and 1 is set for example. This number must be the same between "transmitter" micro:bit and "receiver" micro:bit, so they can be paired together for communication.
In this project, let's assume that the steering servo is attached to P2 pin on the motor controller. Let's configure that the servo swings from 0 to 180 degrees and its central angle is 90 degrees.
set center to 90
In Variable extension, create a new variable center that keeps the servo's central angle you wish. Drag and drop set center to block and set it to 90 degrees.
set servo P2 range from 0 to 180
In Servos extension, drag and drop set servo P2 range from 0 to 180. Make sure to choose P2 pin and the rotation angle ranges from 0 to 180 degrees.
set servo P2 angle to center
In Servos extension, drag and drop set servo P2 angle to center. Make sure to set the angle to the variable center.
set LED RGB to NeoPixel at pin P16 with 4 leds as RGB
In Neopixel extension, drag and drop set strip to NeoPixel at pin P0 with 24 leds as RGB. Click the variable strip and rename it to LED RGB. The motor controller uses pin P16 for its four (x4) RGB LEDs on-board. Thus, choose the pin P16 and enter as 4 leds. Now the block looks like set LED RGB to NeoPixel at pin P16 with 4 leds as RGB.
set LEDs to 0
In Variable extension, create a new variable LEDs that keeps the boolean value of 0 or 1 for powering off and on the LEDs on the motor controller. We use this variable LEDs = 0 to turn off the LEDs and LED = 1 to turn on the LEDs. Let's set LEDs to 0 initially.
(Continuing to the next step)
Reviewing Receiver.hex Sample File (Part 2)
Let's look at the following function blocks that define the direction and the speed of your car.
The car has a micro gear motor M1 on the left rear wheel and M2 on the right rear wheel.
function goForward block
First, let's create goForward function in Functions extension.
digital write pin P13 to 0
P13 pin is used for direction of M1 motor. In Pins extension, drag and drop digital write pin P13 to 0, so that M1 goes forward.
digital write pin P15 to 0
P15 pin is used for direction of M2 motor. In Pins extension, drag and drop digital write pin P15 to 0, so that M2 goes forward.
analog write pin P12 to 1023
P12 pin is used for speed (max speed is 1023) of M1 motor. In Pins extension, drag and drop analog write pin P12 to 1023, so that M1 goes forward at max speed.
analog write pin P14 to 1023
P14 pin is used for speed (max speed is 1023) of M2 motor. In Pins extension, drag and drop analog write pin P14 to 1023, so that M2 goes forward at max speed.
pause (ms) 1000
In Basic extension, drag and drop pause (ms) 1000 block to keep the car going forward for 1000 milliseconds (1 second).
call stop
In Functions extension, drag and drop call stop block to execute function stop. After the car has run for 1 second, it will stop safely.
function goBackward block
Second, let's create goBackward function in Functions extension.
digital write pin P12 to 0
P12 pin is used for direction of M1 motor. In Pins extension, drag and drop digital write pin P12 to 0, so that M1 goes backward.
digital write pin P14 to 0
P14 pin is used for direction of M2 motor. In Pins extension, drag and drop digital write pin P14 to 0, so that M2 goes backward.
analog write pin P13 to 1023
P13 pin is used for speed (max speed is 1023) of M1 motor. In Pins extension, drag and drop analog write pin P13 to 1023, so that M1 goes backward at max speed.
analog write pin P15 to 1023
P15 pin is used for speed (max speed is 1023) of M2 motor. In Pins extension, drag and drop analog write pin P15 to 1023, so that M2 goes backward at max speed.
pause (ms) 1000
In Basic extension, drag and drop pause (ms) 1000 block to keep the car going forward for 1000 milliseconds (1 second).
call stop
In Functions extension, drag and drop call stop block to execute function stop. After the car has run for 1 second, it will stop safely.
function stop block
Lastly, let's create stop function in Functions extension.
digital write pin P13 to 0
P13 pin is used for direction of M1 motor. In Pins extension, drag and drop digital write pin P13 to 0, so that M1 is set for forward direction.
digital write pin P15 to 0
P15 pin is used for direction of M2 motor. In Pins extension, drag and drop digital write pin P15 to 0, so that M2 is set for forward direction.
analog write pin P12 to 0
P12 pin is used for speed (0 means no speed) of M1 motor. In Pins extension, drag and drop analog write pin P12 to 0, so that M1 stops.
analog write pin P14 to 0
P14 pin is used for speed (0 means no speed) of M2 motor. In Pins extension, drag and drop analog write pin P14 to 0, so that M2 stops.
set servo P2 angle to center
In Servos extension, drag and drop set servo P2 angle to center. Make sure to set the angle to the variable center. That way, the car's steering is always straight ahead every time it stops.
(Continuing to the next step)
Reviewing Receiver.hex Sample File (Part 3)
Previously, we've created the variable LEDs in Variable extension. This variable keeps the boolean value of 0 or 1 for powering off and on the LEDs on the motor controller. We use this variable LEDs = 0 to turn off the LEDs and LED = 1 to turn on the LEDs. In Logic extension, we also use if then block. Click + sign to expand it as necessary. This block will sort out the on-board LEDs status on and off using the boolean variable LEDs.
function lightUp block
First, let's create lightUp function in Functions extension.
if LEDs = 0 then
set LEDs to 1
LED RGB show color white
If the boolean variable LEDs is 0 (meaning LEDs are off), then set LEDs to 1 and turn on the light. In Neopixel extension, drag and drop strip show color red. Swap the variable from strip to LED RGB that you've created earlier and choose the color of your choice, so that the block looks like LED RGB show color white. You can choose blue, yellow or any color you like.
else if LEDs = 1 then
set LEDs to 0
LED RGB show color black
If the boolean variable LEDs is 1 (meaning LEDs are on), then set LEDs to 0 and turn off the light. In Neopixel extension, drag and drop strip show color red. Swap the variable from strip to LED RGB that you've created earlier and choose the color black, so that the block looks like LED RGB show color black. The black color means LEDs will turn off the light.
(Continuing to the next step)
Reviewing Receiver.hex Sample File (Part 4)
Whenever "receiver" micro:bit catches the radio string sent from "transmitter" micro:bit over the air, "receiver" micro:bit will sort out and call the relevant function for controlling the car.
on radio received receivedString block
In Radio extension, find on radio received receivedString block and use it for sorting out and call the function on demand. In Logic extension, use if then block and click + sign to expand it as necessary. This block will call the function depending on the received string being sorted out.
if receivedString = calibrateLeft then
set center to center + 2
set servo P2 angle to center
If the received string is "calibrateLeft" then drag and drop set center block in Variable extension here and make it set center to center + 2. It means you could fix the steering to the left by 2 degrees. In Servos extension, drag and drop set servo P2 angle to center. This center has been updated to the left by 2 degrees.
if receivedString = calibrateRight then
set center to center - 2
set servo P2 angle to center
If the received string is "calibrateRight" then drag and drop set center block in Variable extension here and make it set center to center - 2. It means you could fix the steering to the right by 2 degrees. In Servos extension, drag and drop set servo P2 angle to center. This center has been updated to the right by 2 degrees.
else if receivedString = goForward then
call goForward
If the received string is "goForward" then drag and drop call goForward block in Functions extension to call the function.
else if receivedString = goBackward then
call goBackward
If the received string is "goBackward" then drag and drop call goBackward block in Functions extension to call the function.
else if receivedString = goLeft then
set servo P2 angle to center + 10
call goForward
If the received string is "goLeft" then, drag and drop set servo P2 angle to center + 10 in Servos extension. Use Math extension to create center + 10 bracket. It means the steering is shifted +10 degrees to the left. Drag and drop call goForward block in Functions extension to call the function. Now the car is turning left and going forward.
else if receivedString = goRight then
set servo P2 angle to center - 10
call goForward
If the received string is "goRight" then, drag and drop set servo P2 angle to center - 10 in Servos extension. Use Math extension to create center - 10 bracket. It means the steering is shifted -10 degrees to the right. Drag and drop call goForward block in Functions extension to call the function. Now the car is turning right and going forward.
else if receivedString = lightUp then
call lightUp
If the received string is "lightUp" then drag and drop call lightUp block in Functions extension to call the function.