SSC03A - Arduino

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 :slight_smile:

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 :frowning:

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. :confused:

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);
  
   
}

I think you should try reversing the order of the following two lines because you’re probably mistakenly driving the TX pin low briefly after running pinMode.

pinMode(servoControllerTxPin, OUTPUT);
digitalWrite(servoControllerTxPin, HIGH);

Also, you should try taking those lines out completely. I haven’t used SoftwareSerial or NewSoftSerial, but they probably take care of setting up the TX pin for you.

–David Grayson

Hello.

I haven’t looked at your code very carefully, but it looks like you are naming Rx and Tx in a confusing way. The line you’re calling servoControllerTxPin is actually connected to the servo controller Rx pin, right? (If not, that could be part of your problem.) Have you looked at the details of what you are doing with your transmit line in setup()? Why are you making the pin an output before making it go high? If rearranging that doesn’t help, can’t you just put the reset line toggle in your code after your serial line setup?

- Jan

Renamed, switched round and tried removing. all resulting in the exact same issue.

However. Put in a reset command after all that and before the main loop starts and YES it all works.

Thanks guys didnt think of reseting the controller before using it. :unamused:

p.s. I used to have this hooked to the arduino reset so they reset together. But something in the set-up is seting the line off and causing a problem so using a different reset pin and triggering it myself works better.

e.g. hooked the reset line to pin 11 and

  pinMode(11, OUTPUT);
  digitalWrite(11, LOW);
  delay(50);
  digitalWrite(11, HIGH);

Thanks for the extra set of eyes guys…