I wrote this simple piece of code to see if the BotBoarduino would talk to the SSC-32. TX and GND of BotBoarduino connected to the RX and GND of the SSC-32. Nothing happens. Any thoughts?
The problem is you you need to output a real CR not the simple characters
Several ways to do this.
Use the Serial.println
function which will append a cr to the end of the output. Also some of your prints may not default properly. So something like:
void loop() {
Serial.print("#");
Serial.print(5, DEC);
Serial.print(" P");
Serial.print(1600, DEC);
Serial.print(" T");
Serial.println(1000, DEC);
}
Should work. Could also output the characters using special escape characters. Something like:
Serial.print("\n\r");
Says to output the line feed and carriage return characters.
I just use “Serial.print();” to send all the parameters to the SSC-32, and use a “Serial.println();” to properly terminate the command, so the SSC-32 executes it. It works great!
Here is one function I have:
// ********************************************** From Walter_Navigation.h
struct Servo {
byte pin;
int offset;
int msPulse;
int angle;
int minPulse;
int maxPulse;
int maxDegrees;
int error;
};
// ******************************* From Walter_Navigation.cpp
/*
Initialize servos
*/
Servo panServo = {
SERVO_PAN_PIN,
SERVO_PAN_ADJUST,
0,
0,
SERVO_PAN_LEFT_MAX,
SERVO_PAN_RIGHT_MAX,
SERVO_MAX_DEGREES,
0
};
Servo tiltServo = {
SERVO_TILT_PIN,
SERVO_TILT_ADJUST,
0,
0,
SERVO_TILT_DOWN_MAX,
SERVO_TILT_UP_MAX,
SERVO_MAX_DEGREES,
0
};
/*
Move a servo by pulse width in ms (500ms - 2500ms)
*/
Servo moveServoPw (Servo servo, int servoPosition, int moveSpeed, int moveTime, boolean term) {
Servo tServo = servo;
tServo.error = 0;
if ((servoPosition >= tServo.minPulse) && (servoPosition <= tServo.maxPulse)) {
Serial.print("#");
Serial.print(tServo.pin);
Serial.print(" P");
Serial.print(servoPosition + tServo.offset);
tServo.msPulse = servoPosition;
tServo.angle = ((servoPosition - SERVO_CENTER_MS) / 10);
if (tServo.maxDegrees == 180) {
tServo.angle += 90;
}
} else if ((servoPosition < tServo.minPulse) || (servoPosition > tServo.maxPulse)) {
tServo.error = 200;
}
// Add servo move speed - affects just this servo
if (tServo.error == 0) {
if (moveSpeed != 0) {
Serial.print(" S");
Serial.print(moveSpeed);
}
// Terminate the command
if (term) {
// Add the Time parameter - affects the entire move
if (moveTime != 0) {
Serial.print(" T");
Serial.print(moveTime);
}
// Send command to the SSC-32
Serial.println();
}
}
return tServo;
}
Note: The above code is not quite finished, and I haven’t tested it yet. I also have a companion moveServoDegrees() function. This is the basic form it will remain in though. I wanted to create a function that could fully utilize the features of the SSC-32. I will wrap a proper class around the Servo struct, and add these functions as methods. It makes sense to do it this way for best usability. So, you’ll create an instance of Servo for each servo you have, and then do something like servo.movePw() or servo.moveDegrees() to move the servo.
This is all going into an Arduino library after it’s been fully tested and works to my satisfaction. I am very picky about my code.