Problem receiving DS18B20 temperatures from Tx/Rx units

rbright

Member
I've constructed a pair of 434 Mhz TX/RX units based upon Stan Swan's Silicon Chip article Jan 06.
Worked like a dream as designed to transmit temperature integer values using the readtemp instruction.

Based upon the success of that I then wanted to calculate & transmit the temperature to 4 decimal points
so I started using the readtemp12 instruction but I'm receive the incorrect temperature values at the far end.

To simplify fault finding I unplugged the RF modules and made a connection between units using 2 wires.

The TRANSMITTER code below has been stripped of the usual serout 4,n300,(85,85,85,85,"ABC",b1) preamble used with the Tx/RX modules

The TRANSMITTER code works fine and looks good in debug and I can actually see with an external terminal program the valid data typically in the form "Temp = 23.1250" but at the RECEIVER the data out of the serin instruction (as seen in debug into b1) is incorrect. The serin is also stripped in this example of the usual (85,85,85,85,"ABC",b1) preamble.
What is wrong with my implimentation of serin ??? this is the second line of the receiver code and it's output is incorrect in debug. The output code receiver is something like "Temp = 85"

Any ideas .............


' TRANSMITTER CODE
'Picaxe-08M based upon 434MHz Tx/Rx data units. Ver 1.0 11/05 for Jan.'06 SiChip
tx: ' 434MHz UHF transmitter & DS18B20 temp reading routine
high 2 ' turn on DS18B20 temp sensor
wait 1 ' settling time pre temp reading
readtemp12 1,w1 ' direct Celsius value returned
w2 = w1 / 16 ' Integer part
w3 = w1 & %0001 MAX 1 * 0625
w3 = w1 & %0010 MAX 1 * 1250 + w3
w3 = w1 & %0100 MAX 1 * 2500 + w3
w3 = w1 & %1000 MAX 1 * 5000 + w3
debug

SERTXD("Te = ",#w2,".") ' send interger part to local programming cable followed by "."
serout 4,n300,("Temp = ",#w2,".")

SERTXD(#w3,CR,LF) 'send decimal part
serout 4,n300,(#w3,CR,LF)

PAUSE 1
pulsout 0,200 ' red LED winks as data sent
sleep 1 ' power down (adjust to suit SLEEP units 2.3 sec)
goto tx ' loop to send more data

===================================================================

'RECEIVER CODE
rx: 'receiving routine
serin 3,N300,b1 'awaits b1 data without any qualify preceeding

'debug
pulsout 1,200 'green LED winks- doubled if both TX & repeater received!
sertxd("Temp = " ,#b1," ") 'simple F8 display of Celsius temp.Easily extended-Excel?
pause 500
serout 0,n300,("temp is ",#b1," ",13,10)
pause 500
goto rx 'loop to await next data arrival

 

Technical

Technical Support
Staff member
Your serout and serin do not match

serout 4,n300,(#w3,CR,LF)
...
serin 3,N300,b1

You are sending a word w3 in multiple byte ascii format (#) but receiving a single byte b1 in binary format.

Try this instead to trasnfer the value of w3 between chips (w3 is made up of b6 and b7)

serout 4,n300,(b6,b7)
...
serin 3,N300,b6,b7

 

rbright

Member
I tried replacing in TRANSMITTER the serout 4,n300,(#w3,CR,LF) with serout 4,n300,(b6,b7) and I now don't have ascii in the data part of the string that follows "Temp = " but that may not be a problem if it is interperated correctly at the other end
and I also replaced the serin 3,n300,b1 with serin 3,n300,b6,b7 as you suggest but on debug the contents of b6 = $54 and b7 = $67 so I'm still experiencing the same problem with what is returned from the serin instruction.
Appreciate further help
my code now looks like

' *************TRANSMITTER***************
'Picaxe-08M based upon 434MHz Tx/Rx data units. Ver 1.0 11/05 for Jan.'06 SiChip

tx: ' 434MHz UHF transmitter & DS18B20 temp reading routine

high 2 ' turn on DS18B20 temp sensor
wait 1 ' settling time pre temp reading
readtemp12 1,w1 ' direct Celsius value returned
w2 = w1 / 16 ' Integer part
w3 = w1 & %0001 MAX 1 * 0625
w3 = w1 & %0010 MAX 1 * 1250 + w3
w3 = w1 & %0100 MAX 1 * 2500 + w3
w3 = w1 & %1000 MAX 1 * 5000 + w3
'debug
SERTXD("Te = ",b4,b5,".") ' send interger part to local programming cable followed by "."
serout 4,n300,("Temp = ",b4,b5,".")
SERTXD(b6,b7,CR,LF) 'send decimal part
serout 4,n300,(b6,b7,CR,LF)
PAUSE 1
pulsout 0,200 ' red LED winks as data sent
sleep 1 ' power down (adjust to suit SLEEP units 2.3 sec)
goto tx ' loop to send more data

' ****************RECEIVER*****************
rx: 'receiving routine
serin 3,N300,b6,b7 'awaits b1 data without any qualify preceeding

'debug
pulsout 1,200 'green LED winks- doubled if both TX & repeater received!
sertxd("Temp = " ,b6,b7," ") 'simple F8 display of Celsius temp.Easily extended-Excel?
pause 500
serout 0,n300,("temp is ",b6,b7," ",13,10)
pause 500
goto rx 'loop to await next data arrival
 

hippy

Ex-Staff (retired)
You have a complete mish-mash of SEROUT and SERTXD commands and a complete mis-match between the amount of data going from the transmitter to the receiver.

In the transmitter, convert this ...<code><pre><font size=2 face='Courier'> SERTXD(&quot;Te = &quot;,b4,b5,&quot;.&quot;)
serout 4,n300,(&quot;Temp = &quot;,b4,b5,&quot;.&quot;)
SERTXD(b6,b7,CR,LF)
serout 4,n300,(b6,b7,CR,LF) </font></pre></code> To this ...<code><pre><font size=2 face='Courier'> SerTxd( &quot;Temp = &quot;,#w2,&quot;.&quot;,#w3,CR,LF) ' Display as Text
SerOut 4,N300,( &quot;Temp = &quot;,b4,b5,b6,b7) ' Send as Raw Binary Data
</font></pre></code>
In the receiver, convert this ...<code><pre><font size=2 face='Courier'> serin 3,N300,b6,b7 'awaits b1 data without any qualify preceeding
'debug
pulsout 1,200 'green LED winks- doubled if both TX &amp; repeater received!
sertxd(&quot;Temp = &quot; ,b6,b7,&quot; &quot;) 'simple F8 display of Celsius temp.Easily extended-Excel?
pause 500
serout 0,n300,(&quot;temp is &quot;,b6,b7,&quot; &quot;,13,10) </font></pre></code> To this ...<code><pre><font size=2 face='Courier'> SerIn 3,N300,(&quot;Temp = &quot;),b4,b5,b6,b7 ' Receive Raw Binary Data
PulsOut 1,200
SerTxd(&quot;Temp = &quot;,#w2,&quot;.&quot;,#w3,CR,LF) ' Display as Text
Pause 500
SerOut 0,N300,(&quot;Temp = &quot;,b4,b5,b6,b7) ' Pass on as Raw Binary Data </font></pre></code> You might want to change that last SerOut to something else; I'm not sure where it goes, what it's used for or what format data sent is meant to be in.

Once you've got data passing between transmitter and receiver correctly, you can start to refine what data needs to actually be passed between the two.

Edited by - hippy on 11/05/2007 17:30:44
 

hippy

Ex-Staff (retired)
Note also that your program has a bug in that it will display &quot;20.625&quot; when it should be displaying &quot;20.0625&quot;. Get the rest of teh code working first then come back to fixing that if you need to; you'll have to alter the SerTxd commands to ensure the leading zero isn't dropped.
 

manuka

Senior Member
<b>rbright </b> : Looks like the in house brains trust has pretty much cornered the problem! Glad I was able to inspire you with the original article.

From a measurement view point the validity of hi-res temperature readings may be debateable,as thermal issues may arise making readings suspect. Suggest you tell us more about your project. Stan
 

rbright

Member
YES Stan we sure have the &quot;house brains&quot; on this little problem of mine for which I'm very gratful. HIPPY especially thankful for your assistance but the SerIn function just doesn't seem to perform correctly with my setup of two PICAXE connected with 2 bits of wire.

I think the following code proves my concerns.

tx:
b4 = $41 'ASCII A preloaded in b4
b5 = $42 'ASCII B
b6 = $43 'ASCII C
b7 = $44 'ASCII D
SerOut 4,N300,(&quot;SerOut sends = &quot;,b4,b5,b6,b7) 'Send as raw binary data
debug
PAUSE 500
goto tx

*************************************

rx: 'receiving routine
SerIn 3,N300,b4,b5,b6,b7 'receive raw binary data
debug
pause 500
goto rx 'loop

I preload b4 - b7 with the hex equivalent of some ascii characters so I can monitor the transmission over the wired connection between the to devices.
debug shows that the correct code loads into the TX chips b4-b7 but at the RX end debug typically indicates random data like b4=$53, b5=$65, b6=$72, b7=$4F .

Following is a change I made in the receiver to preload b4-7 before the serin function to watch the changes in debug

rx: 'receiving routine
b4 = $41 'ASCII A
b5 = $42 'ASCII B
b6 = $43 'ASCII C
b7 = $44 'ASCII D
debug
pause 1000
serin 3,N300,b4,b5,b6,b7 'receive raw binary data
debug
pause 1000
goto rx 'loop


Absolutely got me stumped..... . I've built a new receiver this time using a 08 chip and problem persists. I've used a CRO to look on the pins of the 08 to look for any spurious noise or earth loops but all looks ok. On the two wires between the Tx &amp; Rx I can see with a terminal program the expected binary data that just happens to represent ascii data. Any further ideas anyone....
Cheers
 

Technical

Technical Support
Staff member
You still haven't understood what hippy was trying to explain!

SerOut 4,N300,(&quot;SerOut sends = &quot;,b4,b5,b6,b7) 'Send as raw binary data

This line transmits 19 bytes of data - you only receive 4!

You are sending &quot;S&quot;, &quot;e&quot;, &quot;r&quot;, &quot;O&quot;, etc until ... b4,b5,b6,b7

You must receive what you send!

So the send must only be

SerOut 4,N300,(b4,b5,b6,b7) 'Send as raw binary data

without any other text!
 

Technical

Technical Support
Staff member
In fact we just checked our ascii table and your program/system is working perfectly (as written), as

b4=$53 = &quot;S&quot;
b5=$65 = &quot;e&quot;
b6=$72 = &quot;r&quot;
b7=$4F = &quot;O&quot;

ie serin is receiving the first 4 bytes you actually send S-e-r-O!
 

hippy

Ex-Staff (retired)
As Technical says. You can either send and receive the raw data with a qualifier ...<code><pre><font size=2 face='Courier'>
SerOut 4,N300,(&quot;SerOut sends = &quot;,b4,b5,b6,b7)
SerIn 3,N300,(&quot;SerOut sends = &quot;),b4,b5,b6,b7 </font></pre></code> or without ...<code><pre><font size=2 face='Courier'> SerOut 4,N300,(b4,b5,b6,b7)
SerIn 3,N300,b4,b5,b6,b7 </font></pre></code> You cannot mix and match, and if a qualifier is used, it must be the same in SerIn as was used in SerOut. Using a qualifier will reduce the incidence of errors and help to keep what you receive synchronised with what is sent.
 
Top