PDA

View Full Version : Pink to propeller communication Via Xbee [SOLVED]



Dgswaner
05-07-2008, 11:47 AM
I've tried for Hours over many days to get the syntax right but I just can't make this work. here is my line of communication PINK> Propeller>Xbee-----Xbee<Propeller

I need to read a string from the pink, and get it to the end propeller, the communication works the only problem is that I can only send one letter at a time. I've stripped down my code and I still can't get this to work. It appears that no matter what I do I can't get more than one character from the PINK.

My ultimate goal is to read a value from the pink (255 for example) and Xmit it to my bot, right now all my that my bot is getting is a 2. I know I need to convert the string value of "255" to a decimal value, which I can do but I'm not receiving the whole "255" to begin with. I know there has to be something that I am missing. I would really appreciate some help before I pull the rest of my hair out.

Thanks, DGS

The code below is partial code each run on a different propeller.



pub GETX ' PINK Code
repeat
myPink.readVar(myPink#Nb_var25,@XVAL) 'gets Pink Value
comm.tx(Xval) ' send Xval to PC
XB.str(Xval) 'send Xval via Xbee
waitcnt (10_000_000+cnt) 'wait 1/10 sec







'Bot Code
Repeat
y := XB.RX ' recieve data from Xbee
comm.tx(y) ' send to PC
Waitcnt (10_000_000+cnt)






I've tried many many variations of this! and still can't get it to work.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

DGSwaner

Post Edited (Dgswaner) : 5/9/2008 5:17:42 AM GMT

Peter Verkaik
05-07-2008, 12:32 PM
Dgswaner,

pub·GETX·····'·PINK·Code
···repeat
·····myPink.readVar(myPink#Nb_var25,@XVAL)······'g ets·Pink·Value
·····comm.str(@Xval)······························ ······'·send·buffer Xval·to·PC
·····XB.str(@Xval)································ ········'send·buffer Xval·via·Xbee
·····waitcnt·(10_000_000+cnt)····················' wait·1/10·sec

'Bot·Code
Repeat
······y·:=·XB.RX···'·recieve·data·from·Xbee
······comm.tx(y)··'·send·to·PC
······Waitcnt·(10_000_000+cnt)

You must pass the buffer address to both comm.str (I think comm.tx just sends one byte)
and to XB.str

regards peter

Dgswaner
05-07-2008, 06:54 PM
Thanks I knew it had to be something simple, I'll give it a try when I get home from work.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

DGSwaner

Dgswaner
05-08-2008, 09:15 AM
Thanks Peter that's all it was, not sending the whole buffer was the problem.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

DGSwaner

Post Edited (Dgswaner) : 5/8/2008 2:27:44 AM GMT

Dgswaner
05-08-2008, 07:16 PM
I spoke too quick, I'm receiving the whole value but but now I can't get it in the correct format. I can recieve a value from the pink (123) I can sent it to the PC fine, and send it to the other Propeller fine, but only as a string. If I use the format object to convert it from a string it does it one character at a time. 1, 2, 3 and not 123. if I don't convert it to value I get the whole number 123 but it's not usable for me because it's a string. This is really driving em crazy this seems like it should be really straight forward. I'd try a different approach but I can't think of any other solution.





pub GETX
repeat
myPink.readVar(myPink#Nb_var25,@XVAL) 'gets Pink Value
format.itoa(@Xval,@X)
COMM.str(@XVal)
XB.tx(X)
waitcnt (10_000_000+cnt) 'wait .75 sec







PUB GETCAMX
X := XB.RX
CamX := format.atoi(@X) 'convert signed decimal string to integer value
comm.dec(Camx)




I've tried what I think should work and tried ever combination of sending and converting and I can't get it to work. this is to control a home brew PTZ camera base 0-255 is going to be the position of a slider on the Pink interface, and needs to get converted to a value on the bot side. Is there an easier way to do this?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

DGSwaner

Post Edited (Dgswaner) : 5/8/2008 12:26:18 PM GMT

Peter Verkaik
05-08-2008, 08:04 PM
You need the format function atoi (ascii to integer) instead of itoa (integer to ascii).
atoi converts the decimal string into a binary value.

regards peter

Dgswaner
05-08-2008, 10:43 PM
I think I switched that in my frustrations, I was using the itoa function and that's where I ran into it giving 1,2,3 instead of one whole number 123. I think I tried every combination possible, reading the value from the pink sending it as a string then converting it. converting it to a decimal then sending it, etc. I was able to receive the whole number and all of the digits but it was either in a string value "123" and if I used Atoi to convert it to an integer I get individual digits.

can I get clarification of my thought process on how I think this should work? perhaps there is something I'm missing.
if NBVAR25 = 123 (this is a string value)

myPink.readVar(myPink#Nb_var25,@XVAL) 'gets the value and stores it in @Xval still in string format
XB.str(@Xval) 'would send the entire string "123"
X := XB.TX would recieve the "123" as a string, there is not option for receiving a value that isn't stored as a value, so there shouldn't be any need to convert the string to a value on the sending propeller.
format.Atoi(@Xval,@X) converts "123" to 123 (an actual number)
I can then use X to control the position of a servo.

Thanks for your help

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

DGSwaner

Peter Verkaik
05-08-2008, 11:05 PM
The function atoi takes a string and returns an integer.
So you would do
myPink.readVar(myPink#Nb_var25,@XVAL) 'gets the value and stores it in @Xval still in string format
value := format.atoi(@XVAL) 'value now holds binary value of decimal string in XVAL
XB.tx(value)· 'transmit byte value
On the receiver side you then get simple binary values.

regards peter

Dgswaner
05-08-2008, 11:17 PM
ok I think I seen how it need to work. thanks for your patients. I have learned a ton though.

Thanks.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

DGSwaner

Dgswaner
05-09-2008, 12:15 PM
Thanks again Peter! once again I was trying to make it more difficult than it needed to be. here is my working code.

Pink Code: This reads NBVAR20 from the pink converts it and then sends out via XBEE and to a PC.



pub GETX
repeat
myPink.readVar(myPink#Nb_var20,@XVAL) 'gets Pink Value
X :=format.AtoI(@Xval)
COMM.dec(X)
comm.tx(13)
XB.TX(X)




Bot Code: receives the value from the pink uses the 0-255 value to set the servo to 400-2200.



pub GETCAMX
repeat
X := XB.RX
comm.dec(X)
comm.tx(13)
SERVO.Set(14,(x*7) + 400)
Waitcnt (10_000_000+cnt)


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster

DGSwaner