Saturday, 18 February 2017

Microbit controlled model mini

I recently found this RC model mini in a charity shop for a bargain price of 50p. There was no remote controller but the model itself had the all important motors (1 for steering the front wheels and 1 for driving the rear wheels).



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:

The positions marked 1,2,3 and 4 are the signal pins to which the Micro:Bit would be later connected. However, rather than bring the Micro:Bit into the mix at this stage I got my son to simulate its action by a second circuit driven by 2 AA batteries, connected 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 Kitronik

Edge 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
After testing the connection to the Android App my son then extended the circuit to include four LEDs and added the rest of the code. We could now operate four LEDs via the forward/reverse and left/right buttons on the Android App.

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
The Micro:bit was then connected to a battery box and we were ready to put everything back together.

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
After some carefully placed velcro, bluetack, foam sheets and sticky pads we managed to squeeze everything in, replace the body and screw it back into position.

Microbit secured

Battery compartment attached to the top for easy access
The very top part was just slotted in and allowed easy access to the inside.

Closing the hatch
Ready for the test drive!

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.

No comments:

Post a Comment