Trying to read and convert an NTC 10k B=3950 sensor with an AD/DA PCF8591 converter using Raspberry PI using python. The wiring as it shown in this picture (except the AD converter, couldn't find one for my PCF8591) : wiring
Using the following python code :
[12:45:03] openhabian@openHABianPi:~$ cat read_pcf8591.py
#!/usr/bin/env python
import math
from smbus import SMBus
bus = SMBus(1)
print("Read the A/D")
print("Control C to stop")
bus.write_byte(0x48, 0) #set control register to channel
last_reading =-1
while(0 == 0):
reading = bus.read_byte(0x48)
if(abs(last_reading - reading) >2):
milivolts = reading*(3300/1024)
degC = (milivolts - 500) / 10
print("Temp: " + str(degC) + " Reading : " + str(reading) + " milivolts: " + str(milivolts))
last_reading = reading
This giving me the following results (I'm heating the sensor with my hand) :
[12:43:23] openhabian@openHABianPi:~$ ./read_pcf8591.py
Read the A/D
Control C to stop
Temp: -10 Reading : 134 milivolts: 402
Temp: -9 Reading : 137 milivolts: 411
Temp: -10 Reading : 134 milivolts: 402
Temp: -11 Reading : 131 milivolts: 393
Temp: -12 Reading : 128 milivolts: 384
Apparently the converting to Celsius is wrong, how I can convert properly to Celsius ? Have read about Steinhart-Hart formula, but have no idea (also my knowledge is limited, I'm a beginner) how to use ... Also some docs are pointing to calibration, again no clue about ... Would be very appreciated if someone can help me or point to a right direction.
Thanks! Best regards,