I had previously hacked a smaller RC car for use with an Arduino, but this time wanted to try out the BBC micro:bit. As it was half term, I roped my son into helping me, especially with some of the fiddly connections and soldering (my eyesight not really being up for the job).
First, he took it apart being careful to reserve screws and take photos as he went along. Once inside, we then identified all the important electrical connections we needed and removed the existing circuit board leaving as much of the wiring as we could.
Next began the gradual process of reworking and testing the model.
Our plan was to use the existing battery box to power the motors, but for the Micro:Bit to control them via an L298N H-bridge motor driver (which we already had). The Micro:Bit would have its own power supply (2 AAA batteries).
Plan of the final circuit |
The motor power supply
The battery box (accessible from underneath) was a little corroded in places and the on/off switch was stuck in the on position. We cleaned everything up, but decided to ditch the switch and remove the existing wiring. The good news was that the battery compartment was for six AA batteries which meant there would be plenty of power for use with the H-bridge.We tested the end to end connection with a volt meter and soldered on two good lengths of wire - black for -ve and red for +ve.
Locating good points to solder on the +ve and -ve wires |
The motor connections
For each motor, we identified the two wires required to activate them. We then gave them a quick test by temporarily connecting them in turn to the battery box. All was fine.As usual in toys of this sort each motor had a capacitor (or two) connected in parallel; we left these in place. The wires looked long enough to use directly so we just used some solder to tin them ready for connection to the H-bridge.
Locating the two wires connected to the rear wheels |
Wiring up and testing the H-bridge
The four motor wires and the two wires from the battery compartment were connected to the H-bridge as follows:He used an old Snap Circuits battery box for this and just moved the +ve connection to each of the signal pins in turn.
Note that the two circuits have the GND connection in common.
Once this had been tested we put the mini away and concentrated on the Micro:Bit side of things.
Accessing and programming the GPIO pins of the Micro:Bit
We were going to need four of the Micro:Bit pins for our project which meant purchasing an edge connector board. We opted for this one from KitronikEdge Connector Breakout Board |
There are lots of options for programming the Micro:Bit. I opted for the Microsoft PXT using the block editor as this seemed to fit our purposes best. I aimed for us to control our car from an Android phone over bluetooth and this project provided clear instructions and a ready made app.
A simple LED circuit
As my son was new to the Micro:Bit and its programming environment I got him to connect up a simple LED circuit and make sure he understood the build and download process. When this code is loaded the LED lights if Button A is pressed and goes off when it is released.
Once this was working via a button press I got him to move on to getting it to work remotely via a smartphone using bluetooth.
Controlling the LED from the Android App
We downloaded the Android App which we planned to use to control our car. Full information on how to write code for the Micro:Bit which responds to events from this app can be found at the Kitronk Blog. (We used Bitty Software's dedicated Bitty Game Controller App rather than the general Microbit Blue App, but the principles and event numbers are the same.)Bitty Game Controller's DPad with event names marked |
Following the instructions, it was very simple to put together the code necessary to connect to the Micro:Bit and to remotely activate the LED by pressing button 1 on the DPad:
This code provides visual confirmation of our connect / disconnect status |
This code handles the events sent when button 1 is pressed on the DPad |
The only complication was having to re-pair the Android device with the Micro:Bit every time we had downloaded new code over the USB connection. You do get used to doing this, but at first it was frustrating.
Attaching the Micro:bit to the mini's motors via the H-Bridge
After testing the code with the LEDs we were ready to attach the Micro:bit to the motors.
We attached the jumper wires from the Micro:bit pins to the H-Bridge pins. We tested each connection via the app as we went along to make sure each game control button activated the correct motor and direction. No adjustment was required to the code at this stage.
Connecting the microbit to the H-bridge and testing |
Putting things together
This was probably the most difficult part of the project as my son was insistent that none of our mods should be visible once the car body was back in place. For me, the important constraints were no risk of short circuits and the ability to easily disconnect both power supplies.H-Bridge connected and secured in position |
Microbit secured |
Battery compartment attached to the top for easy access |
Closing the hatch |
The Test Drive
The power to the motor driver is cut by detaching a connector. The power to the microbit is cut by a switch on its battery compartment. Both of these have easy access. What doesn't have such easy access is the ability to pair the microbit. Fortunately, once your code is loaded and you have already paired with a device it is not something you have to do again as the Android device will remember. But changing to a different Android device will probably require unscrewing a few things.
Still, not a bad half term project.