PDA

View Full Version : Wireless with DS18S20



lerameur
- 1st May 2007, 16:24
Hi

This is a project I did a while ago, it was not working at 100%, I am back into it now and I cannot resolve the issue. The I am using two modules, One sending and one receiving (wireless). The sending modulesends the raw data, and the receiving module decodes it and interprets it onto a LCD screen..
I do get the right temperature, but it just keep changing to extrem values, . Lets say it 21 degrees, then it would chnge to -6500 then to 320 then back to 21. I tried changing the baudrate, faster and slower, no success.
here are both programs.
In the sending program i used to have a LCD to see what was sending, But the final version do not have a LCD, but by removing all the lines corresponging to the LCD, it even worst, I barely see the real temperature, and most of the time its random numbers..
thanks for the help.


'TRANSMIT PIC Code
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTA ' Set LCD Data port
DEFINE LCD_DBIT 0 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000

DQ var PortB.5 : temp var word : temperature var word : count_remain var byte : count_per_c var byte : counter var byte
encoded1 var word:encoded2 var word:encoded22 var word:encoded11 var word:encoded33 var word:encoded44 var word

loop:
owout DQ,1,[$cc] : owout DQ,0,[$44] : Pause 500 : owout DQ,1,[$cc] : owout DQ,0,[$be]
owin DQ, 0, [temperature.LOwBYTE, temperature.Highbyte, Skip 4, count_remain, count_per_c]
'23

encoded1 =temperature.LowBYTE : encoded2 =temperature.HighBYTE

For counter=0 TO 7
IF encoded1.0[counter]=0 Then
encoded11.0[counter*2]=0 : encoded11.0[counter*2+1]=1
Else
encoded11.0[counter*2]=1 : encoded11.0[counter*2+1]=0
EndIF
Next counter

For counter=0 TO 7
IF encoded2.0[counter]=0 Then
encoded22.0[counter*2]=0 : encoded22.0[counter*2+1]=1
Else
encoded22.0[counter*2]=1 : encoded22.0[counter*2+1]=0
EndIF
Next counter
'43
For counter=0 TO 7
IF count_remain.0[counter]=0 Then
encoded33.0[counter*2]=0 : encoded33.0[counter*2+1]=1
Else
encoded33.0[counter*2]=1 : encoded33.0[counter*2+1]=0
EndIF
Next counter

For counter=0 TO 7
IF count_per_c.0[counter]=0 Then
encoded44.0[counter*2]=0 : encoded44.0[counter*2+1]=1
Else
encoded44.0[counter*2]=1 : encoded44.0[counter*2+1]=0
EndIF
Next counter
'59

lcdout $FE,1 : LCDOUT "TempC: ", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, bin count_remain , ".", bin count_per_c," ",$DF,"F"

serout portb.2, n2400,[$55,$55,$55,$55,$aa,encoded11.HighBYTE,encoded11.L owBYTE,encoded22.HighBYTE]
serout portb.2, n2400,[encoded22.LowBYTE,encoded33.HighBYTE,encoded33.Low BYTE,encoded44.HighBYTE]
serout portb.2, n2400,[encoded44.LowBYTE]
goto loop

end


'RECEIVE PIC Code
INCLUDE "modedefs.bas"
DEFINE OSC 20 'use external 20mhz crystal
CMCON = 7 : ANSEL = 0 : ADCON1 = 7
DEFINE LCD_DREG PORTB ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 1 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 0 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000

counter var byte : temperature var word : encoded1 var byte : encoded2 var byte : encoded3 var byte
encoded11 var word : encoded22 var word : encoded33 var word : encoded44 var word : encoded4 var byte
count_remain var byte : count_per_c var byte : temp var word : tempc var word : tempF var word
temperature1 var word : temp1 var word : tempbit var byte : tempf0 var word
pause 2000

loop:
'23
waitfor55:
serin portb.2 , n2400 , temp : if temp <> $55 then goto waitfor55

waitforaa:
serin portb.2 , n2400 , temp : if temp <> $aa then goto waitforaa

serin portb.2, n2400, encoded11.HighBYTE : serin portb.2, n2400, encoded11.LowBYTE
serin portb.2, n2400, encoded22.HighBYTE : serin portb.2, n2400, encoded22.LowBYTE
serin portb.2, n2400, encoded33.HighBYTE : serin portb.2, n2400, encoded33.LowBYTE
serin portb.2, n2400, encoded44.HighBYTE : serin portb.2, n2400, encoded44.LowBYTE

For counter=0 TO 7 'decoding
encoded1.0[counter]=encoded11.0[counter*2] : encoded2.0[counter]=encoded22.0[counter*2]
encoded3.0[counter]=encoded33.0[counter*2] : encoded4.0[counter]=encoded44.0[counter*2]
Next counter
'41

temperature.LowBYTE = encoded1
temperature.HighBYTE = encoded2
count_remain = encoded3
count_per_c = encoded4


temperature = ((( temperature >> 1) *100)- 25) + (((count_per_c - count_remain) * 100) / count_per_c)
tempF = (((temperature /5) *9 ) +3200)


lcdout $FE,1, "TempC: ", "+", dec (temperature / 100) , ".", dec2 temperature," ",$DF,"C"
lcdout $FE,$C0, "TempF: ", "+", dec2 (tempF / 100) , ".", dec2 (tempF // 100)," ",$DF,"F"


goto loop

mister_e
- 1st May 2007, 16:31
When you attach the LCD, is reading O.K?

Did you tried with a single SEROUT line on the transmitter and on SERIN line on the receiver?

Is this working if you remove the RF stuff and connect them with wires?

skimask
- 1st May 2007, 16:56
Hi
This is a project I did a while ago, it was not working at 100%, I am back into it now and I cannot resolve the issue. The I am using two modules, One sending and one receiving (wireless). The sending modulesends the raw data, and the receiving module decodes it and interprets it onto a LCD screen..
I do get the right temperature, but it just keep changing to extrem values, . Lets say it 21 degrees, then it would chnge to -6500 then to 320 then back to 21. I tried changing the baudrate, faster and slower, no success.
here are both programs.
In the sending program i used to have a LCD to see what was sending, But the final version do not have a LCD, but by removing all the lines corresponging to the LCD, it even worst, I barely see the real temperature, and most of the time its random numbers..
thanks for the help.


I remember this...
How often do you actually NEED to send the temperature?
How about adding a bit of simple 'software' filtering in the receiver code?
Something like:

If current_temp_from_sensor > last_temp_reading then
displayed_temp = displayed_temp + 1
else
displayed_temp = displayed_temp - 1
endif
last_temp_reading = displayed_temp
goto where_ever_your_loop_goes_to...

With a little bit of a software-filter-slower-downer-thingy, you're received temperature reading won't respond to extreme flucuations nearly as quickly, but will still respond to a slow-ish moving temperature reading.

dhouston
- 1st May 2007, 16:59
I do get the right temperature, but it just keep changing to extrem values, . Lets say it 21 degrees, then it would chnge to -6500 then to 320 then back to 21. I tried changing the baudrate, faster and slower, no success.Are you sure that you are getting the correct temperature at the sending unit?

This nearly exact issue has come up in three different threads in the past 3-4 days. I will post two simple PBP programs to Code Examples that show how to send two bytes via RF with built-in error checking using the NEC protocol.

lerameur
- 1st May 2007, 17:00
yes its a good idea, but it still wont remove the problem . I am now redoing the whole ting on bread board, I had soldered the sending module, So i am re-doing that on breadboard and do some more testing.

Jerson
- 1st May 2007, 17:14
Lerameur

I suspect you too are using one of the ASK modulated RF modules. I understand from your code that you are Manchester coding the data to send to keep the module happy. However, I find the modules work best when you have just 4-5 bytes to send. Keep the messages short. So, I have used the following technique to send data properly. Of course, it helps to mention that RF shielding is very important for the receiver module in case you have the OEM version.



// wait for a packet marker RJ
serin2 RxD, Baud, [WAIT("RJ"), HEX1 Acc1]

// now disable the receiver since we got the data we need
RxDisable = 1

// if the data is for me, process it
if (ID = Acc1) then
pause 100 ' this delay is to allow the RX01 to turn off
' to prevent RF collision with multiple devices
Pot PotPort, 255, Acc1 ' read pot position and send

// Send the reply with ACC1 having the value to send
// the lower case rj is the packet marker to indicate acknowledge
Serout2 Txd,Baud,[$55,$55,$55,"rj", HEX1 ID,",",Dec2 Acc1]
endif


As you see, I haven't used any encoding and do happen to send the data properly. The trick here is that keeping the message short tricks the receiver into reading the data properly before the signal strength droops at the receiver end.

You may add LRC (Checksum) which will help you choose the good data packets and throw away the corrupted ones.

Jerson

lerameur
- 1st May 2007, 17:28
I use this module here:
http://www.robotshop.ca/home/products/robot-parts/communication-control/rc-communications/on-shine-high-sensitivity-tx-rx.html
is it OOK module ??

I finished building the sending module with the LCD wirelessly. The module ALWAYS indicate a good temperature. So it has to do with the RF part.

k

Jerson
- 1st May 2007, 17:37
Yes it is clearly mentioned in the datasheet to have Amplitude Shift keying modulation. There is a similar thread of recent vintage (about a week old) on this forum that explains how these modules work. Unfortunately, I cant remember the authors name. I shall check and update this post if I find it.

edit : http://www.picbasic.co.uk/forum/showthread.php?t=6212
See post #12

Jerson

lerameur
- 1st May 2007, 17:55
I tried without encoding and I get exactly the same result as with encoding. Slwed end speed up the baud rate had no impact either
ken

dhouston
- 1st May 2007, 18:01
I use this module here:
http://www.robotshop.ca/home/products/robot-parts/communication-control/rc-communications/on-shine-high-sensitivity-tx-rx.html
is it OOK module ??That's a better receiver than the superregenerative receivers I referred to. And that's a really, really, really good price for a TX/RX pair. Unfortunately, the datasheet really doesn't provide adequate details but I'm guessing it's a superhet or hybrid design and the things I said about AGC & threshold may not apply.

lerameur
- 2nd May 2007, 00:56
hi
As for the ground and shielding, should I ground my antrenna or used a metal plate. I have a plastic box, is there a better method ? Of course the second wire of the antenna goes to the input..
ken

Jerson
- 2nd May 2007, 04:59
No, no. You have to shield the receiver module as in put it in a metal box with just the antenna sticking out into the open to get the best results.

This is what I did - take a look here http://www.geocities.com/jerson.geo/photogallery/photo356/rfjoy004.jpg

the 2 green wires you see are the antenna for the transmitter and receiver modules

Jerson

dhouston
- 2nd May 2007, 10:32
hi
As for the ground and shielding, should I ground my antrenna or used a metal plate. I have a plastic box, is there a better method ? Of course the second wire of the antenna goes to the input..
ken
There's no need for anything special and shielding is usually superfluous unless the receiver is near (6-8') an RF noise source. There are commercial antennas available cut for 433.92MHz or you can build your own - it depends on the range needed. A 6 inch piece of wire attached to pin 8 of the receiver may be adequate. Or you can use one like those sold by Bruce Reynolds...http://www.rentron.com/PicBasic/RemoteControl.htmor build one like...http://davehouston.net/eggbeater.htmwhich can be built with any insulated solid wire stiff enough to hold its shape. The phasing line can be made from 75-ohm coax if 93-ohm isn't available.

For the transmitter, a 6" wire is usually more than adequate.

If you need extra range, add a wide-band preamp between the receiving antenna and receiver. Getting 150-200' through a few walls is usually possible.

I've ordered one of the RX/TX pairs so I can test the receiver. In the meantime, can you tell me what the chip is on the receiver? I'm interested in the 24-pin chip - I can tell it's a HiMark chip but cannot read the number. I'm familiar with a HiMark 18-pin superheterodyne ASK receiver chip but cannot recall seeing a 24-pin chip.

lerameur
- 2nd May 2007, 20:07
Ok I am getting better reception with grounded antennas.

this is what is written on the 24 pin chip:
0637
BD69F1

ken