Wireless

cooldude4u2no

New Member
I been racking my brain over wireless communication. I cant seem to find a good tutorial on it either. But im trying to figure out how to send commands from a PC to another device wirelessly. Like for example: "80". When the device receives this is will display 80 on the sceen and then store the variable. With my code however, it seems its only receiving the first character which is "8". Im using two Xbee Series 1 Modules operating at 9600 baud.

Here is what i have.

Receiver:
Code:
#NO_DATA
#NO_TABLE

Main:
Serin B.6, T9600_8, ($55, $55), B0 
let b8 = b0
serout B.0, t9600_8, ("?f") 'LCD Clear Screen
pause 100
serout B.0, t9600_8, (#B0) '
goto main
Transmitter Connected to PC:
Code:
#no_DATA
#NO_TABLE

main:
serin C.3, N9600_8, b0 'From PC using PicAxe Terminal
serout C.1, T9600_8, ($55,$55, b0) 'To Xbee
goto main
Please forgive if the code is sloppy. Im a complete newb to picaxe and just trying to learn it. Maybe complete wrong approach?
 

Chavaquiah

Senior Member
The receiving program reads one character and then takes some time to display it on the screen, before getting ready to accept the next transmission. The sender doesn't seem to wait at all between characters. Perhaps the second character is lost while the receiver is dealing with the display?

You should probably try first to send something like a fixed string and only later start passing commands from the computer. Easier to debug that way.

Also, if you know in advance how many characters a command will have, why have each byte sent separately? You could send two (or more) bytes at once...
 

russbow

Senior Member
Isn't he suggesting that, expecting say a value of 80, he actually receives 8.

Can't be missed bytes. He is only sending two qualifiers and the variable b0.
He is receiving two qualifiers and a value assigned to b0.

I once had a problem of missing the first byte of a series that was caused by my choice of qualifier matching the byte expected.

Changing qualifier values cured it.

But getting 8 instead of 80 ?????

Does it happen with all numbers? Send a 99 - get 9 ?
send 100 get 1 or 10 or 99 ?
 

cooldude4u2no

New Member
Isn't he suggesting that, expecting say a value of 80, he actually receives 8.

Can't be missed bytes. He is only sending two qualifiers and the variable b0.
He is receiving two qualifiers and a value assigned to b0.

I once had a problem of missing the first byte of a series that was caused by my choice of qualifier matching the byte expected.

Changing qualifier values cured it.

But getting 8 instead of 80 ?????

Does it happen with all numbers? Send a 99 - get 9 ?
send 100 get 1 or 10 or 99 ?
Thats the thing. I can send A string or anything. Like if i send cooldude4u2no.. it shows "C" or if i send 2010 it shows 2..
 

MartinM57

Moderator
..and if you send...
C <wait 0.5secs> O <wait 0.5secs> O <wait 0.5secs> L <wait 0.5secs> D <wait 0.5secs> U <wait 0.5secs> D <wait 0.5secs> E
..what happens?

Maybe, in your tests, the PC is sending all the characters to the transmitter so fast (and there is no buffer in the transmitter to store those characters) then by the time it gets to the second serin round the loop all the characters have been sent and lost?
 

ckoehn

Member
I think what you are doing is sending an "80". That is 2 characters. An "8" and a "0". You would need to send.

serout B.0, t9600_8, (B0)

Does that return an 80?
 

BeanieBots

Moderator
That's correct.
Try sending "C" then "o", then "o" .... and so on.

b0 can only ever hold one character, so you need to send each character one at a time.
Or, you could put more variables into the recieve serin and get a character for each.

eg
serin C.3, N9600_8, b0,b1,b2
to receive three characters at once (but you MUST send it three characters)
 

MartinM57

Moderator
I figured by the time "0" is on the air the receiver is talking to the display and waiting 100ms for it to clear. Not (yet) listening for the next characters.
I suspect the "0" never gets on the air - it's never picked up by the Transmitter from the PC...
 

cooldude4u2no

New Member
Hey guys got it to work! Thanks alot! I didnt realize that i was trying to store two or three charaters in one byte... stupid me. But heres my updated code in case some other newb like me needs it.

Receiver:
Code:
#NO_DATA
#NO_TABLE

Main:
Serin B.6, T9600_8, ($55, $55), B0, B1, B2
serout B.0, t9600_8, ("?f")
serout B.0, t9600_8, (B0, B1, B2)
goto main
Transmitter:
Code:
#no_DATA
#NO_TABLE
main:
serin C.3, N9600_8, b0, b1, b2
serout C.1, T9600_8, ($55,$55, b0, b1, b2)
goto main
This atleast gives me a good starting point now. One more question. If i sent over the command, lets say "D80". How could i store the 80. I know i could do a select case on B0 which would b "D" but how could i combine say b1 which is 8 and b2 which is 0 to make say b4 = 80?
 

russbow

Senior Member
Ah.. so you weren't trying to send 80 - one byte, but 8 then 0, two separate bytes. Confusion cleared.
 

Chavaquiah

Senior Member
I suspect the "0" never gets on the air - it's never picked up by the Transmitter from the PC...
Of course you're right. That could also be it. That's why in these cases it's better to divide the project into smaller steps and test and debug one at a time.


how could i combine say b1 which is 8 and b2 which is 0 to make say b4 = 80?
b4 = b1 - "0" * 10 + b2 - "0"

If the above looks weird, that's because Picaxe Basic knows no precedence for operators and evaluates all expressions strictly from left to right.

You're receiving ASCII characters, meaning that when you send "0" what arrives is a byte with value 48 ("1" = 49, and so on). Good thing with Picaxe you can use commas to work with ASCII codes so that "0" actually is the same as 48.

So, you take the first byte (tenths), subtract 48 from it to get the decimal value ("8" = 56 becomes 8), multiply it by 10 and add the decimal value from the second byte.


EDIT: Or use Serin B.6, T9600_8, ($55, $55), B0, #B1, #B2. With this, converting from ASCII to decimal is automatic. Then it becomes:

b4 = b1 * 10 + b2
 
Last edited:

cooldude4u2no

New Member
Of course you're right. That could also be it. That's why in these cases it's better to divide the project in smaller steps and test and debug one at a time.




b4 = b1 - "0" * 10 + b2 - "0"

If the above look weird, that's because Picaxe Basic knows no precedence for operators and evaluates all expressions strictly from left to right.

You're receiving ASCII characters, meaning that when you send "0" what arrives is a byte with value 48 ("1" = 49, and so on). Good thing with Picaxe you can use commas to work with ASCII codes so that "0" actually is the same as 48.

So, you take the first byte (tenths), subtract 48 from it to get the decimal value ("8" = 56 becomes 8), multiply it by 10 and add the decimal value from the second byte.


EDIT: Or use Serin B.6, T9600_8, ($55, $55), B0, #B1, #B2. With this, converting from ASCII to decimal is automatic. Then it becomes:

b4 = b1 * 10 + b2
well ill be! Too bad this isnt as easy as C# or VB.net. lol Ive got to be sure to save this post. U taught me alot today. Maybe one day ill be able to return the favor. Thanks Guys for your help!
 

SAborn

Senior Member
Why not just send and receive ascii charactors and be done with it.

TX

b1= 80

serout C.1, T9600_8, ($55,$55, "D", $55, #b1)

************************************

RX

Serin B.6, T9600_8, #B0, #B1

****************************
You just need to send a non ascii ($55) between each ascii value or the picaxe dont always see the end of one charactor before the start of the next.

Using ascii is a hell of a lot easier than all the conversion processes.
 
Top