I have an Si7012 temperature / humidity sensor attached to the i2c pins on my Raspberry Pi. Specifically, I have the Adafruit "break-out" with this sensor attached https://www.adafruit.com/product/3251. The break-out board adds some power regulation, but should have the same i2c interface.
I'm attempting to read the data. I prefer something other than Python, but I'm working with it for now. The temperature and humidity data each come back as two bytes. I've found multiple examples that suggest that the can be read by successive calls to
read_byte from the
smbus package. But when I do this sequence:
import smbus bus = smbus.SMBus(1) bus.write(0x40, 0xF3) print bus.read_byte(0x40) print bus.read_byte(0x40)
I get 103 printed twice. In the example, 0x40 is the correct address for the sensor on i2c and 0xF3 is the command for "no hold" measurement of temperature. If I blindly apply the specified function for converting the two bytes to a temperature (even though I don't believe they are both right), I get approximately 75 deg F. That's about right, suggesting that maybe I'm getting the more significant byte correctly.
If I do the corresponding thing for humidity (0xF5), then I get 126 printed twice. That coverts - applying the specified formula blindly - to a humidity in the right ballpark.
It seems unlikely that both bytes should be the same on both measurements, so I suspect that I'm not actually getting the second byte like I want, despite the online examples that I've found. Documentation for
smbus that I've found so far has been too terse for me to get much insight.
Here's a third-party example showing similar code for this sensor: http://www.instructables.com/id/Build-a-Hygrometer-at-Home-Using-Raspberry-Pi-and-/
Is there some different API call that I should use here, either instead of or in addition to what I'm doing to get two bytes via i2c? A reference to good documentation on
smbus would help.
After further reading, I eventually found it confirmed that the above does read the most significant bit twice. That explains why I see what I see, but it does not give any hints how to fix the problem.