Hi,
If on a Duemilanove I use either the standard UART or SoftwareSerial, I can successfully command the servo.
However, if I use the NewSoftSerial library, the LED's on the Pololu serial controller indicate the baud rate is too high.
I have tried it even with baud 2400, with no success.
Any comments or suggestions would be appreciated.
Using this code:
#include "NewSoftSerial.h"
#define rxPin 8
#define txPin 9
unsigned int pos = 0;
NewSoftSerial swserial(rxPin, txPin);
void setup()
{
Serial.begin(9600);
pinMode(rxPin, INPUT);
// Keep Pololu board from getting spurious signal
digitalWrite(txPin, HIGH);
pinMode(txPin, OUTPUT);
swserial.begin(9600);
}
void put(int servo, unsigned int angle)
{
unsigned char buff[6];
unsigned int temp;
unsigned char pos_hi;
unsigned char pos_low;
temp = angle & 0x1f80;
pos_hi = temp >> 7;
pos_low = angle & 0x7f;
buff[0] = 0x80; // start byte
buff[1] = 0x01; // device id
buff[2] = 0x04; // command number
buff[3] = servo; // servo number
buff[4] = pos_hi; // data1
buff[5] = pos_low; // data2
for (int i = 0; i < 6; i++){
swserial.print(buff[i], BYTE);
}
}
// Pololu pos = standard servo usec * 2, 3000 is pos 0
void loop()
{
for (pos = 2530; pos <= 3475; pos += 1 )
{
put(0, pos);
delay(10);
}
for (pos = 3475; pos > 2530; pos -= 1)
{
put(0, pos);
delay(10);
}
}