Saturday, 26 May 2012

Sabre Tooth Motor Controller

I've got quadrature encoders working to measure speed and they're now attached to MmBot (although not wired to the arduino yet). Next I need to replace my very basic home made motor controller with the nice Sabre Tooth one I have. In a much earlier post I had a first blast at this but it turned out I had the Sabre Tooth RC. Fortunately, my standard Sabre Tooth 2x5 has now arrived which supports serial communication, and here it is:

Sabre Tooth 2x5 Motor Controller
It's a neat little piece of kit. On the left you can see the motor power connection, with the motor connectors top and bottom. On the right is GND and Vcc coming from Arduino, plus a white signal cable. This controller can run in lots of different modes which are configured with the switches at the bottom.

After a bit of experimentation I find the right setup for a simple serial connection at 9600 baud rate. In this mode you send the motor a value from 1 to 127 to control motor A (1=full reverse, 64=stop,127=full forwards), and 128 to 255 to control motor B in a similar fashion.  In addition, sending a 0 instantly stops both motors.

To get things going, here's the first basic circuit I build:

Circuit diagram of Arduino connected to Sabre Tooth
It's a pretty simple setup. On the left I have the Sabre Tooth connected to a 12V battery, a 12V DC motor , and (instead of another motor) the oscilliscope. On the right you can see the Arduino wired up, with GPIO3 going to the signal 1 connector. Signal 2 is not needed for serial communication. With this setup I can control the actual motor by sending values from 1 to 127, and I can monitor the signals that get sent to a motor by sending values from 128 to 255.

So that's the circuit, here it is built:

Arduino connected to Sabre Tooth, controlling a 12V DC motor.
All pretty simple so far, and now for some equally simple code:


#include <SoftwareSerial.h>

SoftwareSerial MotorSerial(3,2);

void setup()  
{
  MotorSerial.begin(9600);

  Serial.begin(9600);
  Serial.println("Hello"); 
}

void loop()
{
  //gradually take motors from full stop to full reverse
  for(int i = 64; i >= 1; i--)
  {
    MotorSerial.write(i);
    MotorSerial.write(i+128);
    delay(100);
  }
  
  //take motors from full reverse, back to stop and then to full forwards
  for(int i = 1; i <= 127; i++)
  {
    MotorSerial.write(i);
    MotorSerial.write(i+128);
    delay(100);
  }
  
  //take motors back down to full stop
  for(int i = 127; i >= 64; i--)
  {
    MotorSerial.write(i);
    MotorSerial.write(i+128);
    delay(100);
  }
}

In the setup function I simply initialize a software serial connection, which is transmitting via GPIO 3 at 9600 baud. The main loop simply sends different values to the motors to slowly get to full speed in one direction,  then gradually go to full speed in the other direction, and eventually come back to a stop.

And finally, a video of it in action:


All good. Massive thumbs up to Dimension Engineering - this piece of kit isn't just really powerful - it's really easy to use. Not the cheapest of controlellers, but I'd highly recommend it if you're willing to spend a few pounds.


1 comment: