ok understood,
I have my arduino's TX (pin1) and RX(pin 0 ) connected to the cytron sc16a's servo controller's RX and TX pins repectively. I also have the Arduino's 5V and GND pins connected to the servo controller's %V and GND pins. the servo motor is connected to one of the ports of the servo controller. its power is obtained from an external 9v alkaline battery which is connected to the servo controller (as the sc16a provides a slot for this). that's basically my setup. here is the sample code I am currently trying to run:-
#define mainbodyLEFT_Button_9 10
#define mainbodyRIGHT_Button_10 11
int state1 = HIGH;
int position1 = 732;
void setup()
{
Serial.begin (9600); //Set USART Baud Rate to 9600
pinMode (mainbodyLEFT_Button_9, INPUT); //Set button pin to input
digitalWrite (mainbodyLEFT_Button_9, HIGH);/ENABLE INTERNAL PULL-UP RESISTORS ON THIS PIN/
pinMode (mainbodyRIGHT_Button_10, INPUT); //Set button pin to input
digitalWrite (mainbodyRIGHT_Button_10, HIGH);/ENABLE INTERNAL PULL-UP RESISTORS ON THIS PIN/
}
void loop()
{
delay(100); // debounces switches
int mainbodyLEFT_Button_9_value = digitalRead(mainbodyLEFT_Button_9);
int mainbodyRIGHT_Button_10_value = digitalRead(mainbodyRIGHT_Button_10);
if(mainbodyLEFT_Button_9_value != state1 ||mainbodyRIGHT_Button_10_value != state1||Stop_Button_13!= state1)
{
if (mainbodyLEFT_Button_9_value != state1)
{
if (position1 >1463) {
position1 =1463;
send_cmd(0X41, position1,0);
}
else{
position1+=100;
send_cmd(0X41, position1,0);
delay(10); //wait for message to transmit
}
}
else if (mainbodyRIGHT_Button_10_value != state1)
{
if (position1 <0) {
position1 =0;
send_cmd(0X41, position1,0);
}
else
position1--;
send_cmd(0X41, position1,0);
delay(10); //wait for message to transmit
}
}
}
void send_cmd(unsigned int num, unsigned int data, unsigned int ramp)
//UART transmit 4 bytes: servo number, higher byte position,
//lower byte position and speed
{
unsigned char higher_byte=0, lower_byte=0;
higher_byte=(data>>6)&0x003f;
lower_byte=data&0x003f;
Serial.print(num, HEX); //First byte is the servo channel 0x41-0x60
//delay(2000);
Serial.print(higher_byte,HEX); //second byte is the higher byte of position
//0b00xxxxxx
//delay(2000);
Serial.print(lower_byte, HEX); //third byte is the lower byte of position 0b00xxxxxx
//delay(2000);
Serial.println(ramp,HEX ); //fourth byte is the speed value from 0-63
//delay(2000);
}
thanx