Hi everyone,
I am trying to interface TH02 (I2C Temperature and Humidity) Sensor with Netduino3 WiFi.
Link to the Grove I2C Temperature and Humidity Sensor
The Arduino code for this sensor to read temperature and humidity works fine!
Working Code Steps for Arduino:-
- Set TH02 I2C address as 0x40(64)
- Start I2C Transmission
- Select configuration register 0x03
- Select Normal mode enabled, Temperature register 0x11
- Stop I2C transmission
- Start I2C Transmission
- Select data register 0x00
- Stop I2C transmission
- Request 3 bytes of temperature data
Similar things is to be done again to read Humidity sensor but only change is (4th line) i.e. Normal mode enabled, Humidity register is 0x01
Now i am trying to do the same thing using NetDuino but i am getting null data. Hey even changed the i2c clock to 100 and 400 KHz but the result is same and have checked the wiring multiple times!
Netduino code:-
I2CDevice th02Sensor = new I2CDevice(new I2CDevice.Configuration(0x40, 50));
I2CDevice.I2CTransaction[] writeConfig = new I2CDevice.I2CTransaction[2];
// Select configuration register 0x03
byte[] configurationRegister1 = new byte[1] { 0x03 };
writeConfig[0] = I2CDevice.CreateWriteTransaction(configurationRegister1);
// Normal mode enabled, Temperature 0x11
byte[] configurationRegister2 = new byte[1] { 0x11 };
writeConfig[1] = I2CDevice.CreateWriteTransaction(configurationRegister2);
int written = th02Sensor.Execute(writeConfig, TransactionTimeout);
Thread.Sleep(1000);
I2CDevice.I2CTransaction[] reading = new I2CDevice.I2CTransaction[2];
// Select data register
byte[] dataRegister = { 0x00 };
reading[0] = I2CDevice.CreateWriteTransaction(dataRegister);
byte[] temperatureData = new byte[3];
reading[1] = I2CDevice.CreateReadTransaction(temperatureData);
// Read the temperature.
int bytesRead = th02Sensor.Execute(reading, TransactionTimeout);
Debug.Print("Bytes of Data Read:- " + bytesRead);
Debug.Print("Temperature bytes data: " + ByteToHex(temperatureData[0]) + ", " + ByteToHex(temperatureData[1]) + ", " + ByteToHex(temperatureData[2]));