This DEMO reads the temerature from a DS18B20, then outputs the data to the serial terminal available in the PICAXE Editor V6, via the programming cable connected the the PICAXE 08M2.
Photos
Figure
159
PICAXE-08M2 Read Temperature from DS18B20 breadbosrd wiring
Figure
160
PICAXE-08M2 Read Temperature from DS18B20 serial output to terminal in PE6
Photo is for illustrative purposes only. Please refer to the description.
Code Sample
To copy code: Hover over the right top corner of the code panel. Click COPY button, the code will be COPIED to the clipboard.
' /***********************************************/
' /* Read Temperature from DS18B20 - (08M2 chip) */
' /* radiosparks - rhb.20231202 */
'/***********************************************/
#PICAXE 08M2
#Terminal 4800 ; start t erminal as needed
' /**********************/
' /* PORT/PIN */
'/**********************/
Symbol OneWirePORT = C.4
' /**********************/
' /* Register Variables */
'/**********************/
Symbol TemperatureBYTE = b1
INITcode:
pause 3000 ; Delay to allow terminal to startup
Sertxd ( "Program Start: READY", CR, LF )
Main:
readtemp OneWirePORT, TemperatureBYTE ; read value into b1 (TEMPdata)
pause 800
Sertxd("Termperature: ")
if Temperatu reBYTE > 127 then ; test for negative
TemperatureBYTE = TemperatureBYTE - 128 ; adjust neg value
Sertxd("-")
else
Sertxd("+")
end if
Sertxd(#TemperatureBYTE, " C", CR, LF )
pause 200
goto Main