Hi, i´m trying to implement a system do control several servos using 2 modules, the Tx is sending each ppm channel convert to characters to control the respective servo on the Rx board, so i found mem´s code ( http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1247570790 ) about serial packet and i made some changes for using 2 channels of my arduino shield (joystick) and the other side 2 servos on the other arduino board (328).
here is the code for the RX board:
#include <Servo.h>
#define NBR_SERVOS 2 // the number of servos, up to 48 for Mega, 12 for other boards
Servo myServos[NBR_SERVOS] ; // max servos is 48 for mega, 12 for other boards
const int servPins[NBR_SERVOS] = {2,3};
void setup()
{
Serial.begin(9600);
for(int i=0; i < NBR_SERVOS; i++)
myServos_.attach(servPins*); _
_}_
void loop()
_{_
_ static int pos = 0;_
_ if ( Serial.available())_
_ {_
_ char ch = Serial.read();_
_ if(ch >= '0' && ch <= '9') // is ch a number? *_
_ pos = pos * 10 + ch - '0'; // yes, accumulate the value_
* else if(ch >= 'a' && ch <= 'a'+ NBR_SERVOS) // is ch a letter for one of our servos?
_ {_
_ myServos[ch - 'a'].write(pos); // yes, save the position in the position array _
_ pos = 0;*_
* }*
* }*
}[/color]
[/td][/tr][/table]
and the code for the Tx board:
#include <Servo.h>
int potpin0 = 0; // analog pin 0 used to connect the potentiometer A
int val0; // variable to read the value from the analog pin 0
int potpin1 = 1; // analog pin 1 used to connect the potentiometer B
int val1; // variable to read the value from the analog pin 1
void setup()
{
* Serial.begin(9600);*
}
void loop()
{
* val0 = analogRead(potpin0); // reads the value of the potentiometer (value between 0 and 1023)*
* val0 = map(val0, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)*
* val1 = analogRead(potpin1); // reads the value of the potentiometer (value between 0 and 1023)*
* val1 = map(val1, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)*
* Serial.print(val0,DEC), Serial.print("a "); *
* Serial.println("");*
* Serial.print(val1,DEC), Serial.print("b "); *
* Serial.println("");*
* delay(15); // waits for the servo to get there*
}
i tried to connect the Tx pin on the sender side to the Rx pin on the receiver side and wait for the servos to move but nothing happens.
when i send the command over the pc keyboard i can get the servos to move, any considerations on this problem that i have now ? :o
thanks in advance