Getting Temperature/Humidity/Ambient Light data with Python
#1
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...  Smile

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$
  Reply


Messages In This Thread
Getting Temperature/Humidity/Ambient Light data with Python - by Yomet - 09-28-2016, 03:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Examples of I2c in Python blanius 8 15,674 10-02-2017, 08:28 PM
Last Post: tllim
  Humidity sensor and temperature under Android dhewko 0 2,996 03-11-2017, 10:18 AM
Last Post: dhewko
  3g/4glte data connection? mightygrom 2 4,098 08-10-2016, 12:17 PM
Last Post: ipsw

Forum Jump:


Users browsing this thread: 2 Guest(s)