readtemp dont work "DS18S20 to DS1820"

Armagon

Member
readtemp dont work "DS18S20 to DS1820"

I have a problem, I can not find sensor DS18B20, I only found the older version DS1820, so can someone told me what will I have to change on the program (command readtem or any similar command) to use property this sensor
________
Chrysler D platform history
 
Last edited:

Technical

Technical Support
Staff member
You cannot use this old sensor with readtemp command as it uses a different protocol to the DS18B20.
 

pha555

Senior Member
Here is some code I posted on the Yahoo group last Dec. I did not test it, but the other party did indicate it worked.

Note that you can only get 0.5 degrees C resolution with the DS18S20.

' For DS18S20, P H Anderson, Dec 26, '05

Symbol TReading = W0
Symbol Whole = B2
Symbol Fract = B3
Symbol SignBit = B4
Symbol Dig = B5
Symbol TempC_10 = W4

Top:
ReadTemp12 6,TReading

SignBit = TReading / 256 / 128
If SignBit = 0 Then Positive
' its negative
TReading = TReading ^ $ffff + 1

Positive:

TempC_10 = TReading * 5 ' TC = value * 0.5

GoSub DisplayTemp

Wait 1
GoTo Top


DisplayTemp:

Whole = TempC_10 / 10
Fract = TempC_10 % 10
If SignBit = 0 Then DisplayTemp_1
SerTxD ("-")

DisplayTemp_1:

SerTxD (#Whole, ".")
' be sure the fractional is two digits
Dig = Fract / 10
SerTxD (#Dig)
Dig = Fract % 10
SerTxD (#Dig, 13, 10)

Return

********

Peter H Anderson
 

Armagon

Member
Sir:

Thanks for your help, but I’m a beginner in this matter, we use a wizard into Editor software to use the data logger that we build, but how we have to change the program, see one example modify by me, how we can display the temperature from DS1820 on the line 254,200,"In7=",#data7," ")

'AXE110 PICAXE-18X - New Datalogger Mission Program
'Automatically generated by Wizard

'LED will flash green as readings are taken.

'Data can be retrieved after mission (LED red) by Datalink tool (F9).
'Use Datalink options: Baud rate - 4800, Sensors - 4, Send G - Enabled

' *******************
' ***** Options *****
' *******************

'Title - Proto
'Date - 09/11/2006
'Time - 12:30:16 p.m.

'Options Selected
'Sensors:
'Sensor 0 - Light
'Sensor 1 - Sensor 1
'Sensor 2 - Sensor 2
'Sensor 7 - Temperature

'Memory:
'No of readings = 100
'1 x 24LC256

'Outputs:
'Bi-colour LED
'SPE002 Piezo sounder
'AXE033 Serial LCD

'Logging Period:
'DS1307 RTC
'Hours: 0 Mins: 0 Secs: 5

' ********************
' ***** Symbols *****
' ********************

'Symbol definitions
symbol data0 = b0
symbol data1 = b1
symbol data2 = b2
symbol data7 = b3
symbol top_address = w2 '(b4 + b5)
symbol address = w3 '(b6 + b7)
symbol temp_word = w4 '(b8 + b9)
symbol temp_byte = b10
symbol hours = b11
symbol mins = b12
symbol secs = b13
symbol day = b0
symbol month = b1
symbol COM = 44 'comma
symbol RET = 13 'carriage return
symbol LFEED = 10 'line feed

'Preload sensor names and title into data memory
EEPROM 0,(0,0)
EEPROM 16,("Light")
EEPROM 32,("Sensor 1")
EEPROM 48,("Sensor 2")
EEPROM 64,("Temperature")
EEPROM 80,("Proto")


' ***************************
' ***** Initialisation *****
' ***************************

init:
serout 6,N2400,(254,1) 'clear LCD
pause 30

high 5 ' write protect eeprom
'reload the last address from data memory
read 0,b6
read 1,b7


' *********************************
' ***** Main loop - read data *****
' *********************************

'Now read each sensor
main:
high 3 ' flash LED

readadc 0,data0
readadc 1,data1
readadc 2,data2
readtemp 7,data7

low 3 ' end of flash LED

sound 0,(50,50) ' make a piezo beep

' *********************************
' ***** Display values on LCD *****
' *********************************

serout 6,N2400,(254,128,"In0=",#data0," ")
serout 6,N2400,(254,136,"In2=",#data2," ")
serout 6,N2400,(254,192,"In1=",#data1," ")
serout 6,N2400,(254,200,"In7=",#data7," ")
serout 6,N2400,(254,144,"LOG=",#address,"/100 ")
let w5 = address * 100 / 100
serout 6,N2400,(254,208,"PROGRAM=",#w5,"% ")


' *****************************
' ***** Now Save the Data *****
' *****************************

'Now save the data
save_data:
low 5 ' write enable eeprom

'Single 24LC256. Input0 from address 0, input1 from address 4096
'Single 24LC256. Input2 from address 8192, input7 from address 12288

if address > 4095 then memory_full
i2cslave %10100000, i2cslow, i2cword
writei2c address,(data0)
pause 10
readi2c address,(temp_byte)
if temp_byte <> data0 then ee_error

temp_word = address + 4096 writei2c temp_word,(data1)
pause 10
readi2c temp_word,(temp_byte)
if temp_byte <> data1 then ee_error

temp_word = address + 8192 writei2c temp_word,(data2)
pause 10
readi2c temp_word,(temp_byte)
if temp_byte <> data2 then ee_error

temp_word = address + 12288 writei2c temp_word,(data7)
pause 10
readi2c temp_word,(temp_byte)
if temp_byte <> data7 then ee_error

'increment address and save in data memory
inc_address:
high 5 ' write protect eeprom

let address = address + 1
write 0,b6
write 1,b7
if address > 100 then memory_full


' ***********************
' ***** Time Delays *****
' ***********************

'Now do time delay
'Read time now
read_rtc_now:
i2cslave %11010000, i2cslow, i2cbyte
readi2c 0,(secs,mins,hours)

'Convert to decimal then add offset
gosub bcd_decimal

let data0 = secs
let data1 = mins
let data2 = hours

Add_Secs:
let data0 = data0 + 5
if data0 < 60 then Add_Mins
'Secs is now greater than 60 so add 1 to minute instead
let data0 = data0 - 60
let data1 = data1 + 1

Add_Mins:
let data1 = data1 + 0
if data1 < 60 then Add_Hours
'Mins is now greater than 60 so add 1 to hour instead
let data1 = data1 - 60
let data2 = data2 + 1

Add_Hours:
let data2 = data2 + 0
if data2 < 24 then read_rtc
'Hours is now greater than 24 so correct
let data2 = data2 - 24

'Read rtc to test alarm'
read_rtc:
i2cslave %11010000, i2cslow, i2cbyte
readi2c 0,(secs,mins,hours)

gosub bcd_decimal

if secs <> data0 then read_rtc
if mins <> data1 then read_rtc
if hours <> data2 then read_rtc

'now do next reading
goto main


' *************************
' ***** Error Routine *****
' *************************

'Memory error - flash LED red/green'
ee_error:
high 2
low 3
pause 500
low 2
high 3
pause 500
goto ee_error

' ***********************
' ***** Memory Full *****
' ***********************

'Memory is full - LED red'
memory_full:
high 2

' ****************************
' ***** Datalink Routine *****
' ****************************

'Datalink routine to transmit data
read_init:
high 5 ' write protect eeprom
let address = 0

'Get top address from data memory (w2=b4+b5)

read 0,b4
read 1,b5

'Wait for G character sent from software
serin 6, N4800, ("G") 'Wait for GO signal

'Transmit the titles
serout 7,N4800,("Address",COM,"Light",COM,"Sensor 1",COM,"Sensor 2",COM,"Temperature",COM,"Proto",RET,LFEED)

'Now read the data
read_data:
'Single 24LC256. Input0 from address 0, input1 from address 4096
'Single 24LC256. Input2 from address 8192, input7 from address 12288

if address > 4095 then all_done
i2cslave %10100000, i2cslow, i2cword
readi2c address,(data0)

temp_word = address + 4096
readi2c temp_word,(data1)

temp_word = address + 8192
readi2c temp_word,(data2)

temp_word = address + 12288
readi2c temp_word,(data7)

'transmit data
tx_data:
serout 7,N4800,(#address,COM,#data0,COM,#data1,COM,#data2,COM,#data7,RET,LFEED)

let address = address + 1
if address = top_address then all_done
goto read_data

'finished so send NULL
all_done:
serout 7,N4800,(0)
goto read_init


' **********************************
' ***** Convert BCD to decimal *****
' **********************************

'Convert BCD to decimal
bcd_decimal:
let temp_byte = secs & %11110000 / 16 * 10
let secs = secs & %00001111 + temp_byte
let temp_byte = mins & %11110000 / 16 * 10
let mins = mins & %00001111 + temp_byte
let temp_byte = hours & %11110000 / 16 * 10
let hours = hours & %00001111 + temp_byte
return
 

BeanieBots

Moderator
PICAXE officially only supports DS18B20
Peter H Anderson's code is for DS18S20.
If you have the DS1820, then you're probably out of luck.
 

Technical

Technical Support
Staff member
As you say you are a beginner, you really would be better off buying a DS18B20 instead. They are readily available, including from the TechSupplies shop link on this website.
 
Top