Serial Communication to Sabertooth Motor Contol

Newbie here,

I'll try not to waste anyone's time. I work with PLC controllers and programs and automation with electronics back ground but lost right now. My project is a power wheels for my son.

Arduino UNO R3 is my micro-controller.

Sabertooth 2X25 V2-motor sheild
Specifications: 25A continuous, 50A peak per channel, 6-30V nominal, 33.6V absolute maximum

I would like to try: simplified serial if that won't work packetized serial instead of analog(PWM), I have read both manuals front to back. just looking for some direction on setup of my memory and program.
Steps to setup:
After I set the baud rate, and input from the pedal.
How can I split these values 1-255 , 0x00 is fault code shutdown and store in memory or load memory at start up and create a decent ramp. I'm used to bit manipulation with a clock is why I ask if this is possible.

Any setup tips would be great. You don't have to go in great detail just one word steps will help at this point.

I wanted to add a few things. I'm looking for idea of a setup.

I've read about

Using arrays and calling to serial print.

Using math instructions and so on

But i need something that can loop according to the input which also has reverse. I have some control on the motor control board to fine tune the ramp I believe some others.

Simplified Serial transmission.
Motor one:
1 is full reverse 63 is slowest reverse speed, 64 is stop, 65 to 127 is full forward.
Motor two:
128 to 191 is reverse slowest to fastest, 192 is stop, 193 to 255 is forward from slowest to fastest.

Post a link to the datasheet for your shield.

What Arduino are you using?

Shield makers usually have demonstration programs - have you tried them?

...R

Here is the link for the motor control Sabertooth 2X25 V2 regenerative dual motor driver

This is what I'm referring to, but when I look at the library available and I get lost in their translation. Like variable scope, int, define it relies on different paths to access to memory. Declaring in the loop or before. I kinda have information overload. I am getting closer to understanding and It just comes down to the language, syntax .

Should I use stream to build bytes, or should I use math instructions and build from my start byte 65 to 127 and 193 to 255 will that write better to transmit. I also read not to use print and to use write with the serial command. I may be mixing this up at this point.

Option 1: Standard Simplified Serial Mode

Serial data is sent to input S1. The baud rate is selected with switches 4 and 5. Commands are sent as single bytes. Sending a value of 1-127 will command motor 1 Sending a value of 128-255 will command motor 2. Sending a value of 0 will shut down both motors.

Simplified Serial with Slave Select

Option 2: Simplified Serial with Slave Select

This mode is used when it is desirable to have multiple Sabertooth motor drivers running from the same serial transmitter, but you do not wish to use packetized serial. A digital signal (0V or 5V) is fed to the S2 input. This is controlled by the host microcontroller. If the signal on S2 is logic high (5V) when the serial command is sent, the driver will change to the new speed. If the signal on S2 is not high when the command is sent, then command will be ignored. Pseudo-code demonstrating this is shown below. After sending the signal, allow about 50 us before commanding the Slave Select line to a logic LOW to allow time for processing. A hookup diagram and example pseudo-code are shown in Figures 6.2 and 6.3.

Can you post one of the example programs here (the simplest one) so we can see it?

Can you post a link to (or an extract from) the document that defines the serial commands?

I would expect that you can create the serial commands with Serial.print() or Serial.write()

...R

I did find this today and realized I had already downloaded it but it wasn't the entire program the first time.

It was :#include <SabertoothSimplified.h> //so is this allowing them to address the way they are.
This is something I been confused on.

My idea of code wasn't 127 for motor control but binary or hex etc. Still trying to get an overall clearer picture. I might order the book from adafruit I hear is probably the best for newbies. Im trying to get to a point where I can start to add the features like lights, radio, traction control and see how far me and the board can go. I work in automation so I have the best access for good sensors of all shape sizes to add for features.

This seems to simple or they just didn't show the setup and var,def etc?
#include <SabertoothSimplified.h>
SabertoothSimplified ST; // We'll name the Sabertooth object ST.
// For how to configure the Sabertooth, see the DIP Switch Wizard for
// Sabertooth 2X25, 2X12 and 2X5 DIP switch configuration wizard
// Be sure to select Simplified Serial Mode for use with this library.
// This sample uses a baud rate of 9600.
//
// Connections to make:
// Arduino TX->1 -> Sabertooth S1
// Arduino GND -> Sabertooth 0V
// Arduino VIN -> Sabertooth 5V (OPTIONAL, if you want the Sabertooth to power the Arduino)
//
// If you want to use a pin other than TX->1, see the SoftwareSerial example.

void setup()
{
SabertoothTXPinSerial.begin(9600); // This is the baud rate you chose with the DIP switches.
}
void loop()
{
ST.motor(1, 127); // Go forward at full power.
delay(2000); // Wait 2 seconds.
ST.motor(1, 0); // Stop.
delay(2000); // Wait 2 seconds.
ST.motor(1, -127); // Reverse at full power.
delay(2000); // Wait 2 seconds.
ST.motor(1, 0); // Stop.
delay(2000);
}

Post above #3 has the commands and post #1 has the break down. They are from the manual Ill check for anything else.

The are the only two options for Simple serial
Option 1: Standard Simplified Serial Mode

Mode 3: Simplified Serial Mode

Simplified serial uses TTL level single-byte serial commands to set the motor speed and direction. This makes it easy to interface to microcontrollers and PCs, without having to implement a packet-based communications protocol. Simplified serial is a one-direction only interface. The transmit line from the host is connected to S1. The host’s receive line is not connected to the Sabertooth. Because of this, multiple drivers can be connected to the same serial transmitter. If using a true RS-232 device like a PC’s serial port, it is necessary to use a level converter to shift the –10V to 10V RS-232 levels to the 0V to 5V TTL levels the Sabertooth is expecting. This is usually done with a Max232 type chip. If using a TTL serial device like a microcontroller or a USB-to-TTL serial converter, the TX line may be connected directly to S1.

Because Sabertooth controls two motors with one 8 byte character, when operating in Simplified Serial mode, each motor has 7 bits of resolution. Sending a character between 1 and 127 will control motor 1. 1 is full reverse, 64 is stop and 127 is full forward. Sending a character between 128 and 255 will control motor 2. 128 is full reverse, 192 is stop and 255 is full forward. Character 0 (hex 0x00) is a special case. Sending this character will shut down both motors.

Baud Rate Selection

Simplified Serial operates with an 8N1 protocol – 8 data bytes, no parity bits and one stop bit. The baud rate is selected by switches 4 and 5 from the following 4 options:

Serial data is sent to input S1. The baud rate is selected with switches 4 and 5. Commands are sent as single bytes. Sending a value of 1-127 will command motor 1 Sending a value of 128-255 will command motor 2. Sending a value of 0 will shut down both motors.

Option 2: Simplified Serial with Slave Select

This mode is used when it is desirable to have multiple Sabertooth motor drivers running from the same serial transmitter, but you do not wish to use packetized serial. A digital signal (0V or 5V) is fed to the S2 input. This is controlled by the host microcontroller. If the signal on S2 is logic high (5V) when the serial command is sent, the driver will change to the new speed. If the signal on S2 is not high when the command is sent, then command will be ignored. Pseudo-code demonstrating this is shown below. After sending the signal, allow about 50 us before commanding the Slave Select line to a logic LOW to allow time for processing. A hookup diagram and example pseudo-code are shown in Figures 6.2 and 6.3.

Thanks for taking a look at this btw Robin2

If this works

void loop()
{
  ST.motor(1, 127);  // Go forward at full power.
  delay(2000);       // Wait 2 seconds.
  ST.motor(1, 0);    // Stop.
  delay(2000);       // Wait 2 seconds.
  ST.motor(1, -127); // Reverse at full power.
  delay(2000);       // Wait 2 seconds.
  ST.motor(1, 0);    // Stop.
  delay(2000);
}

I don't understand what question you want help with. It seems to be very straightforward.

...R

Ok I'm back after much research. To answer Robin2 question that's not the program I want. Originally I wanted to use 0-255 to control my motor. I would eventually try all modes and all modes should work but I haven't figured much out if other modes work or not because i decided to start over. This is a generic program that I would like to monitor to see what is being sent out. I've set this up in the past with some help for another project but it was continuous stream of data.

At this point I now have an issue with motor 1 not spin and motor 2 is. The first time around(earlier post) i was getting an uninitialized error using 0-255 for motor commands with leakage of about a 1.5 amps on motor 2. It seemed to not be taking the saber tooth library so I deleted everything including the IDE.

I'm not longer getting those error. But doesn't seem to compile like it did before. Before during compiling in the message area I was able to scroll up in the message box on the IDE and read the literature of the compiling and it display a lot of info including the uninitialized commands of 0-255 motor commands in red which is why I thought it wasn't taking the <Sabertoothsimplified.h> library. Now I have nothing to view of the compiling process and I've deleted what monitor program i had previously.

Can someone throw me a bone on setting up monitor to see what is being sent. I talk to dimension engineering who makes the MC and after testing everything they asked, they seem to think the MC is ok.

I assure you, I'm not trying to take the short road or be a "wanna be programmer" or waste anyone's time. At this point I tried so much I back to being confused and ready to move on to a different MC. I really don't want to be out $130

ST.ino (453 Bytes)

Also disregard the #define portion of the program I was trying something there.

Back in Reply #4 I asked you to post a link to the document that defines the serial commands.

Without that I know even less about your problem than you do.

And for short programs please include them in your post between [code] [/code] tags so we don't have to download them. Your code shouldlook like thisand that also makes it easy to copy to a text editor

...R

First: Thank you Robin2 for sticking with me. I apologize, I try to cover every thing.

link for Library protocols in simplified serial:

https://www.dimensionengineering.com/software/SabertoothSimplifiedArduinoLibrary/html/class_sabertooth_simplified.html#aa86e4264ceee0475b8fb33eab4086403

Manual Link to MC:

On a side note: the math for baud rate doesn't add up to me. And it say the comms. are one 8 byte character with 7 bit resolution for each motor. Does this add up to you?

"Because Sabertooth controls two motors with one 8 byte character, when operating in Simplified Serial mode, each motor has 7 bits of resolution."

The manufacturing doesn't show any examples using 0-255 for the motor commands but they assured me it works.

I also have tried to connect using the describe software(had absolutely no issue previously you my dell my back up HP laptop is messing with me or there is an issue. because it won't connect.

In the end, I hope this is a dumb error on my part!

I'm just testing this to see how it post:

#include <SabertoothSimplified.h>


 SabertoothSimplified ST;


int stop = 0;

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

}

void loop() 
{
   
  ST.motor(1,stop);
  ST.motor(2,stop);
  delay(5000);

  ST.motor(1,127);
  ST.motor(2,127);
  delay(5000);

  





return ;

}

riande83:
I'm just testing this to see how it post:

#include <SabertoothSimplified.h>

SabertoothSimplified ST;

int stop = 0;

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

}

void loop()
{
 
  ST.motor(1,stop);
  ST.motor(2,stop);
  delay(5000);

ST.motor(1,127);
  ST.motor(2,127);
  delay(5000);

return ;

}

This looks like it would.make motor one run at 100 percent and motor two would do nothing.

The serial command is an 8 bit number with its range split in the middle between the two motors so a 7 bit resolution. 2^7 = 128.

So.if you send 64 via serial motor one will be stopped. If you send the value 200 motor two will be stopped.

Sending 127 makes motor one run at 100 percent in the forward direction. Sending 127 then 255 makes both motors run forward full speed. Sending 1 and then 129 makes both motors run reverse at full speed.

Seems simple enough 1-127 for motor one and 128-255 for motor two. 7 bit resolution.

Is the problem you need more resolution? For troubleshooting can't you just open a serial terminal and send the values manually?

I don't think @alka is at all correct in Reply #13.

From looking at this simplified link the code you have in Reply #12 looks correct. If only one motor is working maybe there is a wiring problem.

...R

Robin2:
I don't think @alka is at all correct in Reply #13.

From looking at this simplified link the code you have in Reply #12 looks correct. If only one motor is working maybe there is a wiring problem.

...R

Sorry I didn't look at the sabertoothsimplified class. It looks like that takes a -127 to 127 range as you said. I was talking about just sending serial commands.

This is what the op posted however. I believe quoted from the manual.

"Serial data is sent to input S1. The baud rate is selected with switches 4 and 5. Commands are sent as single bytes. Sending a value of 1-127 will command motor 1 Sending a value of 128-255 will command motor 2. Sending a value of 0 will shut down both motors"

alka:
I believe quoted from the manual.

Not your fault but the non-simplified serial system is a lot more complex than that quote.

The packet format for the Sabertooth consists of an address byte, a command byte, a data byte and a seven bit checksum.

...R

Robin2:
Not your fault but the non-simplified serial system is a lot more complex than that quote.
...R

Hmm, something seems more confusing than it should be.. I was talking about the simple serial mode. As in the dip switches are set to simple serial but NOT using the provided library. You should be able to just write the serial commands. That's what I read in the manual. Packettized serial is a bit more complicated.

Not much point discussing this without input from the OP.

...R

I've tried using:

0-255 and still just one motor turns. I switch the motors on the MC terminals to test motors. They are good.

-127 to 127 and still only one motor turns.

At this point I requested the manufacture take a look at it for inspection. They had me test(switches all on except 4) to test output. I have a voltage drop of 4v and 5v on M1 and M2 and they say this is ok. Not sure why its ok for them to be different.

As far as the wiring, there is four wires: 2 for power (from the battery) and 2 from the Uno (Tx to S1 and grd to 0v).

At this point until they send me return instructions, I will work on packet serial mode or something for more testing.

Does anyone know of another Mc I can purchase that is durable and a good start for a newbie? That is why I purchased a sabertooth in the first place.