Running two Sabertooth 2x5 motor controllers

I’m new to Arduino, this is probably super obvious.

I’ve been trying for a while to run 4 motors via Sabertooth 2x5 motor controllers (Sabertooth 2X5 regenerative dual motor driver - analog, R/C, and serial motor control), but nothing’s been working. I’ve been using the SabertoothSimplified Arduino library to try to accomplish this, which has worked for one motor controller. Everything went crazy when I tried to add a second with slave select.
The documentation can be found here: https://www.dimensionengineering.com/datasheets/Sabertooth2x5.pdf
I read over it and tried this:

#include <SabertoothSimplified.h>

SabertoothSimplified ST;
int port1 = 4;
int port2 = 7;

void setup() {
    pinMode(port1, OUTPUT);
    pinMode(port2, OUTPUT);
    SabertoothTXPinSerial.begin(9600);
}

void loop() {
  int power;
  
  for (power = -127; power <= 127; power ++)
  {
    Sabertooth4(power, power, power, power);
    delay(20);
  }
  
  for (power = 127; power >= -127; power --)
  {
    Sabertooth4(power, power, power, power);
    delay(20);
  }
}

void Sabertooth4(int first, int second, int third, int fourth) {
    digitalWrite(port1, HIGH);
    ST.motor(1, first);
    ST.motor(2, second);
    delayMicroseconds(50);
    digitalWrite(port1, LOW);
    digitalWrite(port2, HIGH);
    ST.motor(1, third);
    ST.motor(2, fourth);
    delayMicroseconds(50);
    digitalWrite(port2, LOW);
}

The code is a variation on the “sweep” example found in the Arduino library but with four motors.

It didn’t work. To make things worse, there are inconsistencies in the documentation and every post I find has a different solution. I’m probably just being dumb, but can anyone help?

PS - I only have access to the Arduino every Wednesday for a few hours, so I’ve been having to write the code over the week and then just pray that it works that Wednesday, so I’m working blindly… One idea I’ve had but couldn’t test yet is skipping slave select all together and using the code in the “softwareserial” example to set up another TX port and run each individually. Is this plausible?

Zman350x:
One idea I’ve had but couldn’t test yet is skipping slave select all together and using the code in the “softwareserial” example to set up another TX port and run each individually. Is this plausible?

From a quick look at the library code, it appears to be. You would create two different objects in your sketch like this:

#include <SabertoothSimplified.h>
#include <SoftwareSerial.h>

const byte ST2RxPin = 2;
const byte ST2TxPin = 3;

SoftwareSerial ST2SerialPort(ST2RxPin, ST2TxPin);  // set up SoftwareSerial  port

SabertoothSimplified ST1;  // controller attached to Serial
SabertoothSimplified ST2(ST2SerialPort);  // controller attached to SoftwareSerial port

void setup() {
   SabertoothTXPinSerial.begin(9600);  // initialize Serial
   ST2SerialPort.begin(9600);  // SoftwareSerial port
}

I added what you suggested into my existing sweep code, think it’ll work?

// SoftwareSerial - Version: Latest 
#include <SoftwareSerial.h>

// Sabertooth Simplified - Version: Latest 
#include <SabertoothSimplified.h>

//setting up serial

const byte softRX = 2;
const byte softTX = 3;
SoftwareSerial softPort(softRX, softTX);

SabertoothSimplified ST12; // Default TX port
SabertoothSimplified ST34(softPort); // Software TX port

void setup()
{
   SabertoothTXPinSerial.begin(9600);  // initialize Serial
   softPort.begin(9600);  // SoftwareSerial port
}
void loop()
{
  int power;
  
  // Ramp from -127 to 127 (full reverse to full forward), waiting 20 ms (1/50th of a second) per value.
  for (power = -127; power <= 127; power ++)
  {
    send(power, power, power, power);
    delay(20);
  }
  
  // Now go back the way we came.
  for (power = 127; power >= -127; power --)
  {
    send(power, power, power, power);
    delay(20);
  }
}
void send(int first, int second, int third, int fourth)
{
  ST12.motor(1, first);
  ST12.motor(2, second);
  ST34.motor(1, third);
  ST34.motor(2, fourth);
}

If you think there’s a high chance It’ll work, I can see about requesting access to the Arduino later today instead of waiting for Wednsday.

It looks right to me, but I have never used this library. Does it compile?

pert:
Does it compile?

It compiles. I’ve asked and I can test it in 45 min (1 PM my time), I’ll let ya know if it works.

It works!!!!

Yay! I'm glad to hear it. Enjoy!

I know it's been a while since I posted on this thread, but software serial is causing conflicts with other parts of the code (Servo library). I found this workaround, Yet Another Software Serial, but am having trouble implementing it in the Sabertooth library.

With the old setup I'd implement it like this:

SoftwareSerial softPort(softRX, softTX);
SabertoothSimplified ST34(softPort); // Software TX port

But the sss.ino has no classes to add to the sabertooth. I don't think I worded this well, but I just need a way to use "Yet Another Software Serial" with the Sabertooths.

Have you tried changing Servo.h for ServoTimer2.h. That often fixes problems with Servos and the standard SoftwareSerial but you do need to change the servo code slightly because the commands aren't identical.

I could maybe give more details but I haven't seen any code that uses servos.

Steve

Tried servotimer2 still didn't work.

O.K I still can't see any code and you've given no details of "still didn't work"(about the most useless problem description ever). So that's the best I can do.

Steve

Here’s the code

//imports

#include <SoftwareSerial.h>
#include <SabertoothSimplified.h>
#include <Servo.h>

//variables

int temp_msg[] = {0,0,0,0,0};
int msg[] = {0,0,0,0,0};
int count;

const byte softRX = 2;
const byte softTX = 3;

SoftwareSerial softPort(softRX, softTX);
SabertoothSimplified ST12; // Default TX port
SabertoothSimplified ST34(softPort); // Software TX port


byte servoPin = 9;
Servo servo;


void setup() {
  Serial.begin(9600); // set the baud rate
  Serial.println("Ready"); // print "Ready" once
  
  SabertoothTXPinSerial.begin(9600);  // initialize Serial
  softPort.begin(9600);  // SoftwareSerial port
  
  servo.attach(servoPin);
  servo.writeMicroseconds(1500);
  delay(7000);
}

void loop() {
  char inByte = ' ';
  
  if(Serial.available()){
  
    char inByte = Serial.read(); // read the incoming data
    if (inByte == 'E') {
      for (int i = 0; i < 6; i++) {
        msg[i] = temp_msg[i];
        temp_msg[i] = 1;
      }
      count = 0;
    }
    else if (inByte == '-'){
      temp_msg[count] = -1;
    }
    else {
      temp_msg[count] = temp_msg[count]* abs((int)inByte);
      count++;
    }
    
  }

  ST12.motor(1, msg[0]);
  ST12.motor(2, msg[1]);
  ST34.motor(1, msg[2]);
  ST34.motor(2, msg[3]);
  servo.writeMicroseconds((msg[4]*400/127)+1500);
}

Sabertooths work fine. Servos go crazy and start spinning randomly and unpredictably. If you comment out:
ST34.motor(1, msg[2]);
ST34.motor(2, msg[3]);
Everything works fine besides the 2 motors you commented out.

Still haven't figured it out. I know this thread's been dead for a while but does anyone know how to fix this?

I know I've been kinda vague, so if you need more info to go off of, just ask!