temp/hum with rf modules
Tumbler
Posts: 323
Hi all,
The next values would be send by the transmitter (temperature and humidty values) coming from the SHT11:
··
·· sync, temp.HIGHBYTE, temp.LOWBYTE, hum.HIGHBYTE, hum.LOWBYTE, crc.HIGHBYTE, crc.LOWBYTE
Now i use the next code for the receiver.
This works great but i was wondering if this receiver code could be better.
Post Edited (Tumbler) : 4/8/2008 8:38:38 AM GMT
The next values would be send by the transmitter (temperature and humidty values) coming from the SHT11:
··
·· sync, temp.HIGHBYTE, temp.LOWBYTE, hum.HIGHBYTE, hum.LOWBYTE, crc.HIGHBYTE, crc.LOWBYTE
Now i use the next code for the receiver.
This works great but i was wondering if this receiver code could be better.

'{$STAMP BS2}
'{$PBASIC 2.5}
clrLCD CON 12 ' Clear entire LCD screen.
LightOn CON 14 ' lcd light on
LightOff CON 15 ' lcd light off
posCmd CON 16 ' Position cursor.
ESC CON 27 ' Escape code for graphics instructions.
n9600 CON $4054 ' Baudmode for 9600 bps, inverted.
DEGR CON 128
'
x VAR Word
y VAR Word
crc VAR Word
i VAR Word
temp VAR Word
hum VAR Word
sync VAR Word
key VAR Word
'
Initialize:
SEROUT 4,n9600,[noparse][[/noparse]LightOn,clrLCD,ESC,"F",64,ESC,"E",66] ' Clear screen and reset font.
key = "!"
PAUSE 1000
DO
'get data from receiver
SERIN 7, 16468, [noparse][[/noparse]sync, x.HIGHBYTE, x.LOWBYTE, y.HIGHBYTE, y.LOWBYTE, crc.HIGHBYTE, crc.LOWBYTE]
IF sync = key AND x+y = crc THEN 'let see if it's legal data we reveived
temp = x 'crc is correct: let see the temp and hum. on the lcd
hum = y
DEBUG DEC temp,":",DEC hum,":",crc
FREQOUT 0,30,500 'play a tone if received a legal crc
ENDIF
i=i+1
IF i = 300 THEN 'swich to temp screen
SEROUT 4,n9600,[noparse][[/noparse]posCmd,90,ESC,"F",67,ESC,"E",67,DEC (temp / 10), ",", DEC1 temp,ESC,"F",64,posCmd,79,DEC (hum / 10), ",", DEC1 hum,"%"]
PAUSE 100 'big temp value and small hum. value to LCD
ENDIF
IF i = 600 THEN 'switch to humidity screen
SEROUT 4,n9600,[noparse][[/noparse]posCmd,90,ESC,"F",67,ESC,"E",68,DEC (hum / 10), ",", DEC1 hum,ESC,"F",64,posCmd,79,DEC (temp / 10), ",", DEC1 temp,DEGR]
PAUSE 100 'big hum. and small temp value to LCD
i=0
ENDIF
LOOP
Post Edited (Tumbler) : 4/8/2008 8:38:38 AM GMT

