WhiteSpace
Well-known member
I've been distracted from a couple of larger projects over the past week, trying to create a small thermometer based on the DS18B20. I originally tried the LM335, but the readings fluctuated wildly, I think because the sensor produces an analogue ADC reading that varies by 10mV/degree C and I found it difficult to get a steady reading.
The DS18B20 was a bit tricky to set up in ReadTemp12 mode - I still don't really understand how the 12 bit data that it produces is converted to a temperature. However, a short piece of code in the manual (the 5th example here: https://picaxe.com/basic-commands/analogue-inputoutput/readtemp12/ ) provided a good base. For the display, I relied on @Hemi345's deciphering of the 128 x 32 code, and I also got some inspiration from @AllyCat's very impressive snippet here: https://picaxeforum.co.uk/threads/full-ascii-character-font-for-ssd1306-with-08m2-and-above.32003/ . I didn't understand large parts of it, but the use of "on x, do y" pointed me in the right direction and I eventually created a "Select Case" for displaying the digits that relied on program space rather than storage
What took some time to understand was the difference in value, when looking at Sertxd, between eg. #w12 and w12, and also when to enclose characters in quotation marks.
It seems to work OK: here's a photo:
(The battery holder is for an N battery, with three LR44 batteries and a dummy battery made from a sawn-off copper nail glued inside a cardboard tube). The intention is to squeeze it into a small footprint.
It shows a negative signed number if put in the freezer. It seems fairly accurate - within 1/10 of a degree of our central heating thermostat. I've attached the code in case it's of any use to anyone. Next steps - to provide for rounding up of the digits where required.
The DS18B20 was a bit tricky to set up in ReadTemp12 mode - I still don't really understand how the 12 bit data that it produces is converted to a temperature. However, a short piece of code in the manual (the 5th example here: https://picaxe.com/basic-commands/analogue-inputoutput/readtemp12/ ) provided a good base. For the display, I relied on @Hemi345's deciphering of the 128 x 32 code, and I also got some inspiration from @AllyCat's very impressive snippet here: https://picaxeforum.co.uk/threads/full-ascii-character-font-for-ssd1306-with-08m2-and-above.32003/ . I didn't understand large parts of it, but the use of "on x, do y" pointed me in the right direction and I eventually created a "Select Case" for displaying the digits that relied on program space rather than storage
Rich (BB code):
main:
gosub ClearDisplay
readtemp12 TempSensor, w10
;this part of the code based on the text on the Picaxe website: https://picaxe.com/basic-commands/analogue-inputoutput/readtemp12/
showsignedtemperature:
if w10 < $8000 then ;apparently this is the same as 32768, FWIW. Is that how the sensor displays 0 degrees in 12 bits?
w11 = w10
else
w11 = -w10
end if
w12 = w11 & 15 * 625 ; what does this do?
bintoascii w12, b15,b14,b13,b12,b11 ; here we are only interested in b14, which equates to the first decimal place. It would be good to show the decimal place properly, ie. rounding up or down. To be done: if b13 >= 5, then b14 = b14 + 1 and then I need to be able to roll over the unit and the 10 too.
w12 = w11 / 16
bintoascii w12, b20,b19,b18,b17,b16 ; we're only interested in the 10s and units b17 and b16
sertxd ( "degrees = ", "(tens) ", b17, " (units) ", b16, CR, LF) ; just to test that we have got them right. These come from splitting w12 into its component characters
sertxd( "or put another way, #w12 = ", #w12, ".", b14, CR, LF ) ; I have no idea why w12 has a hash and b14 doesn't. strangely b14 comes from the first bintoascii line
It seems to work OK: here's a photo:
(The battery holder is for an N battery, with three LR44 batteries and a dummy battery made from a sawn-off copper nail glued inside a cardboard tube). The intention is to squeeze it into a small footprint.
It shows a negative signed number if put in the freezer. It seems fairly accurate - within 1/10 of a degree of our central heating thermostat. I've attached the code in case it's of any use to anyone. Next steps - to provide for rounding up of the digits where required.
Attachments
-
12.1 KB Views: 21