I am trying to interface HDC1008 with imp002. For making a reading , I have to write 0x0000 at the address 0x02 and then read the humidity from address 0x01. While it works on Arduino and WICED, it throws an I2C read error -6 with imp. Any suggestions on how to resolve this error will be helpful! I have added the code and datasheet.
`
//initialize I2C
hardware.i2c12.configure(CLOCK_SPEED_100_KHZ);
//read humidity sensor
function read_humidity()
{
local bytes=hardware.i2c12.read(0x82, “\x01”, 2);
local z=hardware.i2c12.readerror();
server.log(z); //prints -6 on running this code
server.log(bytes);
if (typeof(bytes)!= “string”)
{ //server.log("i2c read error: "+bytes);
return;
}
local data_low = bytes[0];
data_low = data_low << 8;
local data_high = bytes[1];
local humidity= data_low+data_high;
humidity=humidity/65536;
server.log("Humidity:"+humidity);
return humidity;
}
//initialize humidity sensor
function humidity_init()
{
local y;
From what I have understood while debugging, the 16 bit write operation is not happening properly. This operation configures the chip for the subsequent read operation.
I think it depends on how he has it the chip’s two address select pins wired up, @hvacspei, but changing the address to 0x80 is certainly something to try, I’d say.