09-28-2016, 03:34 PM
Hi,
I have tried to get data from both the Temp/Humidity and the Ambient Light sensor by using python and python-smbus. I have found and read the tech docs of both adapters as specified by Pine64 but have not gotten all the way to reading the correct data, i.e. I get data from the T/H sensor but it says that it's -5 C inside and I don't believe that since I'm sitting in short-sleeves...
I also found the posts from khgoh (http://forum.pine64.org/showthread.php?tid=231&page=3) and skimmed through the source code for the WifiRemoteI2C server but that is in C (C++) and does not help me at all, or rather, it does not help me solving it in python...
My problem is that the value I get from the T/H sensor does not convert correctly into the ambient temperature and relative humidity.
I would really appreciate if someone told me where I am going wrong and how to correct it.
Many thanks
DS
Source:
Output:
I have tried to get data from both the Temp/Humidity and the Ambient Light sensor by using python and python-smbus. I have found and read the tech docs of both adapters as specified by Pine64 but have not gotten all the way to reading the correct data, i.e. I get data from the T/H sensor but it says that it's -5 C inside and I don't believe that since I'm sitting in short-sleeves...
I also found the posts from khgoh (http://forum.pine64.org/showthread.php?tid=231&page=3) and skimmed through the source code for the WifiRemoteI2C server but that is in C (C++) and does not help me at all, or rather, it does not help me solving it in python...
My problem is that the value I get from the T/H sensor does not convert correctly into the ambient temperature and relative humidity.
I would really appreciate if someone told me where I am going wrong and how to correct it.
Many thanks
DS
Source:
Code:
import smbus
import time
bus = smbus.SMBus(1)
address = 0x40
cmd_temp = 0xE3
cmd_humid = 0xE5
temp = 0L
humid = 0L
temp = bus.read_word_data(address, cmd_humid)
print "RH read_word_data returns ", humid
print ""
humid = 125.0 * humid / 65536 - 6
print "RH: ", humid, " %"
print ""
print ""
temp = bus.read_word_data(address, cmd_temp)
print "Temp read_word_data returns ", temp
print ""
temp = 175.72 * temp / 65536 - 46.85
print "Temperature: ", temp, " C"
print ""
print ""
Output:
Code:
debian@pine64:~/i2c$ python getTemp2.py
RH read_word_data returns 0
RH: -6.0 %
Temp read_word_data returns 10341
Temperature: -19.1229412842 C
debian@pine64:~/i2c$