Shop OBEX P1 Docs P2 Docs Learn Events
433 MHz RF Transceiver Code Fail! — Parallax Forums

433 MHz RF Transceiver Code Fail!

Luis_PLuis_P Posts: 246
edited 2010-05-26 15:29 in BASIC Stamp
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
·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-23 16:42
    The 433MHz transceivers have no built-in error checking. It's possible that some noise causes a false signal that "looks like" an exclamation point ("!") to the BS2, then the SERIN statement will take the next byte as it's value for X1.

    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.
  • LeonLeon Posts: 7,620
    edited 2010-05-23 17:19
    Low-cost transceivers usually require NRZ encoding and decoding, such as Manchester code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Leon Heller
    Amateur radio callsign: G1HSM
  • FranklinFranklin Posts: 4,747
    edited 2010-05-23 17:19
    You say it sends all by itself. Is the data received correct or garbage? you may need to add a resistor to your button line to make sure it stays in the off position until pressed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Luis_PLuis_P Posts: 246
    edited 2010-05-23 20:26
    Mike you are right, some noise causing a false signal. I need to use the checksum code but the problem is that I'm using the BS1 for the transmitter and there are no examples for the Bs1. I don't know how to build my own error check code on $PBASIC 1.0. Can you help me with something simple? PLEASE!

    THANKS
    LUIS
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-23 23:44
    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
  • Luis_PLuis_P Posts: 246
    edited 2010-05-24 02:47
    Solved! Actually was more simple that I tought, if I clear the variable after the receiver receive the value, if some other noise activate the loop will not go trought if I place a condition on my 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!!!!!
  • MoskogMoskog Posts: 554
    edited 2010-05-24 07:25
    As long as you only need to send a simple value as that, your code will work well, but you are still facing the possibility of receiving a false signal if you are in a noisy environment. I guess (from self experience) that you soon will continue to develope your program as new ideas pops out of your brain. Soon as you want to send and receive several values you will need some kind of error check. So print out and save Mike's good advices, you will probably need them sooner then you know.
  • Luis_PLuis_P Posts: 246
    edited 2010-05-24 15:13
    I was wrong!! I'm still getting noises getting into my code!!! I will try Mike's suggestions today.

    · Wird!!!smhair.gif

    Gracias
    Luis
  • Luis_PLuis_P Posts: 246
    edited 2010-05-24 15:27
    Mike:
    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
  • Luis_PLuis_P Posts: 246
    edited 2010-05-24 17:59
    Oh I guess $A5,$5A are values sent for x1 and x2.
    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....
  • Luis_PLuis_P Posts: 246
    edited 2010-05-24 20:25
    Aha! the =! means does not equal, is that right Mike?
    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?
  • Luis_PLuis_P Posts: 246
    edited 2010-05-25 22:05
    Thanks everybody! is working find now:

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-25 22:50
    I probably should have said something like:

    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
  • Luis_PLuis_P Posts: 246
    edited 2010-05-26 15:16
    What? Mike, now you really confuse me, even more. Where did you get the $FF, you never mentioned before, are you in the rigth topic?
    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!
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-26 15:29
    Read the section in the Stamp Basic Syntax and Reference Manual on the "^" operator, then try what I've written on paper.

    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.
Sign In or Register to comment.