wireless serial servo control
in Propeller 1
this is probably a simple oversight on my part but i am at a road block, I have two propeller boards both connected to transceivers rx p0 and tx p1, the end result is to send a number between 100 and 1800 from board 1 to board two and control a servo. i believe my problem is with board two with combining the incoming" 1,8,0,0" into "1800" so that servo_angle(11, servo); can use it. any suggestions? thanks.

Comments
Here's a simple method that waits on a number via ASCII characters from your serial input. Any non-digit character will cause it to end.
pub get_value | value, c value := 0 repeat c := serial.rx if ((c => "0") and (c =< "9")) value := (value * 10) + (c - "0") else return valueEdit: Whoops, my code is in Spin, the Propeller's native language (because you hadn't yet posted code or specified language when I originally responded). Still, any C programmer should be able to convert my simple method -- C is, after all, the superior language. Right?
transmit = fdserial_open(0, 1, 0, 9600);
dprint(transmit,"%d%c",servo1, 13);
dprint(transmit,"%c%c",servo1, 13);
dprint(transmit,"%c",servo1);
dprint(transmit,"%d%d%d%d%d%d%d%d", A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7]);
yes there are multiple servos.
servo1 = fdserial_rxChar(receive)
servo1 = fdserial_rxCheck(receive)
char servo1;
char servo1[4] = {0,0,0,0};
#include "simpletools.h" // Include simple tools
#include "fdserial.h"
fdserial *transmit;
int servo1;
int main() // Main function
{
//RX TX
transmit = fdserial_open(13, 14, 0, 9600);
servo1 = 1745;
while(1)
{
dprint(transmit,"%d",servo1);
pause(100);
print("--%d --%c \n",servo1,servo1);
}
}
#include "simpletools.h" // Include simple tools
#include "servo.h"
#include "fdserial.h"
fdserial *receive;
char servo1;
int main() // Main function
{
//RX TX
receive = fdserial_open(0, 1, 0, 9600); // p0-p1 trancever
while(1)
{
servo1 = fdserial_rxCheck(receive);
print("--%d --%c \n",servo1,servo1);
// servo_angle(11, servo1);
}
}
You have values between 100 and 1800, this fits well into 16bit (= 2 bytes). It even fits in a 14bit range (0..16383) , so you can send it as two 7bit "bytes". The spare bit in a byte can then be used as a Sync marker.
Here is a -not tested- possible code for your two Main routines:
// Transmit a 14bit value: int main() { int servo1; transmit = fdserial_open(13, 14, 0, 9600); servo1 = 1745; while(1) { fdserial_txChar(transmit, 0x80); //send a Sync-Byte fdserial_txChar(transmit, servo1 >> 7); //send Higher 7 bits fdserial_txChar(transmit, servo1 & 0x7F); //send Lower 7 bits pause(100); print("sent: %d \n",servo1); } } --------------------------------- // Receive the 14bit value: int main() { int serval; receive = fdserial_open(0, 1, 0, 9600); // p0-p1 trancever while(1) { while(fdserial_rxChar(receive) != 0x80) ; //wait for Sync Byte serval = fdserial_rxChar(receive) << 7; //get Higher 7 bits serval += fdserial_rxChar(receive) & 0x7F; //get and add Lower 7 bits print("got: %d \n",serval); // servo_angle(11, serval); } }Andy
(btw. use the capital C icon in the Forum-Editbox to post code)