Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Arduino and Sabertooth 2x5 ?

  1. #1
    Join Date
    Sep 2007
    Location
    La Paz, Bolivia
    Posts
    25
    Rep Power
    43

    Arduino and Sabertooth 2x5 ?

    Friends:

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

    Thanks in advance,

    Migs
    "The medicine for my suffering I had within me from the very beginning" Bruce Lee - Jeet Kune Do
    "One single grateful thought raised to heaven is the most perfect prayer. " G. E. Lessing
    "Time has a wonderful way of showing us what really matters." - Margaret Peters
    "We all have the extraordinary coded within us, waiting to be released."-Jean Houston

  2. #2
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    181

    Re: Arduino and Sabertooth 2x5 ?

    At it's simplest - just use PWM and treat it exactly like two servos.

    http://www.arduino.cc/playground/ComponentLib/Servo
    I Void Warranties´┐Ż

  3. #3
    Join Date
    Sep 2007
    Location
    La Paz, Bolivia
    Posts
    25
    Rep Power
    43

    Re: Arduino and Sabertooth 2x5 ?

    Thanks Adrenalyn! This was just what I was looking for. -Migs
    "The medicine for my suffering I had within me from the very beginning" Bruce Lee - Jeet Kune Do
    "One single grateful thought raised to heaven is the most perfect prayer. " G. E. Lessing
    "Time has a wonderful way of showing us what really matters." - Margaret Peters
    "We all have the extraordinary coded within us, waiting to be released."-Jean Houston

  4. #4
    Join Date
    Nov 2009
    Location
    Canada
    Posts
    45
    Images
    25
    Rep Power
    41

    Re: Arduino and Sabertooth 2x5 ?

    Quote Originally Posted by Migs View Post
    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/data...zard/start.htm

    Sabertooth routines:
    (NOTE: setEngineSpeed will control both motors at the same time.)
    Code:
    #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:
    Code:
    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

  5. #5
    Join Date
    May 2008
    Location
    TN
    Posts
    853
    Images
    99
    Rep Power
    77

    Re: Arduino and Sabertooth 2x5 ?

    I don't have a sabertooth but you code may be helpful to people in the futre. Thanks for posting it!
    "If A is a success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut."
    -
    Einstein

    Don't be a HelpVampire

  6. #6
    charlieo Guest

    Re: Arduino and Sabertooth 2x5 ?

    Noog,

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

    Thanks,
    Charlie O

  7. #7
    Join Date
    Nov 2009
    Location
    Canada
    Posts
    45
    Images
    25
    Rep Power
    41

    Re: Arduino and Sabertooth 2x5 ?

    Quote Originally Posted by charlieo View Post
    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

  8. Re: Arduino and Sabertooth 2x5 ?

    Quote Originally Posted by Noog View Post
    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/data...zard/start.htm

    Sabertooth routines:
    (NOTE: setEngineSpeed will control both motors at the same time.)
    Code:
    #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:
    Code:
    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

  9. #9
    Join Date
    Nov 2009
    Location
    Canada
    Posts
    45
    Images
    25
    Rep Power
    41

    Re: Arduino and Sabertooth 2x5 ?

    Quote Originally Posted by tank View Post
    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

  10. Wink Re: Arduino and Sabertooth 2x5 ?

    Thanks Noog. I'll keep you posted

    Tank

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Anyone got Sabertooth packetized mode to work?
    By shobley in forum Arbotix, Microcontrollers, Arduino
    Replies: 9
    Last Post: 01-25-2009, 08:28 PM
  2. Replies: 6
    Last Post: 01-07-2009, 08:10 AM
  3. Sabertooth 2x5 R/C issue
    By wireframewolf in forum Arbotix, Microcontrollers, Arduino
    Replies: 6
    Last Post: 10-13-2008, 04:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •