More years ago than I care to remember (probably 15), I foolishly subscribed to a magazine called Real Robots, published by Eaglemoss. Each monthly part included components which, when you had spent a small fortune buying the magazine, would let you build a robot - Cybot.
I became disillusioned when I realised that all I would be doing was screwing mechanical parts together and plugging in already fully populated PCBs, some of which carried pre-programmed microprocessors: I had assumed more involvement.
By the time I cancelled my subscription I had a 3 wheeled base driven by 2 independent DC motors, with a line follower module,
and a collection of sensors and circuit boards. These were all packed away when I moved house 10 years ago and only unpacked recently when I did some work with lego and a stepper motor and remembered poor old Cybot.
There a few websites devoted to Cybot and one in particular: http://lpilsley.co.uk/cybot/index.htm, is very useful. The site includes functional descriptions of the circuit boards and some reverse engineered circuit diagrams.
Bearing in mind the relative antiquity of anything designed and built around 15 years ago, I decided to keep the sensors (for now) and scrap all the circuit boards, pausing only to carefully unsolder the small, white 2, 3 and 4 pin connectors, which mate with plugs on the sensor leads.
These connectors have proved difficult to identify - I did eventually track them down as XH250 series which are, annoyingly, 2.50 mm pitch! The 2 pin connectors will fit 2.54 mm pitch holes, anything more than 2 pins varies from a struggle to totally impossible. I wouldn't choose to use them. If anyone is interested, the connectors can be found here: http://www.toby.co.uk/content/catalogue/products.aspx?series=XH250-xx-H and a similar connector is available 2.54 mm pitch
My first requirement for the rejuvenation process was a motor drive board:
I tested the motors on 6 V and they draw about 250 mA, well within the capabilities of the L9110 H-Bridge chip - 800 mA continuous.
I sourced this board, which carries two L9110 chips, from eBay, for a very modest sum. It can drive 2 DC motors or 1 stepper motor.
The motors leads were terminated with the 2 pin connectors mentioned earlier. Rather than clip them off, I made up some extension leads, using the salvaged connectors from the scrapped circuit boards:
The other ends of the extensions then connect directly into the screw terminal outputs of the L9110 board.
Driving the L9110 and the motors
There is plenty of guidance on how to write a sketch to test the L9110 board and the motors, in particular:
and:
http://www.bajdi.com/l9110-h-bridge-module/
The bananarobotics link includes a truth table for the L9110 and an Arduino sketch to control a single motor. I tried the sketch and was pleased to see that it worked precisely as expected. However, the way in which the variables were defined was a little cumbersome for my own coding style, so I modified all of that and then created a set of functions to replace the original in-line code.
Everything still worked fine, but there was still a bit of potential confusion because, although the sketch uses 2 PWM capable digital pins - 10 and 11, only pin 10 is actually used in PWM mode, whilst 11 - the "direction" pin - is either high or low. This results in a need to fiddle with the PWM duty cycle between forward and reverse to get the same speed. The following code segment (using my version) should make this clear:
#define B_IA 10 // D10 --> Motor B Input A #define B_IB 11 // D11 --> Motor B Input B #define motorBSpeed B_IA // Motor B PWM Speed #define motorBDirection B_IB // Motor B Direction void forward(int thisSpeed) { softStop(); delay( DIR_DELAY ); // set the motor speed and direction digitalWrite( motorBDirection, HIGH ); // direction = forward analogWrite( motorBSpeed, 255-thisSpeed ); } void reverse(int thisSpeed) { softStop(); delay( DIR_DELAY ); // set the motor speed and direction digitalWrite( motorBDirection, LOW ); // direction = reverse analogWrite( motorBSpeed, thisSpeed ); }
- in forward mode, the PWM duty cycle is set to be ( 255 - desired speed ), with direction pin high
- in reverse mode, the PWM duty cycle is set to be ( desired speed ), with the direction pin low
In order to achieve the same speed in both directions. This seemed a little confusing.
I then got into a bit of trouble when I modified the sketch to control 2 motors - I assigned pins 8 and 9 for the second motor, keeping things in order. I didn't remember that pin 8 is NOT PWM, so it didn't work properly. I had to switch 8 and 9 around. I got there in the end!
I then took a detailed look at the sketch provided by Bajdi. This uses all the pins in PWM mode and presents a very straightforward view of the speed issue. I preferred the Bananarobotics menu driven approach so I changed the pin assignments and the detail of the functions in my own sketch to use those from Bajdi's example:
const int AIA = 9; // (pwm) pin 9 connected to pin A-IA const int AIB = 5; // (pwm) pin 5 connected to pin A-IB const int BIA = 10; // (pwm) pin 10 connected to pin B-IA const int BIB = 6; // (pwm) pin 6 connected to pin B-IB void forward(byte thisSpeed) { softStop(); delay(pause); // set the motor speed and direction analogWrite(AIA, thisSpeed); analogWrite(AIB, 0); analogWrite(BIA, thisSpeed); analogWrite(BIB, 0); } void reverse(byte thisSpeed) { softStop(); delay(pause); // set the motor speed and direction analogWrite(AIA, 0); analogWrite(AIB, thisSpeed); analogWrite(BIA, 0); analogWrite(BIB, thisSpeed); }
I hope most people will agree that this is far less confusing.
I then added Left and Right turn functions into my sketch. In the example given by Bajdi, the two motors were run in opposite directions. This produces a "spin" rather than a turn. I decided to change it so that both motors run in the same direction, but one runs slower than the other.
At this point, the Cybot is upside down, so that I can run the motors; the motor drive board is powered from a breadboard 5 V PSU and the Arduino UNO is still connected to my PC so that it gets power and I can control the motors via the serial monitor.
In my next Blog post I will add Bluetooth communication to the Cybot and also liberate the Aruino and the motor driver board by running them from batteries (separate, of course).
The Arduino Sketch up to this point is attached.
Top Comments