I am having a little trouble getting a reliable software serial link to the servo controler.
I am using and Arduino Duemilanove with v.0018 of the development environment and have put some test code together, attached below.
As you can see I have put pin 3 as software serial and the standard pin would be used for the hardware serial. Im repeating the commands on both lines
What happens is:
If I reset the board with the pin connected to the HARDWARE serial pin, everything works great. No problems at all, the servo moves as directed
When I connect to the pin3 (softwareserial) and reset All I get is a RED light, followed by the green one flashing. But no servo movement at all
HOWEVER, If I connect the signal pin to nothing and reset then after a seccond or so connect it to pin3 then it works fine. Servo moves under software serial control.
My problem is something in the initialisation is fouling up the connection, but I dont know what to do about it!
Note: I have tried SOFTWARESERIAL and NEWSOFTSERIAL, they both behave in the same way
#include <NewSoftSerial.h>
#define PBAUDRATE 38400 // set to the baudrate used.
#define servoControllerRxPin 12 // digital pin
#define servoControllerTxPin 3 // digital pin
NewSoftSerial PSerial = NewSoftSerial(servoControllerRxPin, servoControllerTxPin);
void setup()// run once, when the sketch starts
{
pinMode(servoControllerTxPin, OUTPUT);
digitalWrite(servoControllerTxPin, HIGH); // supposed to keep pololu board from getting spurious signal!
Serial.begin(PBAUDRATE);// set up Serial library at defined rate
PSerial.begin(PBAUDRATE); // init the software serial to same
delay(100); // small delay
}
void put(unsigned char servo, unsigned int angle){
//servo is the servo number (typically 0-7)
//angle is the absolute position from 500 to 5500
//mySerial.print(someChar);
//Send a Pololu Protocol command
PSerial.print(0x80,BYTE); //start byte
PSerial.print(0x01,BYTE); //device id
PSerial.print(0x04,BYTE); //command number
PSerial.print(servo,BYTE); //servo number
//Convert the angle data into two 7-bit bytes
PSerial.print(((angle>>7)&0x3f),BYTE); //data1
PSerial.print((angle&0x7f),BYTE); //data2
// repeat the command over hardware serial
Serial.print(0x80,BYTE); //start byte
Serial.print(0x01,BYTE); //device id
Serial.print(0x04,BYTE); //command number
Serial.print(servo,BYTE); //servo number
//Convert the angle data into two 7-bit bytes
Serial.print(((angle>>7)&0x3f),BYTE); //data1
Serial.print((angle&0x7f),BYTE); //data2
}
void loop()// run over and over again
{
// delay before next reading:
// move servo between two values
delay(1000);
put(0,1550);
delay(1000);
put(0,2000);
}