Go Down

Topic: Self balance board help (Read 1 time) previous topic - next topic


Hi guys,
I am using a arduino demiwhatsisname board and a 2x 25w sabertooth motor controller is the aim to make a unit the uses a acceleraometer to keep itself level.
Having some problems and i was hoping for some fresh ideas.

Last week i turned it on the for first time and something was wired up incorrectly i think, which caused the motor controller to catch fire.

Now i have new controller, have connected it just to the arduino and have been given some code to test the motors. The code storts the motors, goes to 10% power, 20%, 30% up to 50% then back down again ect. This is proven code and definatly works.
WHen i do it with my board however the moters are all over the place, they just around between all the speeds and sometimes just into reverse, its very odd.
VBoth motors do this and there appears to be no pattern. They always run withing the defined speeds, and for the right amount of time but just not at the right speed.

The motor controller is powered by two 12v 7amph batteries in parallel.
All signal wires have been moved far away from the power wires ect and i have tried changing pins on the arduino but doesnt seem to help.

Any ideas??
Could i have damaged the arduino when the motor controller went bang?


Wow, seems to like your motors are running like part of your text!!!

Anyway, somebody is about to ask this soon, so why don't I do it...

Code and wiring, please!

The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"


Haha sorry about the text, i was trying to type fast as i had run out of lunch break at work.

I will post wiring and code up when i get home in an hour or so.



Right, very basic wiring for now as i just want to get the motors working.

Digital pin 13 to S1 on the motor controller 
Ground pin to 0V on motor controller

Two 12v 7amph batteries connected in parallel to the + and - of the motor controller.
And the two motors are connected.

I have taken it apart and layed it out, it seems interference was causing some of the more strange problems. The motors dont just all over the place any more.
Motor 2 runs through fine although will suddenly jump into reverse randomly.
Motor 1 either doesnt start, or starts at 10% and will stay there untill 40% and will suddenly jump up. It will then do the same as it goes back down again.

Here is the code

//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>
//must have SoftwareSerial in your arduino library !

//******************** 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


//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

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;

//int deadmanbuttonPin = 9;  // deadman button is digital input pin 9

void setup()                    // run once, when the sketch starts
  initSabertooth( );

  //digital inputs
// pinMode(deadmanbuttonPin, INPUT);

    Serial.begin(9600);      // HARD wired Serial feedback to PC for debugging in Wiring


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 ");

if (Motor1percent > 100) Motor1percent = 100;
if (Motor1percent < -100) Motor1percent = -100;
if (Motor2percent > 100) Motor2percent = 100;
if (Motor2percent < -100) Motor2percent = -100;

cSpeedVal_Motor1 = map (Motor1percent,
cSpeedVal_Motor2 = map (Motor2percent,
SaberSerial.print (cSpeedVal_Motor1, BYTE);
SaberSerial.print (cSpeedVal_Motor2, BYTE);

  Serial.print("Motor1percent = ");
  Serial.print ("  level = ");
  Serial.println (level);
  Serial.print("Motor2percent = ");
  Serial.print("cSpeedVal_Motor1 = ");
  Serial.print("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
  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

Any help would be very much appreciated

Go Up