Using an Arduino to control a Bigtrak.

All of the code from this post is on GitHub here, because WordPress doesn’t seem to display it correctly.

Hi everyone. I realise I haven’t written anything for more than two months, and I apologise. I’ve just been really busy recently.

I still haven’t been able to get a good language model working. When I get some more time, I’ll try and either change the size of the neural network or use a more powerful computer and more training data. Just remember that it’s in the pipeline.

Anyway, we’re taking a break from machine learning now to do some robotics. Here’s what you’ll need:

• Bigtrak
• an Arduino Mega or other Arduino with a 5V logic level
• L298N dual H-bridge motor driver (like this)
• Some cables
• 5x 1.5V AA batteries
• USB power bank
• Soldering iron and solder
• Screwdrivers

You can get the motor driver board and a battery holder cheaply from China, or if you want them quickly you can pay slightly more to buy them locally.

Step 1: Disassembling the Bigtrak

There are several screws that secure the top half of the Bigtrak case to the bottom half. These should be undone to open it up. Remember that you keep them safe for later!

The back of the Bigtrak is the hard part. There’s a clever trick on Peter Vis’ website here. The grey plastic part on the back of the Bigtrak needs to be taken off to reveal the hidden screw holding the case together. There are four tabs holding it on. I used some pliers to force the two tabs on either side out from inside individually and then used the card trick on the website to undo the back tabs before sliding the grey plastic out. Then I could undo the annoying hidden screw.

Inside, there is a white ribbon cable connecting to the keypad. Use a small screwdriver to undo this from the circuit board inside. Then you should cut the black, red and yellow cable for the power switch to separate both halves of the case.

Undo the screws holding the PCB on to the case. You will find that it is still soldered on. These are the contacts for the motors – two on each side as you can see in the photo below.

You now need to use a soldering iron to desolder the PCB from the contacts, which should be quite straightforward.

Once you have done that, you can pull the circuit board out. The black box underneath is the gearbox – I didn’t open it, in case I couldn’t get it back together again.

Step 2: Adding the cables

Now we need to solder some cables on to the motor contacts – four in total (two for each motor). The contacts should now look something like this terrible photo:

Part 3: Wiring

You should now screw the cables for the motors into the blue output sockets on either side of the driver board.

Now we need to connect the Arduino to the driver. Each motor needs 3 inputs to control it – Input A, Input B and motor enable. Inputs A and B are used to control the direction of the motor. If A is high and B is low, the motor goes forward whereas if B is high and A is low the motor goes backwards. If they are both high or low, the motor stops.

The motor enable pin is used to control the motor’s speed. It is connected to a PWM signal – the higher the duty cycle, the faster the motor’s speed. It originally has a jumper on it connecting it to 5V – this means that the motor would just rotate at full speed. To control the speed, we need to take off the jumper and connect the pin to an Arduino PWM pin.

Here’s a wiring diagram:

As you can see, the driver is connected to the Arduino via 7 pins – 3 for each motor and a ground pin. If you’re using a different arduino board, you can substitute the pins for the equivalent on your board, but you’ll have to change the pin numbers in the code later. Also, make sure they’re connected to the correct type of pins – 4 digital pins for direction control, 2 analog pins for PWM speed control and a ground pin to create a common ground. If you want to, you can use one of the holes in the Arduino Mega to attach it to the Bigtrak with one of the screw holes for the original PCB. The inside should now look something like this:

If you don’t want to connect the arduino to a USB power bank, the driver has a 5V voltage regulator built in. The blue connector next to ground that is not being used is 5V. You can connect this and ground to the Arduino to power it off the same batteries as the motors.

Part 4: Code

Now we need to try making the Bigtrak move to make sure everything works. Time to open the Arduino IDE and start typing!

int B1Out = 4;
int B2Out = 5;
int A1Out = 6;
int A2Out = 7;
int APWM = 8;
int BPWM = 9;

Firstly we have to define all of the pin numbers – 2 digital pins for each motor and one analog pin for each motor.
void setup() {
pinMode(A1Out, OUTPUT);
pinMode(A2Out, OUTPUT);
pinMode(B1Out, OUTPUT);
pinMode(B2Out, OUTPUT);
pinMode(APWM, OUTPUT);
pinMode(BPWM, OUTPUT);
}

Secondly we have to configure all of the pins as output pins.
void loop() {
analogWrite(APWM, 200);
analogWrite(BPWM, 200);
digitalWrite(A1Out, LOW);
digitalWrite(A2Out, HIGH);
digitalWrite(B1Out, LOW);
digitalWrite(B2Out, HIGH);
delay(2000);
digitalWrite(A1Out, LOW);
digitalWrite(A2Out, LOW);
digitalWrite(B1Out, LOW);
digitalWrite(B2Out, LOW);
delay(1000);

We then start the PWM signal and instruct the motors to go forward for two seconds before stopping for one second.
digitalWrite(A1Out, HIGH);
digitalWrite(A2Out, LOW);
digitalWrite(B1Out, HIGH);
digitalWrite(B2Out, LOW);
delay(2000);
digitalWrite(A1Out, LOW);
digitalWrite(A2Out, LOW);
digitalWrite(B1Out, LOW);
digitalWrite(B2Out, LOW);
delay(1000);
}

Finally, we instruct the motors to go backwards for two seconds and stop for one second.
Here’s the code all together:

int B1Out = 4;
int B2Out = 5;
int A1Out = 6;
int A2Out = 7;
int APWM = 8;
int BPWM = 9;

void setup() {
pinMode(A1Out, OUTPUT);
pinMode(A2Out, OUTPUT);
pinMode(B1Out, OUTPUT);
pinMode(B2Out, OUTPUT);
pinMode(APWM, OUTPUT);
pinMode(BPWM, OUTPUT);
}

void loop() {
analogWrite(APWM, 200);
analogWrite(BPWM, 200);
digitalWrite(A1Out, LOW);
digitalWrite(A2Out, HIGH);
digitalWrite(B1Out, LOW);
digitalWrite(B2Out, HIGH);
delay(2000);
digitalWrite(A1Out, LOW);
digitalWrite(A2Out, LOW);
digitalWrite(B1Out, LOW);
digitalWrite(B2Out, LOW);
delay(1000);
digitalWrite(A1Out, HIGH);
digitalWrite(A2Out, LOW);
digitalWrite(B1Out, HIGH);
digitalWrite(B2Out, LOW);
delay(2000);
digitalWrite(A1Out, LOW);
digitalWrite(A2Out, LOW);
digitalWrite(B1Out, LOW);
digitalWrite(B2Out, LOW);
delay(1000);
}

When you upload the code to the Arduino, you should find that it moves forward and backwards repeatedly. Ta da! If the motors are rotating in different directions and it’s rotating on the spot, you can swap around the wires connecting one of the motors to the driver.
If it isn’t moving at all, make sure that your batteries are supplying more than 5V. At first I tried to use 5V but I found that the motor driver didn’t work with the PWM signal when the voltage was that low. Try reattaching the jumpers on the enable pins and see if it works then.
A word of warning: The Bigtrak originally used 3x 1.5v batteries to supply 4.5v for the motors. We’re now supplying 7.5v. However, there is a 2v drop across the driver, so the motors at most get 5.5v. This is still a little high for my liking – I don’t want the motors to burn out. Therefore, we need a maximum of 4.5v out of 5.5v – to ensure this, we can keep the PWM signal below a certain value (255 is the maximum value). $\frac{4.5}{5.5} \times 255$ makes 208, so we should keep the analogWrite values below about 200.
In the next blog when we’ll make the Bigtrak remote controllable!

__ATA.cmd.push(function() {
__ATA.initVideoSlot('atatags-370373-5d7ddab7d8a97', {
sectionId: '370373',
format: 'inread'
});
});

Advertisements

__ATA.cmd.push(function() {
__ATA.initSlot('atatags-26942-5d7ddab7d8ac0',  {
collapseEmpty: 'before',
sectionId: '26942',
location: 120,
width: 300,
height: 250
});
});

__ATA.cmd.push(function() {
__ATA.initSlot('atatags-114160-5d7ddab7d8ac5',  {
collapseEmpty: 'before',
sectionId: '114160',
location: 130,
width: 300,
height: 250
});
});

Share this:TwitterFacebookEmailPrintLinkedInRedditLike this:Like Loading...