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.

Thursday 9 February 2017

Printable soft circuits for Arduino, Microbit and Raspberry Pi

Image of an embroidered design printed onto cotton
The following idea developed out of a secondary school Creative Computing club I helped run. I had read that one way to engage more girls in coding was with e-textiles so I looked into ways that we could incorporate this into our club.

I have seen some impressive e-textile creations online but many of these involve significantly more sewing than actual coding. I was concerned that by introducing e-textiles to the club we would end up with students spending most of their time sewing rather than forging ahead with more challenging coding concepts.

I wanted something in kit form, with minimal sewing but which introduced students to the potential of e-textiles and soft circuits. It also had to be cheap as we had very little budget. Basically I was after a printable textile equivalent of kits such as this Christmas Tree kit:


Pi Hut's Christmas Tree Kit

or even better, something like this e sewing template from Spark Fun
Lilypad e sewing kit
So, I turned to my old friend - a stack of inkjet T-shirt transfer paper - which I have called upon for many projects over the years. I found a suitable Christmas Tree Image online to which I added the following:
  • LED positions
  • resistor positions
  • guidelines for conductive thread
  • external connection positions
The image was then reversed,



printed onto T-shirt transfer paper, cut out and ironed onto white felt. Here is the finished article.

Completed Christmas Tree
I sewed this myself and presented it to the students as one of many ready-made projects for which the coding was the main goal. Another example was this training shoe:

Trainer Light Sequencing Project
And here are a couple connected up to a BBC microbit:




Once completed, these e-textiles were easy to store, reusable and robust.

Not only is this technique useful for introducing e-textiles it also provides an alternative to breadboard circuits and commercially made projects such as traffic light add-ons.

No special electronic components were used, just cheap LEDs and resistors which were attached with conductive thread. There are plenty of instructions elsewhere online as to the best way to sew these on. I use long nose pliers to twist the ends into loops, but scissors also work. Here are some of my efforts:





And for the terminals, I use small coils of copper wire. These can be attached easily to crocodile clips or to jumper wires: