433 MHz RF Transceiver Code Fail!
Luis_P
Posts: 246
Please need help to solve this problem! I don't know if the transceiver doesn't work well or what, but the code below fail. It suposs to communicate between Bs1 and Bs2 only when 1 button is pressed (pin2) but sometimes transmition happens by itself! How can that happen?
The Bs1 is connected to one·Transceiver and has a button on Pin2
this is the code for BS1:
' {$STAMP BS1}
··
SYMBOL x1 = B2
Check1:
· PAUSE 100
· IF· PIN2 = 1 THEN press1· 'bs1 button
GOTO Check1
··· press1:
··· x1 = 255
··· HIGH 5··· '+ line on - Receiver on
··· PAUSE 200
··· HIGH 1 'T/R line
··· PULSOUT 0, 300 'Sync pulse for the Transceivers
··· SEROUT 0, N2400, ("!", x1)
··· PAUSE 150
··· LOW 5····· '+ line off - receiver off
··· PAUSE 1000
'====================================================
The Bs2 is connected to another transceiver the loop is waiting for a signal, when I press button on BS1 (pin2) is out of the loop and goes to my code. This is the code for Bs2:
' {$STAMP BS2}··
LOW 1 ' T/R Line
DO
· LOW 0
· SERIN 0, 16780, [noparse][[/noparse]WAIT("!"), x1]
· HIGH 0
· IF x1 = 255 THEN GOTO Main_Code
·
LOOP
Main_Code:
··· 'My code goes here
·
The Bs1 is connected to one·Transceiver and has a button on Pin2
this is the code for BS1:
' {$STAMP BS1}
··
SYMBOL x1 = B2
Check1:
· PAUSE 100
· IF· PIN2 = 1 THEN press1· 'bs1 button
GOTO Check1
··· press1:
··· x1 = 255
··· HIGH 5··· '+ line on - Receiver on
··· PAUSE 200
··· HIGH 1 'T/R line
··· PULSOUT 0, 300 'Sync pulse for the Transceivers
··· SEROUT 0, N2400, ("!", x1)
··· PAUSE 150
··· LOW 5····· '+ line off - receiver off
··· PAUSE 1000
'====================================================
The Bs2 is connected to another transceiver the loop is waiting for a signal, when I press button on BS1 (pin2) is out of the loop and goes to my code. This is the code for Bs2:
' {$STAMP BS2}··
LOW 1 ' T/R Line
DO
· LOW 0
· SERIN 0, 16780, [noparse][[/noparse]WAIT("!"), x1]
· HIGH 0
· IF x1 = 255 THEN GOTO Main_Code
·
LOOP
Main_Code:
··· 'My code goes here
·
Comments
The best way to handle this is to move somewhere far away from other sources of 433MHz signals. That's not possible for most situations, so the next best way is to make the transmission more redundant, possibly using something more complex than "!" for a prefix and possibly sending the data (x1) multiple times and comparing the two or more values, then ignoring them if they don't match. There are coding examples for the 433MHz transceivers that use a CRC (cyclic redundancy check) to detect communications errors and resend the data if it's not received correctly. Look at the Parallax webstore page for the transceivers for links to the examples.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Leon Heller
Amateur radio callsign: G1HSM
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
THANKS
LUIS
You're really only sending one of two messages and maybe receiving two different fixed messages using the BS1. Modify the examples for the BS2 to fit your situation and, instead of actually transmitting the data with the BS2, use DEBUG statements to display what's being sent and what's expected to be received by the BS2 program. If you use the HEX formatter, you'll see the data in hexadecimal. You can then put together a simple BS1 program that just sends one of two or three specific character strings and looks for a fixed response (acknowledge or error acknowledge). This way you don't have to have the error check code on the BS1.
As an alternative, use the "!" as the introducer, but use something like $A5 as the data character and have its complement $5A as a 2nd data character like SEROUT 0, N2400, ("!", $A5,$5A). In your BS2 code, you'll have SERIN 0, 16780, [noparse][[/noparse]WAIT("!"), x1, x2] and follow that with IF x1 = !x2 and x1 = $A5 THEN GOTO Main_Code
Do
If x1 = 255 then
'Go to my code
Endif
Loop
'My code goes here
x1= 0 ' if I clear the value then only my transmitter will pass the loop because it sends the value of x1 = 255
Thanks for your time Mike!!!!!
· Wird!!!
Gracias
Luis
This is what you suggest. But I don't see the x1 and x2 values been send by the BS1 (transmitter). How that works?
'BS1
SEROUT 0, N2400, ("!", $A5,$5A).
'BS2
SERIN 0, 16780, [noparse][[/noparse]WAIT("!"), x1, x2]
IF x1 = !x2 and x1 = $A5 THEN GOTO Main_Code
so what !x2 means? maybe is $A5 backwards? because if x1 is = !x2 wich x2 is $5A then !x2 is equal to $A5 ? mmmmm
When I get home I will try to debug those hex. and see if I can figure out.
I'll come back to work now....
So what you doing is putting two HEX valriables and compare both to make sure there are not equal and then that x1 = $A5
I got it right?
For future reference:
'BS1 with Transceiver as a remote control (transmitter)
SEROUT 0, N2400, ("!", $A5,$5A).
'BS2 with Tranceiver (receiver)
SERIN 0, 16780, [noparse][[/noparse]WAIT("!"), x1, x2]
IF x1 <> x2 and x1 = $A5 THEN GOTO Main_Code
IF x1 = (x2 ^ $FF) AND x1 = $A5 THEN
Saying !x2 is actually·equivalent to·saying x2 ^ $FFFF which isn't exactly the same thing.· Sorry
You should just get my code (top of the page) and change what ever is wrong.
I will re-open this topic because I still getting errors, less than before but still not working
Thanks Mike!
The whole idea is that you want to send the same data several times, possibly modified. In this case, the data is sent once plain, then the one's complement of the data is sent. The BS2 code checks that one byte is the one's complement of the other, then checks that the data has the expected value.