PDA

View Full Version : [Question(s)] Arduino and SC16A Problem



ROBOTMAN
02-07-2010, 07:27 PM
I am using the arduino to communicate with the SC16A with the SoftwareSerial library. I google looking for code but I only got two results. I used the users manual I found here (http://www.cytron.com.my/usr_attachment/SC16A%20User%20Manual.pdf) to create some code.


#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);


void setup()
{
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
mySerial.begin(9600);
Serial.begin(9600);
}

void loop()
{
mySerial.print(byte(65));
mySerial.print(byte(50));
mySerial.print(byte(50));
mySerial.print(byte(20));
}

This seemed like a good start but it dose not work. I am still researching the different types of data so I am not really sure how to simply ask the servo to turn to center. I know what order to send the information and what information to send. The part I am most fuzzy on is how to send both the start bit 0b01 and the servo number. If someone could point me in the direction of a decimal to binary converter or show me how to properly send the data it would be appreciated.

Noog
02-08-2010, 04:41 PM
Disclaimer: I have not used the SC16A personally, just poked through the user manual a little bit.

Make sure the switch on your board is set to single board mode and that you have your servo connected to the first channel. Try this code out:



void loop()
{
mySerial.print( 65, BYTE );
mySerial.print( 25, BYTE );
mySerial.print( 0, BYTE );
mySerial.print( 0, BYTE );
}

Your numbers looked close, but I change the position so that it was within the range specified by the user manual. I also set the speed value to zero, but that was just to be safe (default servo speed). You can change that speed value back after you got the code working.

Noog

Adrenalynn
02-08-2010, 04:47 PM
I lost interest when I saw we were using software serial on a hardware UART...

ROBOTMAN
02-08-2010, 06:01 PM
Is there another way I should be doing this? From what I gathered UART was serial. I'll google but will the code noog mentioned work.

Noog
02-08-2010, 06:01 PM
Yeah, you should remove the serial.begin(9600) line from your setup routine (or change the pins you are using).

Noog

ROBOTMAN
02-08-2010, 06:10 PM
I have removed that but the code still dose nothing... Not really sure how to proceed. Any recommendations on a way to communicate with the SC16A?

Adrenalynn
02-08-2010, 06:18 PM
I'm not even sure why it links...

void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}

void loop() {}

Get rid of all references to software serial - you're using a hardware serial port.

ROBOTMAN
02-08-2010, 06:21 PM
Oh I see what you are saying. I didn't want to do this because I wanted to send data back to the computer for processing. You are saying connect RX to pin 0 and TX to pin 1 correct? Now I would just use the typical Serial.print() command correct?

Adrenalynn
02-08-2010, 06:34 PM
The UART is bidirectional. I was thinking the hardware serial was on 2/3, but I guess it's on 0/1. One of these clone boards is on 2/3... [shrug]

You can run software serial or hardware serial. Don't have that other begin in there until you address it.

When you run it from a level shifter into the PC serial port and watch it with a terminal, what does it display?

Noog
02-08-2010, 09:17 PM
Hmm, I could use a little more information.

1) What arduino board are you using?

2) With the SC16A connected to your arduino, what LEDs are on?

3) Have you tried running your SC16A from a computer through the USB port with the servo you are now trying to control?

Noog

ROBOTMAN
02-09-2010, 07:39 PM
I am using an arduino diecimila. The servo controller dose work with usb connection. When I power up the arduino the 5v and servo lights light up. I need to send the start bit in order to initialize communication. The first command should be a combination of start bit and servo number I am not sure how to do this.

Noog
02-09-2010, 10:15 PM
I need to send the start bit in order to initialize communication. The first command should be a combination of start bit and servo number I am not sure how to do this.

The SC16A software protocol says that the initial byte of their command packet needs to have the most significant bit set to a zero and the following bit set to a one. The last 6 bits are used for the servo number. Essentially, the first byte in the command packet will be 64 (the start bit) + servo_number.

I hope my explanation makes sense, just ask if you want me to clarify/expand on any part of it.

Noog

ROBOTMAN
02-14-2010, 02:57 PM
So this code should be working then?


void setup()
{
Serial.begin(9600);
}

void loop()
{
Serial.print( 65, BYTE );
Serial.print( 25, BYTE );
Serial.print( 0, BYTE );
Serial.print( 0, BYTE );
}

I dose not appear to have any affect. The serial light only lights up when I connect to it with the serial monitor and it doesn't move the servo.

ROBOTMAN
02-17-2010, 06:25 PM
Still nothing working no matter how I switch the code. I know the board is receiving the serial data my arduino sends and I know that the controller works so I am stuck. The numbers I am printing to the SC16A from the arduino are converted to A's and strange symbols on any serial monitor.

lnxfergy
02-17-2010, 06:51 PM
65 = ASCII "A"

-Fergs

ROBOTMAN
02-17-2010, 06:54 PM
Ya thats what I figured... It would appear the correct data is being sent and received.

Noog
02-18-2010, 08:39 AM
I'll start with a dumb suggestion: have you tried reversing the tx and rx lines? I tend to wires these up backwards, even on the good days. =)

Hmm, my next suggestion would be to get the SC16A to send data back to your microcontroller.

I don't see any version or identity request commands in the user manual. It does support a position reporting command. Check the end of the SC16A user guide for the details on how this command works. If you don't have an LCD to display the values, you may want to setup your microcontroller to have a debug uart to your PC again.

If you can get some sane values back from the servo controller this will confirm that the serial communication is working properly.

Noog

ROBOTMAN
02-19-2010, 06:40 PM
Nothing happens with this code used to read data back from the sc16a and print it to serial port.

#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3
byte data = 0;
byte data1 = 0;
byte data2 = 0;

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

void setup()
{
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
mySerial.begin(9600);
Serial.begin(9600);
}

void loop()
{
mySerial.print( 65, BYTE );
mySerial.print( 65, BYTE );
delay(100);
data = mySerial.read();
data1 = mySerial.read();
data2 = mySerial.read();
Serial.println(data + data1 + data2);
}

I think I know what the problem is I am just not sure how to express or fix it. I don't think that the sc16a is "picking up" the serial line. I think for some reason my arduino doesn't send until my sc16a is ready to receive. What led me to believe this was when I was experimenting with using the arduino hardware serial ports. Every time I tried the program the tx light would remain dark. When I attached a usb cable to my sc16a the arduino started transmitting and the serial monitor for the sc16a showed the proper information was being sent by the arduino and patched through the sc16a to its serial monitor on the computer. "Note that the servo still refused to move". This same thing happens with the software serial library. I hope all that I said makes sense. Oh and by the way I make sure I flip the wires during every test because I have been known to make many mistakes.

lu_01
03-19-2011, 08:50 PM
Hi all,

I am currently having the same problem. anybody ouit there know how to fix this?