SlideShare a Scribd company logo
//TWIN WHEELER MODIFIED FOR ARDUINO SIMPLIFIED SERIAL PROTOCOL TO
SABERTOOTH V2
//**********THIS VERSION JUST TESTS COMMUNICATION BETWEEN ARDUINO AND
SABERTOOTH AND MOTORS PLUS DEADMAN SWITCH****************
//*********** DEADMAN SWITCH MUST BE PRESSED IN, MOTORS WILL STOP IF
RELEASED **********************
//MOTORS WILL INCREASE IN SPEED BY 10% EVERY 5 SECONDS UNTIL 50% OF FULL
POWER IS REACHED
//THEY WILL THEN GO DOWN TO ZERO IN STEPS OF 10%.
//BOTH WHEELS SHOULD BE SPINNING IN SAME DIRECTION AT THE SAME SPEED AT ALL
TIMES ELSE YOU WILL HAVE WIRED ONE MOTOR UP BACK TO FRONT
//SABERTOOTH MUST HAVE DIP SWITCHES SET TO THE SERIAL MODE:i.e. DIP
switches 1, 3, 5 and 6 set to ON, the remainder set to OFF
//IMU NOT CONNECTED AT THIS POINT (CAN BE PHYSICALLY CONNECTED IF YOU LIKE
BUT ARDUINO WILL NOT BE READING IT AT ALL)
//ONLY THING YOU NEED IS DEAD MAN SWITCH TO DIGITAL PIN 9 (+5V TO PIN 9
WHEN SWITCH PRESSED, PULL DOWN RESISTOR FROM PIN 9 TO GND KEEPS IT AT 0V
OTHERWISE)
//J. Dingley March 1 2011 For Arduino 328 Duemalinove or similar with a
3.3V accessory power output
//i.e. the current standard Arduino board.
#include <SoftwareSerial.h>
//******************** IMPORTANT ***************************
//Set dip switches on the Sabertooth for simplified serial and 9600
Buadrate. Diagram of this on my Instructables page//
//i.e. DIP switches 1, 3, 5 and 6 set to ON, the remainder set to OFF
//******************** IMPORTANT ***************************
//Digital pin 13 is serial transmit pin to sabertooth
#define SABER_TX_PIN 13
//Not used but still initialised, Digital pin 12 is serial receive from
Sabertooth
#define SABER_RX_PIN 12
//set baudrate to match sabertooth dip settings
#define SABER_BAUDRATE 9600
//simplifierd 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 full stop command
#define SABER_ALL_STOP 0
SoftwareSerial SaberSerial = SoftwareSerial (SABER_RX_PIN, SABER_TX_PIN );
void initSabertooth (void) {
//initialise software to communicate with sabertooth
pinMode ( SABER_TX_PIN, OUTPUT );
SaberSerial.begin( SABER_BAUDRATE );
//2 sec delay to let it settle
delay (2000);
SaberSerial.print(0, BYTE); //kill motors when first switched on
}
float level = 0;
int u;
//float k1;
//int k2;
//int k3;
int k4;
signed char Motor1percent;
signed char Motor2percent;
//DIGITAL INPUT
int deadmanbuttonPin = 9; // deadman button is digital input pin 9
void setup() // run once, when the sketch starts
{
initSabertooth( );
//analogINPUTS
//digital inputs
pinMode(deadmanbuttonPin, INPUT);
Serial.begin(9600); // HARD wired Serial feedback to PC for
debugging in Wiring
}
void sample_inputs() {
k4 = digitalRead(deadmanbuttonPin); //this is needed - if you let go the
motors both stop for your own safety
}
void set_motor() {
unsigned char cSpeedVal_Motor1 = 0;
unsigned char cSpeedVal_Motor2 = 0;
//set motors using the simplified serial Sabertooth protocol (same for
smaller 2 x 5 Watt Sabertooth by the way)
Motor1percent = (signed char) level;
Motor2percent = (signed char) level;
Serial.print("level ");
Serial.println(level);
if (Motor1percent > 100) Motor1percent = 100;
if (Motor1percent < -100) Motor1percent = -100;
if (Motor2percent > 100) Motor2percent = 100;
if (Motor2percent < -100) Motor2percent = -100;
//if not pressing deadman button on hand controller - cut everything
if (k4 < 1) {
level = 0;
Motor1percent = 0;
Motor2percent = 0;
Serial.println("Pressing Dead Man Button");
delay(1000);
}
cSpeedVal_Motor1 = map (Motor1percent,
-100,
100,
SABER_MOTOR1_FULL_REVERSE,
SABER_MOTOR1_FULL_FORWARD);
cSpeedVal_Motor2 = map (Motor2percent,
-100,
100,
SABER_MOTOR2_FULL_REVERSE,
SABER_MOTOR2_FULL_FORWARD);
SaberSerial.print (cSpeedVal_Motor1, BYTE);
SaberSerial.print (cSpeedVal_Motor2, BYTE);
/*
//debugging
Serial.print("Motor1percent = ");
Serial.print(Motor1percent);
Serial.print (" level = ");
Serial.println (level);
Serial.print("Motor2percent = ");
Serial.println(Motor2percent);
Serial.print("cSpeedVal_Motor1 = ");
Serial.println(cSpeedVal_Motor1);
Serial.print("cSpeedVal_Motor2 = ");
Serial.println(cSpeedVal_Motor2);
*/
delay(5000); //5 second delay
}
void loop () {
for (u=0; u<5; u++) {
level= u * 10; //level = 0 then 10, then 20 until it gets to 50% of max
motor power. each set motor routine has 5 sec delay at end of it
sample_inputs(); //check the dead man button still pressed in
set_motor();
}
for (u=0; u<5; u++) {
level= (5- u) * 10; //level = 50 then 40, then 30 then 20 until it gets
to 0% of max motor power. each set motor routine has 5 sec delay at end of
it
sample_inputs();//check the dead man button still pressed in
set_motor();
}
}

More Related Content

DOC
Acn Experiment No 3
DOC
Acn Experiment No 6
DOC
Acn Experiment No 5
DOC
Acn Experiment No 4
DOC
Resumen vlan configuracion basica
PDF
Config VLAN Dell
PDF
CCIE R&S Real Lab Workbbok 2018 updated
PDF
Acn Experiment No 3
Acn Experiment No 6
Acn Experiment No 5
Acn Experiment No 4
Resumen vlan configuracion basica
Config VLAN Dell
CCIE R&S Real Lab Workbbok 2018 updated

What's hot (14)

DOC
Cisco 2960 basic configuration – vlan configuration
DOCX
How to create and delete vlan on cisco catalyst switch
DOC
Configuring the cisco switch with the cli based setup program
PPTX
How to obtain ip address from a different network dhcp
PDF
Ssr 303 user manual
PDF
PDF
Trik singkat STATIC ROUTING via cli Packet Tracer
PPTX
Mac address-table static
PDF
PBR-LB - Direct Server Return Load Balancing using Policy Based Routing (MEMO)
DOCX
Basic Switch Configurations
DOCX
How to configure port security in cisco switch
PDF
53340 0420 gs5_gs501_rca-30k
PDF
Catalog mikro mikro mk233a-user-dienhathe.vn
Cisco 2960 basic configuration – vlan configuration
How to create and delete vlan on cisco catalyst switch
Configuring the cisco switch with the cli based setup program
How to obtain ip address from a different network dhcp
Ssr 303 user manual
Trik singkat STATIC ROUTING via cli Packet Tracer
Mac address-table static
PBR-LB - Direct Server Return Load Balancing using Policy Based Routing (MEMO)
Basic Switch Configurations
How to configure port security in cisco switch
53340 0420 gs5_gs501_rca-30k
Catalog mikro mikro mk233a-user-dienhathe.vn
Ad

Similar to Twin wheeler modified for arduino simplified serial protocol to sabertooth v2 (20)

DOCX
Twin wheeler modified for arduino simplified serial protocol to sabertooth v22
DOCX
Twin wheeler modified for arduino simplified serial protocol to sabertooth v21
PDF
GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf
PDF
Arduino Lecture 3 - Interactive Media CS4062 Semester 2 2009
PDF
Arduino Lecture 3 - Interactive Media CS4062 Semester 2 2009
PDF
Controller-programming-manual---20221125(1).pdf
PDF
Fadal Spindle Drive and Motor Manual
PDF
MaxBotix Code Examples
PDF
GSM GPRS SIM900A Modem
DOCX
Program, Code of Program and Screen Shot of Output (UNIVERSAL DRIVER USING µ...
PPT
AVR_GENERAL KOSTI.ppt
PDF
Afd Control
PPTX
drive related all details available for learning and practical for working in...
DOCX
How to configure cisco 6500 vss
PDF
Musical Machines and Flapping Phones
PDF
Applied motion products si5580 datasheet
PDF
BLD-AC1000S.pdf
PDF
GSM GPRS sim900 a modem with stub antenna and sma connector-USB
DOCX
Lampiran 1.programdocx
PDF
PowerMate15 Technical Specification
Twin wheeler modified for arduino simplified serial protocol to sabertooth v22
Twin wheeler modified for arduino simplified serial protocol to sabertooth v21
GENESIS BOARD MINI SUMO ROBOT PROGRAMFOR 3 OPPONENT SENSOR, .pdf
Arduino Lecture 3 - Interactive Media CS4062 Semester 2 2009
Arduino Lecture 3 - Interactive Media CS4062 Semester 2 2009
Controller-programming-manual---20221125(1).pdf
Fadal Spindle Drive and Motor Manual
MaxBotix Code Examples
GSM GPRS SIM900A Modem
Program, Code of Program and Screen Shot of Output (UNIVERSAL DRIVER USING µ...
AVR_GENERAL KOSTI.ppt
Afd Control
drive related all details available for learning and practical for working in...
How to configure cisco 6500 vss
Musical Machines and Flapping Phones
Applied motion products si5580 datasheet
BLD-AC1000S.pdf
GSM GPRS sim900 a modem with stub antenna and sma connector-USB
Lampiran 1.programdocx
PowerMate15 Technical Specification
Ad

More from josnihmurni2907 (19)

DOCX
Simple timer code for arduino
DOCX
Michael kontopoulos
DOCX
Michael kontopoulo1s
DOCX
How to write timings and delays
DOCX
Define ba1
DOCX
Define ba
DOCX
Call and message using arduino and gsm module
DOCX
DOCX
Arduino 101
PDF
140813560 nota-kimia-tingkatan-4
DOC
1.funtions (1)
PDF
132944997 rancangan-tahunan-mm-t5-2013
DOCX
Agihan kertas 1 dan kertas 2
DOCX
Ciri pemimpin
DOCX
Cara menghilangkan rasa ngantuk di kelas
DOCX
Bercakap mengenai nikmat allah s
DOCX
Bandar purba dalam tasik di china
DOCX
12 kaum yang telah allah swt binasakan
PPTX
Smkts 2015 p1
Simple timer code for arduino
Michael kontopoulos
Michael kontopoulo1s
How to write timings and delays
Define ba1
Define ba
Call and message using arduino and gsm module
Arduino 101
140813560 nota-kimia-tingkatan-4
1.funtions (1)
132944997 rancangan-tahunan-mm-t5-2013
Agihan kertas 1 dan kertas 2
Ciri pemimpin
Cara menghilangkan rasa ngantuk di kelas
Bercakap mengenai nikmat allah s
Bandar purba dalam tasik di china
12 kaum yang telah allah swt binasakan
Smkts 2015 p1

Recently uploaded (20)

PDF
Classroom Observation Tools for Teachers
PPTX
master seminar digital applications in india
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
RMMM.pdf make it easy to upload and study
PDF
Computing-Curriculum for Schools in Ghana
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Institutional Correction lecture only . . .
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Presentation on HIE in infants and its manifestations
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
Classroom Observation Tools for Teachers
master seminar digital applications in india
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Microbial disease of the cardiovascular and lymphatic systems
VCE English Exam - Section C Student Revision Booklet
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Module 4: Burden of Disease Tutorial Slides S2 2025
Chinmaya Tiranga quiz Grand Finale.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
GDM (1) (1).pptx small presentation for students
Supply Chain Operations Speaking Notes -ICLT Program
RMMM.pdf make it easy to upload and study
Computing-Curriculum for Schools in Ghana
human mycosis Human fungal infections are called human mycosis..pptx
Institutional Correction lecture only . . .
Final Presentation General Medicine 03-08-2024.pptx
Presentation on HIE in infants and its manifestations
102 student loan defaulters named and shamed – Is someone you know on the list?

Twin wheeler modified for arduino simplified serial protocol to sabertooth v2

  • 1. //TWIN WHEELER MODIFIED FOR ARDUINO SIMPLIFIED SERIAL PROTOCOL TO SABERTOOTH V2 //**********THIS VERSION JUST TESTS COMMUNICATION BETWEEN ARDUINO AND SABERTOOTH AND MOTORS PLUS DEADMAN SWITCH**************** //*********** DEADMAN SWITCH MUST BE PRESSED IN, MOTORS WILL STOP IF RELEASED ********************** //MOTORS WILL INCREASE IN SPEED BY 10% EVERY 5 SECONDS UNTIL 50% OF FULL POWER IS REACHED //THEY WILL THEN GO DOWN TO ZERO IN STEPS OF 10%. //BOTH WHEELS SHOULD BE SPINNING IN SAME DIRECTION AT THE SAME SPEED AT ALL TIMES ELSE YOU WILL HAVE WIRED ONE MOTOR UP BACK TO FRONT //SABERTOOTH MUST HAVE DIP SWITCHES SET TO THE SERIAL MODE:i.e. DIP switches 1, 3, 5 and 6 set to ON, the remainder set to OFF //IMU NOT CONNECTED AT THIS POINT (CAN BE PHYSICALLY CONNECTED IF YOU LIKE BUT ARDUINO WILL NOT BE READING IT AT ALL) //ONLY THING YOU NEED IS DEAD MAN SWITCH TO DIGITAL PIN 9 (+5V TO PIN 9 WHEN SWITCH PRESSED, PULL DOWN RESISTOR FROM PIN 9 TO GND KEEPS IT AT 0V OTHERWISE) //J. Dingley March 1 2011 For Arduino 328 Duemalinove or similar with a 3.3V accessory power output //i.e. the current standard Arduino board. #include <SoftwareSerial.h> //******************** IMPORTANT *************************** //Set dip switches on the Sabertooth for simplified serial and 9600 Buadrate. Diagram of this on my Instructables page// //i.e. DIP switches 1, 3, 5 and 6 set to ON, the remainder set to OFF //******************** IMPORTANT *************************** //Digital pin 13 is serial transmit pin to sabertooth #define SABER_TX_PIN 13 //Not used but still initialised, Digital pin 12 is serial receive from Sabertooth #define SABER_RX_PIN 12 //set baudrate to match sabertooth dip settings #define SABER_BAUDRATE 9600 //simplifierd 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 full stop command
  • 2. #define SABER_ALL_STOP 0 SoftwareSerial SaberSerial = SoftwareSerial (SABER_RX_PIN, SABER_TX_PIN ); void initSabertooth (void) { //initialise software to communicate with sabertooth pinMode ( SABER_TX_PIN, OUTPUT ); SaberSerial.begin( SABER_BAUDRATE ); //2 sec delay to let it settle delay (2000); SaberSerial.print(0, BYTE); //kill motors when first switched on } float level = 0; int u; //float k1; //int k2; //int k3; int k4; signed char Motor1percent; signed char Motor2percent; //DIGITAL INPUT int deadmanbuttonPin = 9; // deadman button is digital input pin 9 void setup() // run once, when the sketch starts { initSabertooth( ); //analogINPUTS //digital inputs pinMode(deadmanbuttonPin, INPUT); Serial.begin(9600); // HARD wired Serial feedback to PC for debugging in Wiring }
  • 3. void sample_inputs() { k4 = digitalRead(deadmanbuttonPin); //this is needed - if you let go the motors both stop for your own safety } void set_motor() { unsigned char cSpeedVal_Motor1 = 0; unsigned char cSpeedVal_Motor2 = 0; //set motors using the simplified serial Sabertooth protocol (same for smaller 2 x 5 Watt Sabertooth by the way) Motor1percent = (signed char) level; Motor2percent = (signed char) level; Serial.print("level "); Serial.println(level); if (Motor1percent > 100) Motor1percent = 100; if (Motor1percent < -100) Motor1percent = -100; if (Motor2percent > 100) Motor2percent = 100; if (Motor2percent < -100) Motor2percent = -100; //if not pressing deadman button on hand controller - cut everything if (k4 < 1) { level = 0; Motor1percent = 0; Motor2percent = 0; Serial.println("Pressing Dead Man Button"); delay(1000); } cSpeedVal_Motor1 = map (Motor1percent, -100, 100, SABER_MOTOR1_FULL_REVERSE, SABER_MOTOR1_FULL_FORWARD); cSpeedVal_Motor2 = map (Motor2percent, -100, 100,
  • 4. SABER_MOTOR2_FULL_REVERSE, SABER_MOTOR2_FULL_FORWARD); SaberSerial.print (cSpeedVal_Motor1, BYTE); SaberSerial.print (cSpeedVal_Motor2, BYTE); /* //debugging Serial.print("Motor1percent = "); Serial.print(Motor1percent); Serial.print (" level = "); Serial.println (level); Serial.print("Motor2percent = "); Serial.println(Motor2percent); Serial.print("cSpeedVal_Motor1 = "); Serial.println(cSpeedVal_Motor1); Serial.print("cSpeedVal_Motor2 = "); Serial.println(cSpeedVal_Motor2); */ delay(5000); //5 second delay } void loop () { for (u=0; u<5; u++) { level= u * 10; //level = 0 then 10, then 20 until it gets to 50% of max motor power. each set motor routine has 5 sec delay at end of it sample_inputs(); //check the dead man button still pressed in set_motor(); } for (u=0; u<5; u++) { level= (5- u) * 10; //level = 50 then 40, then 30 then 20 until it gets to 0% of max motor power. each set motor routine has 5 sec delay at end of it sample_inputs();//check the dead man button still pressed in set_motor(); }
  • 5. }