Skip to content

Instantly share code, notes, and snippets.

@jklemmack
Created June 28, 2015 20:45
Show Gist options
  • Save jklemmack/d3c958fbaff5e6c4fd31 to your computer and use it in GitHub Desktop.
Save jklemmack/d3c958fbaff5e6c4fd31 to your computer and use it in GitHub Desktop.
Windows Universal code to read data from HIH6130
private void GetTemperatureAndHumidity(out double RH, out double T_C)
{
RH = 0d;
T_C = 0d;
try
{
byte[] write = new byte[] { (0x27 << 1) | 0x01 };
byte[] read = new byte[4];
// Inspired by http://www.phanderson.com/arduino/hih6130.html
// --------------------------------------------------------------
// copyright, Peter H Anderson, Baltimore, MD, Nov, '11
// You may use it, but please give credit.
// --------------------------------------------------------------
sensor.WriteRead(write, read);
byte Hum_H = read[0], Hum_L = read[1], Temp_H = read[2], Temp_L = read[3];
byte _status = (byte)((Hum_H >> 0x06) & 0x03); // Get top 2 bytes
Hum_H = (byte)(Hum_H & 0x3f); // Get lower 6 bytes
UInt16 H_Dat = (UInt16)((Hum_H << 8) | Hum_L);
UInt16 T_Dat = (UInt16)((Temp_H << 8) | Temp_L);
T_Dat = (UInt16)(T_Dat >> 2);
RH = H_Dat * 6.10e-3;
T_C = T_Dat * 1.007e-2 - 40.0;
}
catch (Exception ex)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment