I'm trying to get an Adafruit HDC1008 Temperature and Humidity breakout working on the Raspberry Pi. I have had some success using the 'raw' code shown at the bottom of the Interfacing HDC1008 Temperature/Humidity thread from Raspberry Pi Dot Org but would like to get the smbus version working.
Currently my code looks like:
bus = smbus.SMBus(1)
ADDR = 0x40
myBytes = [0x10,0x00]
bus.write_i2c_block_data(ADDR,0x02,myBytes)
tempRaw = bus.read_i2c_block_data(ADDR,0x00)
print(tempRaw)
However this is resulting in an IOError with the read block line. Having looked at the HDC1008 datasheet page 12 suggests that I should set the address pointer and then read:
- Trigger the measurement by executing a pointer write transaction. Refer to Figure 12. – Set the address pointer to 0x00 for a temperature measurement. – Set the address pointer to 0x01 for a humidity measurement.
- Wait for the measurement to complete, based on the conversion time ...
- Read the output data: Retrieve the completed measurement result from register address 0x00 or 0x01, as appropriate ...
So my question is: Does the read_i2c_block set the address for me? Or if not how do I set the address before reading.
Thanks
**** UPDATE ****
So I'm pass the IOError by setting the address but don't appear to be reading the data correctly. Whether this is because I'm not setting the address correctly or not reading it I don't know. I'm still looking at this.
#!/usr/bin/python
import time
import smbus
bus = smbus.SMBus(1)
HDC1008_ADDR = 0x40
#Set configuration with two bytes written to 0x02
myBytes = [0x10, 0x00]
bus.write_i2c_block_data(HDC1008_ADDR,0x02,myBytes)
time.sleep(0.0635)
#Set Pointer to 0x00 and sleep
bus.write_byte(HDC1008_ADDR,0x00)
time.sleep(0.0635)
#Read temp as two bytes from 0x00
data = bus.read_byte_data(HDC1008_ADDR,2)
print(data)