I have the HDC1080 temperature and humidity sensor connected to a raspberry pi 3 via 3.3v, GND, SDA and SCL. I am trying to get a temperature reading using C and the wiringPi library. I keep reading '-1' from the 0x00 register.
This is my code:
#include <stdio.h> #include <wiringPi.h> #include <wiringPiI2C.h> int main() { int fd, temp; unsigned int a = 15; delay(a); fd = wiringPiI2Csetup(0x40); /*intializing i2c system*/ delay(a); wiringPiI2CWrite(fd, 0x80); /* sending slave byte for writing*/ delay(a); wiringPiI2CWriteReg16(fd, 0x02, 0x00); /*configuring measurement*/ delay(a); wiringPiI2CWrite(fd, 0x80); delay(a); wiringPiI2CWrite(fd, 0x00); /*triggering measurement*/ delay(a); /* waiting for measurement*/ wiringPiI2CWrite(fd, 0x81); /*sending slave byte for reading */ delay(a); temp = wiringPiI2CReadReg16(fd,0x00); /*reading temperature*/ delay(a); temp = (((temp)/(2^16))*165)-40; /*converting reading to degrees celsius*/ printf("%d", temp); }