Shop OBEX P1 Docs P2 Docs Learn Events
Software For 433 MHZ Transceiver — Parallax Forums

Software For 433 MHZ Transceiver

simpsonmichael1simpsonmichael1 Posts: 13
edited 2010-05-10 14:03 in BASIC Stamp
·· I downloaded the program examples found on this website·to run the 433 MHZ transciever with my basic stamp.··I'm not sure how to modify the programs below as some of the program commands are new to me.· Basically, I want to switch a·relay on/off using a remote transmitter via a password, such as 3564 sent from that transmitter.· The receiver·captures·the 3564 password and energizes a relay.·· Is there a much simpler way to tranmit and receive a message?··Does anyone have documentation on these tranceivers, because I·noticed there's not alot of information on this subject.· I do not have the experience to understand the examples below.· Please advise.· Thank you.

For the receiver side:

Wiring:
' P14
> Parallax 433 MHz RF transceiver (27982) TR pin.
' P15
> Parallax 433 MHz RF Transceiver (27982) DATA pin.

'
[noparse][[/noparse] Revision History ]
' 10-08-2009
' Updated program description to accurately cover the change in which RF
' modules are being used by this version of the program.

'
[noparse][[/noparse] I/O Definitions ]
TxEnable······· PIN···· 14············· ' Transmitter(27982)TR pin
Tx············· PIN···· 15············· ' Transmitter(27982)DATA pin
'
[noparse][[/noparse] Constants ]
EOM············ CON···· 255············ ' Value to signal end-of-message
#SELECT $STAMP························· ' Select Baud constants
· #CASE BS2, BS2E, BS2PE
··· T1200······ CON···· 813
··· T2400······ CON···· 396
··· T4800······ CON···· 188
··· T9600······ CON···· 84
··· T19K2······ CON···· 32
· #CASE BS2SX, BS2P
··· T1200······ CON···· 2063
··· T2400······ CON···· 1021
··· T4800······ CON···· 500
··· T9600······ CON···· 240
··· T19K2······ CON···· 110
· #CASE BS2PX
··· T1200······ CON···· 3313
··· T2400······ CON···· 1646
··· T4800······ CON···· 813
··· T9600······ CON···· 396
··· T19K2······ CON···· 188
#ENDSELECT
Inverted······· CON···· $4000·········· 'Value for inverted serial format
Baud··········· CON···· T9600+Inverted· '9600 baud, 8,N,1 inverted
'
[noparse][[/noparse] Variables ]
string········· VAR···· Byte(16)······· 'Array to hold received data
strLen········· VAR···· Byte··········· 'Length of string received
temp··········· VAR···· Byte··········· 'Temporary variable
packet········· VAR···· Byte··········· 'Current packet number
lastPacket····· VAR···· Byte··········· 'Last good packet number
cValue········· VAR···· Byte··········· 'Value to add to CRC value
crc············ VAR···· Word··········· 'Calculate CRC value
rcvdCrc········ VAR···· Word··········· 'Received CRC value

'
[noparse][[/noparse] EEPROM Data ]

'
[noparse][[/noparse] Initialization ]

'
[noparse][[/noparse] Program Code ]
Main:
LOW Tx
LOW TxEnable
DO
· ' Wait for preamble, then receive data and crc value
· SERIN Tx,Baud,[noparse][[/noparse]WAIT ("U!"), packet, strLen, STR string\strLen,
················ rcvdCrc.LOWBYTE,rcvdCrc.HIGHBYTE]
· ' Calculate crc of received data
· crc = 0
· FOR temp = 0 TO strLen-1
··· cValue = string(temp)
··· GOSUB CalcCRC
· NEXT
· ' See if received crc value matches calculated crc value
· IF rcvdCrc = crc THEN
··· ' Check if this is a repeated packet
··· IF packet <> lastPacket THEN
····· ' Is last character the "end-of-message" marker ?
····· IF string(strLen-1) <> EOM THEN
······· DEBUG STR string\strLen·········· ' Display string on debug screen
····· ELSE
······· strLen = strLen -1··············· ' Don't display EOM
······· DEBUG STR string\strLen, "--END OF MESSAGE--",CR,CR
····· ENDIF
··· ENDIF
··· lastPacket = packet
··· ' Send acknoledgement back to transmitter
··· HIGH TxEnable
··· PULSOUT Tx,1200
··· SEROUT Tx, Baud, [noparse][[/noparse]"UUUU"]
··· PAUSE 3···························· ' Give transmitter time to process
··· SEROUT Tx,Baud, [noparse][[/noparse]"!"]
··· PAUSE 3···························· ' Give transmitter time to process
··· SEROUT Tx, Baud, [noparse][[/noparse]crc.LOWBYTE, crc.HIGHBYTE]
··· LOW TxEnable
· ELSE
··· ' Received crc did NOT match calculated crc
··· DEBUG "· ** RECEIVE ERROR **· ", BELL
· ENDIF
LOOP

'
[noparse][[/noparse] Subroutines ]
' CRC Checksum Calculation Routine
CalcCRC:
· cValue= crc.HIGHBYTE ^ cValue >> 4 ^ (crc.HIGHBYTE ^ cValue)
· crc = cValue ^ (cValue << 5) ^ (cValue << 12) ^ (crc << 8)
RETURN





For the transmitter:
' Wiring:
' P14
> Parallax 433 MHz RF transceiver (27982) TR pin.
' P15
> Parallax 433 MHz RF Transceiver (27982) DATA pin.

'
[noparse][[/noparse] Revision History ]
' 09-09-09
' Updated code to support RF Transceiver instead of seperate Transmitter
' and Receiver.
' 10-08-2009
' Updated program description to accurately cover the change in which RF
' modules are being used by this version of the program.

'
[noparse][[/noparse] I/O Definitions ]
TxEnable······· PIN···· 14············· ' Transmitter(27982)TR pin
Tx············· PIN···· 15············· ' Transmitter(27982)DATA pin
'
[noparse][[/noparse] Constants ]
EOM············ CON···· 255············ ' Value to signal end-of-message
#SELECT $STAMP························· ' Select Baud constants
· #CASE BS2, BS2E, BS2PE
··· T1200······ CON···· 813
··· T2400······ CON···· 396
··· T4800······ CON···· 188
··· T9600······ CON···· 84
··· T19K2······ CON···· 32
· #CASE BS2SX, BS2P
··· T1200······ CON···· 2063
··· T2400······ CON···· 1021
··· T4800······ CON···· 500
··· T9600······ CON···· 240
··· T19K2······ CON···· 110
· #CASE BS2PX
··· T1200······ CON···· 3313
··· T2400······ CON···· 1646
··· T4800······ CON···· 813
··· T9600······ CON···· 396
··· T19K2······ CON···· 188
#ENDSELECT
Inverted······· CON···· $4000·········· 'Value for inverted serial format
Baud··········· CON···· T9600+Inverted· '9600 baud, 8,N,1 inverted
'
[noparse][[/noparse] Variables ]
string········· VAR···· Byte(16)······· 'Array to hold received data
idx············ VAR···· Word··········· 'Index into message data
StrLen········· VAR···· Byte··········· 'Length of string received
char··········· VAR···· Byte··········· 'Current character from message
packet········· VAR···· Byte··········· 'Current packet # being transmitted
rcvdCrc········ VAR···· Word··········· 'Crc value received
temp··········· VAR···· Byte··········· 'temporary byte variable
crc············ VAR···· Word··········· 'Calculate Crc value
'
[noparse][[/noparse] EEPROM Data ]
Message DATA " 3564.", CR············· 'password sent from transmitter
··········· DATA EOM

'
[noparse][[/noparse] Initialization ]

'
[noparse][[/noparse] Program Code ]
LOW Tx································· 'Initialize transceiver interface
LOW TxEnable··························· 'Disable transmitter
packet = 1····························· 'Initialize packet number
DO
· idx = Message························ 'Point idx to start of message data
· DO
··· strLen = 0························· 'Set string length to zero
··· crc = 0···························· 'Start Crc at zero
··· DO
····· strLen = strLen + 1
····· READ idx, char··················· 'Read a character from message data
····· idx = idx + 1···················· 'Point to next character in message
····· string(strLen-1) = char·········· 'Put character into string array
····· temp = char······················ 'Prepare to add char to Crc value
····· GOSUB CalcCRC···················· 'Add cValue to Crc value
····· IF (strLen = 15) OR (char = EOM) THEN EXIT ' Exit if done
··· LOOP······························· 'Keep reading message characters
··· DO
RecvTimeOut:
····· PAUSE 100························ 'Give receiver time to process
····· DEBUG "Sending packet ", DEC packet, CR
····· HIGH TxEnable···················· 'Enable transmitter
····· ' Send packet
····· PULSOUT Tx,1200·················· 'Send sync pulse to radio
····· ' Send preample "UUUU!", packet #, string length, string data, crc
····· SEROUT Tx, Baud, [noparse][[/noparse]"UUUU!", packet, strLen, STR string\strLen,
······················· crc.LOWBYTE, crc.HIGHBYTE]
····· LOW TxEnable····················· 'Disable transmitter
····· PAUSE 10
····· ' Wait for response from receiver
GetResponse:
····· ' Receive up to 100 characters looking for a "!"
····· ' Use rcvdCrc as temporary variables
····· FOR rcvdCrc.LOWBYTE = 1 TO 100
······· SERIN Tx,Baud,600,RecvTimeOut,[noparse][[/noparse]rcvdCrc.HIGHBYTE]
······· IF rcvdCrc.HIGHBYTE = "!" THEN EXIT
····· NEXT
····· ' If we didn't receive a "!" then timeout
····· IF rcvdCrc.HIGHBYTE <> "!" THEN RecvTimeOut
····· ' Receive the Crc value
····· SERIN Tx,Baud,600,RecvTimeOut,[noparse][[/noparse]rcvdCrc.LOWBYTE,rcvdCrc.HIGHBYTE]
··· LOOP UNTIL crc = rcvdCrc··········· 'Repeat packet until crc match
··· packet = packet + 1················ 'Advance packet value
··· packet = packet MIN 1·············· 'Don't use packet value zero
· LOOP WHILE char <> EOM··············· 'Keep sending until EOM
LOOP··································· 'Start at the beginning

'
[noparse][[/noparse] Subroutines ]
' CRC Checksum Calculation Routine
CalcCRC:
· temp= crc.HIGHBYTE ^ temp >> 4 ^ (crc.HIGHBYTE ^ temp)
· crc = temp ^ (temp << 5) ^ (temp << 12) ^ (crc << 8)
RETURN

·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-10 14:03
    The 433MHz Transceivers send serial data (with SERIN / SEROUT) back and forth between two Stamps. They have no error checking or error correction, so, if you want that, you have to do it in your program. The examples you downloaded include error checking using a checksum and the transmit and receive ends cooperate so that the transmitting end expects confirmation of correct reception of the data and will resend the data if it doesn't get it. If you have specific questions about some of the Basic statements or operators used and you can't find an explanation in the documentation (available in the Stamp Editor's help files or downloadable from Parallax), ask.

    The documentation for the Transceivers is available via links on the product's webstore page. You'll also find links to the sample programs.

    The documentation shows some very simple examples of sending data without error checking or correction. If the Transceivers are close to one another and there's no potential interference at your location, that may work. Since you want to send a password to activate a relay, I wouldn't recommend this. Use the more complex routines.

    If you're going to use the sample code, spend some time to understand it. Read the documentation on the Basic statements or operators that you don't know. Actually experiment with the sample code and get it to work, first as it's written, then modified the way you want it.
Sign In or Register to comment.