PDA

View Full Version : Arduino and Sabertooth 2x5 ?



Migs
10-16-2009, 05:15 PM
Friends:

Do you have some code and hook up of driving a Sabertooth 2x5 motor controller from an Arduino microcontroller?

Thanks in advance,

Migs

Adrenalynn
10-16-2009, 05:31 PM
At it's simplest - just use PWM and treat it exactly like two servos.

http://www.arduino.cc/playground/ComponentLib/Servo

Migs
10-18-2009, 09:36 AM
Thanks Adrenalyn! This was just what I was looking for. -Migs

Noog
01-09-2010, 10:56 AM
Do you have some code and hook up of driving a Sabertooth 2x5 motor controller from an Arduino microcontroller?



I was trolling through the archives when I saw this thread. I see that the original poster already had their answer, but I figured I would post this just in case anyone else could use this in the future .

I did a little project a while ago where I connected a Sabertooth 2x5 to an Arduino using the simplified serial protocol over a software serial port.

Don't forget that the DIP switch wizard can be found here:
http://dimensionengineering.com/datasheets/Sabertoothdipwizard/start.htm

Sabertooth routines:
(NOTE: setEngineSpeed will control both motors at the same time.)


#include <SoftwareSerial.h>

/************************************************** ***
* DIP Switches as per the wized:
* - NiMh Battery
* - TTL RS232
* - Simplified Serial Mode
* - Just one Sabertooth conected
* - 9600 baudrate
*
* Pin 1 - ON
* Pin 2 - OFF
* Pin 3 - ON
* Pin 4 - OFF
* Pin 5 - ON
* Pin 6 - ON
************************************************** **/

// Labels for use with the Sabertooth 2x5 motor controller

// Digital pin 13 is the serial transmit pin to the
// Sabertooth 2x5
#define SABER_TX_PIN 13

// NOT USED (but still init'd)
// Digital pin 12 is the serial receive pin from the
// Sabertooth 2x5
#define SABER_RX_PIN 12

// Set to 9600 through Sabertooth dip switches
#define SABER_BAUDRATE 9600

// Simplified serial Limits for each motor
#define SABER_MOTOR1_FULL_FORWARD 127
#define SABER_MOTOR1_FULL_REVERSE 1

#define SABER_MOTOR2_FULL_FORWARD 255
#define SABER_MOTOR2_FULL_REVERSE 128

// Motor level to send when issuing the full stop command
#define SABER_ALL_STOP 0


SoftwareSerial SaberSerial = SoftwareSerial( SABER_RX_PIN,
SABER_TX_PIN );

void initSabertooth( void )
{
// Init software UART to communicate
// with the Sabertooth 2x5
pinMode( SABER_TX_PIN, OUTPUT );

SaberSerial.begin( SABER_BAUDRATE );

// 2 second time delay for the Sabertooth to init
delay( 2000 );

// Send full stop command
setEngineSpeed( SABER_ALL_STOP );
}

/************************************************** ***
* setEngineSpeed
*
* Inputs - cSpeed_Motor1 - Input a percentage of full
* speed, from -100 to +100
*
************************************************** ***/
void setEngineSpeed( signed char cNewMotorSpeed )
{
unsigned char cSpeedVal_Motor1 = 0;

unsigned char cSpeedVal_Motor2 = 0;

// Check for full stop command
if( cNewMotorSpeed == 0 )
{
// Send full stop command for both motors
SaberSerial.print( 0, BYTE );

return;
}

// Calculate the speed value for motor 1
if( cNewMotorSpeed >= 100 )
{
cSpeedVal_Motor1 = SABER_MOTOR1_FULL_FORWARD;

cSpeedVal_Motor2 = SABER_MOTOR2_FULL_FORWARD;
}
else if( cNewMotorSpeed <= -100 )
{
cSpeedVal_Motor1 = SABER_MOTOR1_FULL_REVERSE;

cSpeedVal_Motor2 = SABER_MOTOR2_FULL_REVERSE;
}
else
{
// Calc motor 1 speed (Final value ranges from 1 to 127)
cSpeedVal_Motor1 = map( cNewMotorSpeed,
-100,
100,
SABER_MOTOR1_FULL_REVERSE,
SABER_MOTOR1_FULL_FORWARD );

// Calc motor 2 speed (Final value ranges from 128 to 255)
cSpeedVal_Motor2 = map( cNewMotorSpeed,
-100,
100,
SABER_MOTOR2_FULL_REVERSE,
SABER_MOTOR2_FULL_FORWARD );
}

// Fire the values off to the Sabertooth motor controller
SaberSerial.print( cSpeedVal_Motor1, BYTE );

SaberSerial.print( cSpeedVal_Motor2, BYTE );
}
Calling the routines:


void setup( )
{
initSabertooth( );
}

void loop ( )
{
// Full stop
setEngineSpeed( 0 );

// Half reverse
setEngineSpeed( -50 );

// Full reverse
setEngineSpeed( -100 );

// Half forward
setEngineSpeed( 50 );

// Full forward
setEngineSpeed( 100 );
}
Enjoy!

Noog

jes1510
01-09-2010, 02:16 PM
I don't have a sabertooth but you code may be helpful to people in the futre. Thanks for posting it!

charlieo
02-19-2010, 12:13 AM
Noog,

Did you use any decoupling filter between Arduino and the Sabertooth?

Thanks,
Charlie O

Noog
02-19-2010, 08:32 AM
Did you use any decoupling filter between Arduino and the Sabertooth?


Initially no, I connected them directly to each other. Since both boards were running at 5V there was no problems with the connection. After a little bit, I did separate them from each other with an optoisolator. Both configurations worked fine for me.

Noog

tank
09-30-2010, 02:21 AM
I was trolling through the archives when I saw this thread. I see that the original poster already had their answer, but I figured I would post this just in case anyone else could use this in the future .

I did a little project a while ago where I connected a Sabertooth 2x5 to an Arduino using the simplified serial protocol over a software serial port.

Don't forget that the DIP switch wizard can be found here:
http://dimensionengineering.com/datasheets/Sabertoothdipwizard/start.htm

Sabertooth routines:
(NOTE: setEngineSpeed will control both motors at the same time.)


#include <SoftwareSerial.h>

/************************************************** ***
* DIP Switches as per the wized:
* - NiMh Battery
* - TTL RS232
* - Simplified Serial Mode
* - Just one Sabertooth conected
* - 9600 baudrate
*
* Pin 1 - ON
* Pin 2 - OFF
* Pin 3 - ON
* Pin 4 - OFF
* Pin 5 - ON
* Pin 6 - ON
************************************************** **/

// Labels for use with the Sabertooth 2x5 motor controller

// Digital pin 13 is the serial transmit pin to the
// Sabertooth 2x5
#define SABER_TX_PIN 13

// NOT USED (but still init'd)
// Digital pin 12 is the serial receive pin from the
// Sabertooth 2x5
#define SABER_RX_PIN 12

// Set to 9600 through Sabertooth dip switches
#define SABER_BAUDRATE 9600

// Simplified serial Limits for each motor
#define SABER_MOTOR1_FULL_FORWARD 127
#define SABER_MOTOR1_FULL_REVERSE 1

#define SABER_MOTOR2_FULL_FORWARD 255
#define SABER_MOTOR2_FULL_REVERSE 128

// Motor level to send when issuing the full stop command
#define SABER_ALL_STOP 0


SoftwareSerial SaberSerial = SoftwareSerial( SABER_RX_PIN,
SABER_TX_PIN );

void initSabertooth( void )
{
// Init software UART to communicate
// with the Sabertooth 2x5
pinMode( SABER_TX_PIN, OUTPUT );

SaberSerial.begin( SABER_BAUDRATE );

// 2 second time delay for the Sabertooth to init
delay( 2000 );

// Send full stop command
setEngineSpeed( SABER_ALL_STOP );
}

/************************************************** ***
* setEngineSpeed
*
* Inputs - cSpeed_Motor1 - Input a percentage of full
* speed, from -100 to +100
*
************************************************** ***/
void setEngineSpeed( signed char cNewMotorSpeed )
{
unsigned char cSpeedVal_Motor1 = 0;

unsigned char cSpeedVal_Motor2 = 0;

// Check for full stop command
if( cNewMotorSpeed == 0 )
{
// Send full stop command for both motors
SaberSerial.print( 0, BYTE );

return;
}

// Calculate the speed value for motor 1
if( cNewMotorSpeed >= 100 )
{
cSpeedVal_Motor1 = SABER_MOTOR1_FULL_FORWARD;

cSpeedVal_Motor2 = SABER_MOTOR2_FULL_FORWARD;
}
else if( cNewMotorSpeed <= -100 )
{
cSpeedVal_Motor1 = SABER_MOTOR1_FULL_REVERSE;

cSpeedVal_Motor2 = SABER_MOTOR2_FULL_REVERSE;
}
else
{
// Calc motor 1 speed (Final value ranges from 1 to 127)
cSpeedVal_Motor1 = map( cNewMotorSpeed,
-100,
100,
SABER_MOTOR1_FULL_REVERSE,
SABER_MOTOR1_FULL_FORWARD );

// Calc motor 2 speed (Final value ranges from 128 to 255)
cSpeedVal_Motor2 = map( cNewMotorSpeed,
-100,
100,
SABER_MOTOR2_FULL_REVERSE,
SABER_MOTOR2_FULL_FORWARD );
}

// Fire the values off to the Sabertooth motor controller
SaberSerial.print( cSpeedVal_Motor1, BYTE );

SaberSerial.print( cSpeedVal_Motor2, BYTE );
}
Calling the routines:


void setup( )
{
initSabertooth( );
}

void loop ( )
{
// Full stop
setEngineSpeed( 0 );

// Half reverse
setEngineSpeed( -50 );

// Full reverse
setEngineSpeed( -100 );

// Half forward
setEngineSpeed( 50 );

// Full forward
setEngineSpeed( 100 );
}
Enjoy!

Noog

Hello Noog,

Thanks for the code! Some clarifications though:

I will just copy paste this at the arduino IDE sketch right? ( the code) and place the calling routines below..?

I can control the motor by using the setEngineSpeed ( -50 to 100..)? Maybe I can incorporate it with key press...

Your reply would be greatly appreciated :)
tank

Noog
09-30-2010, 10:15 AM
Hello Noog,

Thanks for the code! Some clarifications though:

I will just copy paste this at the arduino IDE sketch right? ( the code) and place the calling routines below..?

I can control the motor by using the setEngineSpeed ( -50 to 100..)? Maybe I can incorporate it with key press...

Your reply would be greatly appreciated :)
tank

Yes, include the Sabertooth subroutines into your sketch and you should be ready to go. You can have them in the same file as the main loop, or you can keep them in a separate file (linked to the same sketch) just for clarity.

The Setup() and Loop() routines I posted were just an example on how to call the Sabertooth routines. You don't need to include these since you probably already have your own.

Noog

tank
09-30-2010, 10:49 PM
Thanks Noog. I'll keep you posted :)

Tank

tank
10-03-2010, 01:44 AM
Hi Noog,

Upon studying your code, I need some clarifications:

Why is there a need to map the values of the motor speed?

Why not just fire values in between the 1 and 127 for motor 1 and 128 and 255 for motor 2?

My application is tank style steering / skid steering" or "differential steering

Hope for your response,
Tank

Noog
10-04-2010, 01:09 PM
Why is there a need to map the values of the motor speed?

Why not just fire values in between the 1 and 127 for motor 1 and 128 and 255 for motor 2?


My intentions were to make the command values being sent to the motor controller intuitive to the programmer (myself in this case). You may remove the mapping if it makes more sense to you.




My application is tank style steering / skid steering" or "differential steering


You will want to change my code so that both motors are not being given the same command then. For instance, make separate setLeftEngineSpeed() and setRightEngineSpeed() routines, or like you mentioned earlier, make a single routine that will receive values between 1 and 127 for motor 1 and 128 and 255 for motor 2.

Feel free to tune my example code to your specific needs. :happy:

Noog

tank
10-04-2010, 05:54 PM
Appreciated it Noog! :)

tank
10-13-2010, 09:12 PM
Hi Noog,

I patterned your code with mine, but it didn't compile.. Please help
I tried this using my arduino only.. No connections from the sabertooth do I have to connect it?


It says:
sketch_oct14a.cpp: In function 'void setEngineSpeedDir(signed char)':
sketch_oct14a:173: error: a function-definition is not allowed here before '{' token
sketch_oct14a:178: error: a function-definition is not allowed here before '{' token
sketch_oct14a:186: error: a function-definition is not allowed here before '{' token
sketch_oct14a:205: error: expected `}' at end of input

My code: I added keypress and added some functions to make it tank style steering

#include <SoftwareSerial.h>

// Labels for use with the Sabertooth 2x5 motor controller

// Digital pin 13 is the serial transmit pin to the
// Sabertooth 2x5
#define SABER_TX_PIN 13

// NOT USED (but still init'd)
// Digital pin 12 is the serial receive pin from the
// Sabertooth 2x5
#define SABER_RX_PIN 12

// Set to 9600 through Sabertooth dip switches
#define SABER_BAUDRATE 9600

// Simplified serial Limits for each motor
#define SABER_MOTOR1_FULL_FORWARD 127
#define SABER_MOTOR1_FULL_REVERSE 1
#define SABER_MOTOR1_FULL_STOP 64


#define SABER_MOTOR2_FULL_FORWARD 255
#define SABER_MOTOR2_FULL_REVERSE 128
#define SABER_MOTOR2_FULL_STOP 192


// Motor level to send when issuing the full stop command
#define SABER_ALL_STOP 0


SoftwareSerial SaberSerial = SoftwareSerial( SABER_RX_PIN,
SABER_TX_PIN );

void initSabertooth( void )
{
// Init software UART to communicate
// with the Sabertooth 2x5
pinMode( SABER_TX_PIN, OUTPUT );

SaberSerial.begin( SABER_BAUDRATE );

// 2 second time delay for the Sabertooth to init
delay( 2000 );
// Send full stop command
setEngineSpeed( SABER_ALL_STOP );
}

/************************************************** ***
* setEngineSpeed
*
* Inputs - cSpeed_Motor1 - Input a percentage of full
* speed, from -100 to +100
*
************************************************** ***/
void setEngineSpeed( signed char cNewMotorSpeed )
{
unsigned char cSpeedVal_Motor1 = 0;

unsigned char cSpeedVal_Motor2 = 0;

// Check for full stop command
if( cNewMotorSpeed == 0 )
{
// Send full stop command for both motors
SaberSerial.print( 0, BYTE );

return;
}

// Calculate the speed value for motor 1
if( cNewMotorSpeed >= 100 )
{
cSpeedVal_Motor1 = SABER_MOTOR1_FULL_FORWARD;

cSpeedVal_Motor2 = SABER_MOTOR2_FULL_FORWARD;
}
else if( cNewMotorSpeed <= -100 )
{
cSpeedVal_Motor1 = SABER_MOTOR1_FULL_REVERSE;

cSpeedVal_Motor2 = SABER_MOTOR2_FULL_REVERSE;
}
else
{
// Calc motor 1 speed (Final value ranges from 1 to 127)
cSpeedVal_Motor1 = map( cNewMotorSpeed,
-100,
100,
SABER_MOTOR1_FULL_REVERSE,
SABER_MOTOR1_FULL_FORWARD );

// Calc motor 2 speed (Final value ranges from 128 to 255)
cSpeedVal_Motor2 = map( cNewMotorSpeed,
-100,
100,
SABER_MOTOR2_FULL_REVERSE,
SABER_MOTOR2_FULL_FORWARD );
}

// Fire the values off to the Sabertooth motor controller
SaberSerial.print( cSpeedVal_Motor1, BYTE );

SaberSerial.print( cSpeedVal_Motor2, BYTE );
}

void move( )
{
initSabertooth( );
}

void control ( )
{
// Full stop
setEngineSpeed( 0 );

// Half reverse
setEngineSpeed( -50 );

// Full reverse
setEngineSpeed( -100 );

// Half forward
setEngineSpeed( 50 );

// Full forward
setEngineSpeed( 100 );
}

void setEngineSpeedDir( signed char cNewMotorSpeedDir )
{
unsigned char cSpeedValDir_Motor1 = 0;

unsigned char cSpeedValDir_Motor2 = 0;

if( cNewMotorSpeedDir >= 100 )
{
cSpeedValDir_Motor1 = SABER_MOTOR1_FULL_FORWARD; // GO RIGHT

cSpeedValDir_Motor2 = SABER_MOTOR2_FULL_STOP;
}

else if( cNewMotorSpeedDir <= -100 )
{
cSpeedValDir_Motor1 = SABER_MOTOR1_FULL_STOP; // GO LEFT

cSpeedValDir_Motor2 = SABER_MOTOR2_FULL_FORWARD;
}


else
{
// Calc motor 1 speed (Final value ranges from 64 to 127)
cSpeedValDir_Motor1 = map( cNewMotorSpeedDir,
-100,
100,
SABER_MOTOR1_FULL_STOP,
SABER_MOTOR1_FULL_FORWARD );

// Calc motor 2 speed (Final value ranges from 192 to 255)
cSpeedValDir_Motor2 = map( cNewMotorSpeedDir,
-100,
100,
SABER_MOTOR2_FULL_FORWARD,
SABER_MOTOR2_FULL_STOP);
}

// Fire the values off to the Sabertooth motor controller
SaberSerial.print( cSpeedValDir_Motor1, BYTE );

SaberSerial.print( cSpeedValDir_Motor2, BYTE );

void moveit( )//
{
initSabertooth( );
}

void turn ( )
{
// Turn left
setEngineSpeedDir( -100 );

// Turn right
setEngineSpeedDir( 100 );

}
void key() {

If(Serial.available()>0) {

Int data = Serial.read();
digitalWrite(buttonPin,LOW);
switch(data)
{
case'w':traverse = 100;break; //full forward
case's':traverse = -50;break; // half reverse
case'q':traverse = 0;break; // Stop
case'a':negotiate = -100;break; // left
case'd':negotiate = 100;break; // right
}
setEngineSpeed( traverse );
setEngineSpeedDir( negotiate );
}


{


Hope for your support..

Noog
10-16-2010, 03:50 PM
Hi Noog,

I patterned your code with mine, but it didn't compile.. Please help
I tried this using my arduino only.. No connections from the sabertooth do I have to connect it?

It says:
sketch_oct14a.cpp: In function 'void setEngineSpeedDir(signed char)':
sketch_oct14a:173: error: a function-definition is not allowed here before '{' token
sketch_oct14a:178: error: a function-definition is not allowed here before '{' token
sketch_oct14a:186: error: a function-definition is not allowed here before '{' token
sketch_oct14a:205: error: expected `}' at end of input

My code: I added keypress and added some functions to make it tank style steering

Hope for your support..

Hi Tank,

If your program doesn't compile, then the problem is not in your hardware, it is still in your code. You should not need to connect any hardware for a sketch compilation to succeed.

Problem 1: Each sketch requires two functions to always exist. They are called setup() and loop(). Your sketch had neither.

Please go a read up on the basics of the language. Start here (http://www.ladyada.net/learn/arduino/lesson2.html), then here (http://www.arduino.cc/playground/Code/VariableScope) and then maybe here (http://cslibrary.stanford.edu/101/EssentialC.pdf) if you still need more help.

Problem 2: Please review your control logic. I got the sketch working, but only because I made some assumptions about what you were trying to perform.

This code should at least give you a starting program that compiles. Hack away at this...


#include <SoftwareSerial.h>

// Labels for use with the Sabertooth 2x5 motor controller

// Digital pin 13 is the serial transmit pin to the
// Sabertooth 2x5
#define SABER_TX_PIN 13

// NOT USED (but still init'd)
// Digital pin 12 is the serial receive pin from the
// Sabertooth 2x5
#define SABER_RX_PIN 12

// Set to 9600 through Sabertooth dip switches
#define SABER_BAUDRATE 9600

// Simplified serial Limits for each motor
#define SABER_MOTOR1_FULL_FORWARD 127
#define SABER_MOTOR1_FULL_REVERSE 1
#define SABER_MOTOR1_FULL_STOP 64


#define SABER_MOTOR2_FULL_FORWARD 255
#define SABER_MOTOR2_FULL_REVERSE 128
#define SABER_MOTOR2_FULL_STOP 192


// Motor level to send when issuing the full stop command
#define SABER_ALL_STOP 0


SoftwareSerial SaberSerial = SoftwareSerial( SABER_RX_PIN, SABER_TX_PIN );

void initSabertooth( void )
{
// Init software UART to communicate
// with the Sabertooth 2x5
pinMode( SABER_TX_PIN, OUTPUT );

SaberSerial.begin( SABER_BAUDRATE );

// 2 second time delay for the Sabertooth to init
delay( 2000 );
// Send full stop command
setEngineSpeed( SABER_ALL_STOP );
}

/************************************************** ***
* setEngineSpeed
*
* Inputs - cSpeed_Motor1 - Input a percentage of full
* speed, from -100 to +100
*
************************************************** ***/
void setEngineSpeed( signed char cNewMotorSpeed )
{
unsigned char cSpeedVal_Motor1 = 0;

unsigned char cSpeedVal_Motor2 = 0;

// Check for full stop command
if( cNewMotorSpeed == 0 )
{
// Send full stop command for both motors
SaberSerial.print( 0, BYTE );

return;
}

// Calculate the speed value for motor 1
if( cNewMotorSpeed >= 100 )
{
cSpeedVal_Motor1 = SABER_MOTOR1_FULL_FORWARD;

cSpeedVal_Motor2 = SABER_MOTOR2_FULL_FORWARD;
}
else if( cNewMotorSpeed <= -100 )
{
cSpeedVal_Motor1 = SABER_MOTOR1_FULL_REVERSE;

cSpeedVal_Motor2 = SABER_MOTOR2_FULL_REVERSE;
}
else
{
// Calc motor 1 speed (Final value ranges from 1 to 127)
cSpeedVal_Motor1 = map( cNewMotorSpeed,
-100,
100,
SABER_MOTOR1_FULL_REVERSE,
SABER_MOTOR1_FULL_FORWARD );

// Calc motor 2 speed (Final value ranges from 128 to 255)
cSpeedVal_Motor2 = map( cNewMotorSpeed,
-100,
100,
SABER_MOTOR2_FULL_REVERSE,
SABER_MOTOR2_FULL_FORWARD );
}

// Fire the values off to the Sabertooth motor controller
SaberSerial.print( cSpeedVal_Motor1, BYTE );
SaberSerial.print( cSpeedVal_Motor2, BYTE );
}

void setup( )
{
initSabertooth( );
}

void control( )
{
// Full stop
setEngineSpeed( 0 );

// Half reverse
setEngineSpeed( -50 );

// Full reverse
setEngineSpeed( -100 );

// Half forward
setEngineSpeed( 50 );

// Full forward
setEngineSpeed( 100 );
}

void setEngineSpeedDir( signed char cNewMotorSpeedDir )
{
unsigned char cSpeedValDir_Motor1 = 0;

unsigned char cSpeedValDir_Motor2 = 0;

if( cNewMotorSpeedDir >= 100 )
{
cSpeedValDir_Motor1 = SABER_MOTOR1_FULL_FORWARD; // GO RIGHT

cSpeedValDir_Motor2 = SABER_MOTOR2_FULL_STOP;
}
else if( cNewMotorSpeedDir <= -100 )
{
cSpeedValDir_Motor1 = SABER_MOTOR1_FULL_STOP; // GO LEFT

cSpeedValDir_Motor2 = SABER_MOTOR2_FULL_FORWARD;
}
else
{
// Calc motor 1 speed (Final value ranges from 64 to 127)
cSpeedValDir_Motor1 = map( cNewMotorSpeedDir,
-100,
100,
SABER_MOTOR1_FULL_STOP,
SABER_MOTOR1_FULL_FORWARD );

// Calc motor 2 speed (Final value ranges from 192 to 255)
cSpeedValDir_Motor2 = map( cNewMotorSpeedDir,
-100,
100,
SABER_MOTOR2_FULL_FORWARD,
SABER_MOTOR2_FULL_STOP);
}

// Fire the values off to the Sabertooth motor controller
SaberSerial.print( cSpeedValDir_Motor1, BYTE );

SaberSerial.print( cSpeedValDir_Motor2, BYTE );
}

void turn ( )
{
// Turn left
setEngineSpeedDir( -100 );

// Turn right
setEngineSpeedDir( 100 );
}

void loop()
{
signed char traverse;
signed char negotiate;

if(Serial.available()>0)
{
int data = Serial.read();

// digitalWrite(buttonPin,LOW);

switch(data)
{
case'w':traverse = 100;break; //full forward
case's':traverse = -50;break; // half reverse
case'q':traverse = 0;break; // Stop
case'a':negotiate = -100;break; // left
case'd':negotiate = 100;break; // right
}

setEngineSpeed( traverse );
setEngineSpeedDir( negotiate );
}
}


Noog

tank
10-17-2010, 01:21 AM
Hi Noog Thanks for the correction :)

I already have my sabertooth 2x25 and I setup all the wirings, but when I powered them all up; the motors won't run upon pressing my W,S,D,A in the keyboard... The status 1 led in the sabertooth is turned on brightly.

I'm sure I wired the battery and the motors to the sabertooth correctly and for the arduino to the sabertooth: I connected s1 ( sabertooth) to digital pin 13 ( arduino) that serves as the TX line and 0V ( sabertooth) to the GND pin of the arduino..

My DIP switches are the same as you have suggested, I also double checked in the data sheet and it is the same, I'm using 2 pcs 12 volt 18ah Lead Acid batteries.

Any clues?

Regards

tank
10-17-2010, 02:09 AM
Hi Noog,

Finally I got it working!!! ,but I didn't use the keypress code.

Do you have any idea how to incorporate it with keypress?

My working code: ( edited Part)

void loop()
{
setEngineSpeedDir( -100 );
delay( 5000 );
setEngineSpeed( 0 );




// signed char traverse;
// signed char negotiate;
//
// if(Serial.available()>0)
// {
// int data = Serial.read();
//
//// digitalWrite(buttonPin,LOW);
//
// switch(data)
// {
// case'w':traverse = 100;break; //full forward
// case's':traverse = -50;break; // half reverse
// case'q':traverse = 0;break; // Stop
// case'a':negotiate = -100;break; // left
// case'd':negotiate = 100;break; // right
// }
//
// setEngineSpeed( traverse );
// setEngineSpeedDir( negotiate );
// }
}

Regards,

tank
10-19-2010, 09:46 AM
I really need to send the controls by keyboard press, but it won't work work with my arduino..
Someone help

Noog
10-24-2010, 04:17 PM
I really need to send the controls by keyboard press, but it won't work work with my arduino..
Someone help

Your first problem is that you are calling both setEngineSpeed() and setEngineSpeedDir() every time you process a key press command. These two routines are essentially doing the same thing, so you only need to use one of them. Try making this change to your code and see if you can get it running with the key presses.

Noog

tank
10-24-2010, 08:10 PM
Noog,

What kind of editing would it be? from the tutorials, the keypress should work, but it won't respond. Any ideas?

Regards

lnxfergy
10-24-2010, 10:09 PM
It would appear your setup() function is missing a call to "Serial.begin(baud);" to start your serial port at a particular baud rate -- without that, you'll never have serial data arriving to be processed.

-Fergs

tank
10-24-2010, 10:34 PM
Inxfergy,

This is what is placed in my setup function:

void setup( )
{
initSabertooth( );
}


So I will add Serial.begin(9600); inside the setup function? 9600 is my baudrate. I'll try it and hopefully my keypress would work.

Thanks

tank
10-24-2010, 11:52 PM
Inxfergy,

Thanks for the tip! my keypress controls worked! but I'm not sure why my q key ( To stop) won't respond?

My arduino keypress code below:

void loop()
{

// setEngineSpeed( 100 );
// delay( 5000 );
// setEngineSpeed( 50 );
// delay( 5000 );



//setEngineSpeedDir( -100 );
//delay( 5000 );
//setEngineSpeed( 0 );
//delay( 5000 );




signed char traverse;
signed char negotiate;

if(Serial.available()>0)
{
int data = Serial.read();

// digitalWrite(buttonPin,LOW);
switch(data)
{
case'w':traverse = 100;break; //full forward
case's':traverse = -50;break; // half reverse
case'q':traverse = 0;break; // Stop, THIS COMMAND WON'T RESPOND
case'a':negotiate = -100;break; // left
case'd':negotiate = 100;break; // right
}

setEngineSpeed( traverse );
setEngineSpeedDir( negotiate );
}
}

Hope for your support
Thanks