Serial servo controller with Arduino
Hello,
I'm using parallax servo controller(serial) with arduino. And I found a code sample from arduino forum.
This code works well for single servo motor.
If I wrote for·multiple servos like below, it·does not work.
Actually they got some movement, but they never moved at the same time.
· SetServoPos(0,180,7);
· SetServoPos(1,180,7);
· delay(3000);
· SetServoPos(0,0,7);
· SetServoPos(1, 0,7);
· delay(3000);
I tried other ways to make them move together, nothing worked!!!
I have no idea what I should do. I think there's the root cause in the code.
Here's what I'm using now, I just copied from the forum.
What's wrong???????
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <SoftwareSerial.h>
#define rxPin 0
#define txPin 7
void SetServoPos(byte chan, int pos, byte ramp);
SoftwareSerial mySerial =· SoftwareSerial(rxPin, txPin);
byte BR = 1;·
void setup(){
··
· // define pin modes for tx, rx:
· pinMode(rxPin, INPUT);
· pinMode(txPin, OUTPUT);
··
· // set the data rate for the SoftwareSerial port
· // The PSC starts at 2400
· mySerial.begin(2400);
· digitalWrite(13, HIGH);
· // set PSC baud rate to 38400
· // makes the PSC go as fast as possible
· mySerial.print("!SCSBR");
· mySerial.print(BR, BYTE);·
· mySerial.print(13, BYTE);·
··
· mySerial.begin(38400);
·
}
void loop() {
· // SetServoPos Example:
· // SetServoPos(Channel, Angle, RampRate)·
· SetServoPos(0,180,7);
· delay(3000);
· SetServoPos(0,0,7);
· delay(3000);
··
}·
void SetServoPos(byte chan, int pos, byte ramp){
··
· // Converts angel into PWM data
· int realpos = int(pos*(1000.0/180.0)+250.0);
··
· byte lsb =· realpos & 0xFF;·····
· byte msb =· realpos >> 8;
· mySerial.print("!SC");
· mySerial.print(chan, BYTE);·
· mySerial.print(ramp, BYTE);
· mySerial.print(lsb, BYTE);·
· mySerial.print(msb, BYTE);
· mySerial.print(13, BYTE);·
}
·
I'm using parallax servo controller(serial) with arduino. And I found a code sample from arduino forum.
This code works well for single servo motor.
If I wrote for·multiple servos like below, it·does not work.
Actually they got some movement, but they never moved at the same time.
· SetServoPos(0,180,7);
· SetServoPos(1,180,7);
· delay(3000);
· SetServoPos(0,0,7);
· SetServoPos(1, 0,7);
· delay(3000);
I tried other ways to make them move together, nothing worked!!!
I have no idea what I should do. I think there's the root cause in the code.
Here's what I'm using now, I just copied from the forum.
What's wrong???????
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <SoftwareSerial.h>
#define rxPin 0
#define txPin 7
void SetServoPos(byte chan, int pos, byte ramp);
SoftwareSerial mySerial =· SoftwareSerial(rxPin, txPin);
byte BR = 1;·
void setup(){
··
· // define pin modes for tx, rx:
· pinMode(rxPin, INPUT);
· pinMode(txPin, OUTPUT);
··
· // set the data rate for the SoftwareSerial port
· // The PSC starts at 2400
· mySerial.begin(2400);
· digitalWrite(13, HIGH);
· // set PSC baud rate to 38400
· // makes the PSC go as fast as possible
· mySerial.print("!SCSBR");
· mySerial.print(BR, BYTE);·
· mySerial.print(13, BYTE);·
··
· mySerial.begin(38400);
·
}
void loop() {
· // SetServoPos Example:
· // SetServoPos(Channel, Angle, RampRate)·
· SetServoPos(0,180,7);
· delay(3000);
· SetServoPos(0,0,7);
· delay(3000);
··
}·
void SetServoPos(byte chan, int pos, byte ramp){
··
· // Converts angel into PWM data
· int realpos = int(pos*(1000.0/180.0)+250.0);
··
· byte lsb =· realpos & 0xFF;·····
· byte msb =· realpos >> 8;
· mySerial.print("!SC");
· mySerial.print(chan, BYTE);·
· mySerial.print(ramp, BYTE);
· mySerial.print(lsb, BYTE);·
· mySerial.print(msb, BYTE);
· mySerial.print(13, BYTE);·
}
·
Comments
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1201077061
Since the Parallax servos are pretty standard, and your question is about software, that'd be the better place to go, I think.