Pages: 1 [2]   Go Down
Author Topic: Sabertooth Analog mode  (Read 1815 times)
0 Members and 1 Guest are viewing this topic.
Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well no. I can't either, but each to their own.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25760
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@OP
Your sketch is too long and rambling.
You've been asked to implement arrays and functions to simplify and shorten it.
You've been asked to add debug prints; you're the one with the hardware and you need some observations to figure out what it is doing.
You've been asked to remove useless code and useless comments; they just add to the noise.

And please, please, drop the txt and start using the shift key.
« Last Edit: May 09, 2012, 01:55:56 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

FL
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Its not that I can't explain it... Its just you wouldn't understand.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ironically I had the same problem,  because I have the sabertooth too. I figured mine out. First set all of the DIP switches to the OFF position, then arduino code time. Servo.write(120); is backwards (in my case), Servo.writeMicroseconds(1200); is forwards (in my case). Now you have independent control of each motor. This has nothing to do with how far it has gone, so in that case, you would have to get encoders or optical interrupters. I hope to be building an AI/pathfinding robot using this speed controller (2x12). You can adjust the speed accordingly. Oh and by the way I have a serial sample code for you where you can test out the different frequencies

Code:
// If you need any help feel free to PM me (simonfrfr) or email me
// at newtonlabs@bellsouth.net
String readString;
#include <Servo.h>
Servo myservo;  // create servo object to control a servo
Servo myservo2; // create second servo object
const int left = 10; // left motor's pin on arduino
const int right = 9; // right motor's pin on arduino
void setup() {
  Serial.begin(9600);
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string
    if (readString == "l") // acfivates left servo only
    {
      myservo.attach(left); // writing both to left motor
      myservo2.attach(left);
    }
        if (readString == "r") // activates right servo only
    {
      myservo.attach(right); // writing both to left motor
      myservo2.attach(right);
    }
        if (readString == "b") // activates both motors
    {
      myservo.attach(left); // writing to left motor
      myservo2.attach(right); // writing to right motor
    }
    int n = readString.toInt();  //convert readString into a number

    // auto select appropriate value, copied from someone elses code.
    if(n >= 500)
    {
      Serial.print("writing Microseconds: "); // serial display
      Serial.println(n); // number
      myservo.writeMicroseconds(n); // writes to ports
      myservo2.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: "); // serial display
      Serial.println(n); // number
      myservo.write(n); // writes to ports
      myservo2.write(n);
    }

    readString=""; //empty for next input
  }
}
Logged

FL
Offline Offline
Newbie
*
Karma: 0
Posts: 34
Its not that I can't explain it... Its just you wouldn't understand.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

PS: forgot to tell you, that is only for one.
Logged

Pages: 1 [2]   Go Up
Jump to: