Hello,
I'm currently using an Arduino Duemilanove to send commands to a motor controller, the Saberthooth 2x25.
Current setup:
Arduino -->GND Wire + Signal Wire --> Sabertooth (as per Sabertooth datasheet linked)
Whenever I send commands to the Sabertooth, whether via their 'Simplified' or 'Parallelized' serial protocol, the motor the Sabertooth is attached to is getting bad commands.
So far, I can tell that the Arduino is receiving the correct ASCII character (one at a time) via Serial, but I think I may be incorrectly interpreting the received character for the outgoing message. This is because the serial protocol I'm using incorporates a checksum as part of each packet, and the Sabertooth won't act unless the checksum is correct.
My code (seems to be...) tells me over the Serial Monitor that the correct speed setting is being sent (and correctly identifies the command received based on input value). But the motor itself spins at the wrong speed and direction each time.
I was hoping someone with sharper ATmega eyes than mine could see if I'm somehow miss-mapping the received bytes.
In short:
Arduino interfacing with Sabertooth 2x25 motor controller.
Arduino reads incoming serial correctly.
Sabertooth reads correct checksums.
Sabertooth spins motor incorrectly.
Possible mis-mapping issue, interpretation on the ATmega's end.
Thank you for any help on this.
/* Send a byte via hardware serial to the Sabertooth using Parallelized Serial Interface */
void SendCommand(byte command, byte rate) {
byte checksum;
Serial.print(SABERTOOTH_ADDRESS, BYTE);
Serial.print(command, BYTE);
Serial.print(rate, BYTE);
Serial.print ( ((SABERTOOTH_ADDRESS + command + rate) & 0b01111111), BYTE); //checksum
delay(5);
}
void setup(){
//Hardware Serial
Serial.begin(SABERTOOTH_BAUDRATE);
delay(2000); //required delay for Sabertooth
Serial.print(170, BYTE); //bauding character to Sabertooth
}
byte reader = 0;
byte command = 0;
void loop() {
delay(100);
if (Serial.available() > 0) {
reader = Serial.read();
//Serial.println(reader);
if (reader == 48) {
reader = 0;
}
else if (reader >= 65 && reader <= 90 ) {
reader = map(reader, 65, 90, 0, 127);
command = 9;
}
else {
reader = map(reader, 97, 122, 0, 127);
command = 8;
}
SendCommand(command, reader);
/*
Serial.print("Command: ");
Serial.println(command, DEC);
Serial.print("Value: ");
Serial.print(reader);
Serial.print(" as: ");
Serial.println(reader, DEC);
*/
} //end of serial loop, nothing else happens here
}