Honeywell HIH-6130 Humidity / Temperature Sensor

I have completed an application note with sample Arduino code for the HIH-6130 at;

http://www.phanderson.com/arduino/hih6130.html

This sensor in an 8-pin SOIC package is relatively inexpensive, provides a standard I2C interface and High and Low RH alarms with hysterisis.

If you use it, please give credit.

Peter Anderson

Thanks for sharing,

some improvement ideas:

replace print_float(RH, 1); ==> Serial.print(RH, 1); The print class of the arduino can print floats, it uses a similar algorithm as you wrote

Furthermore I would proprose to wrap the code in a class similar to this lib I wrote - http://arduino.cc/playground/Main/DHTLib - The interfaces can be almost identical. That would encapsulate all the math for calculating the temp & humidity inside the class, making it easier for users to use.

FInally one question: is it possible to change the address of the HIH6130? SO I can use more than one on the I2C bus?

Thank you for sharing code and useful links :)

I actually did, and yes, the I2C address is changeable.

cheers
Josh

20130224-HIH6130_Arduino.zip (3.93 KB)

see also: http://arduino.cc/forum/index.php/topic,149836.0.html and: http://arduino.cc/forum/index.php/topic,150584.0.html

Maybe these 2 libraries could/should be merged?

would be a good idea !

is that right, we're working on the same time on the very same chip? And I've, to admit you did the better Job, went the extra mile to implement all features :)

Just skimming through it - how do you enter the command mode exactly (within that 3/10ms)? Reason why i have a function pointer is that we might want the HIH to be field-programmable. E.g. hook up to the output of a PCF8591 or similar to power-cycle the HIH while being installed.

followup readers: please check http://playground.arduino.cc//Main/HoneywellHumidIconTMDigitalHumidity-TemperatureSensors and http://arduino.cc/forum/index.php/topic,150584.0.html

thanks for your work and cheers

is that right, we're working on the same time on the very same chip?

Apparently so, if I'd have known what you were doing, I wouldn't have started on this....

And I've, to admit you did the better Job, went the extra mile to implement all features smiley

Thanks a lot!

how do you enter the command mode exactly (within that 3/10ms)?

I have been wrestling with command mode for a couple of weeks, because I didn't know the voltage on the 3.3V pin on the arduino isn't cut when you reset the arduino (or isn't cut long enough). But then finally it hit me... So I just put a 3.3V voltage regulator on a digital pin to supply the chip (the datasheet says it can handle 5V, but I didn't want to fry the chip, so...). So: digitalWrite(powerPin, HIGH); enables the chip And: digitalWrite(powerPin, LOW); disables it If you want to cycle the power do something like this:

digitalWrite(powerPin, HIGH);
//  HIH is enabled now, so let's cycle the power:
digitalWrite(powerPin, LOW);
delay(1); // this is the important part: give the chip the time to notice the power has been cut
digitalWrite(powerPin, HIGH);

I hope this answers your question because I've got no idea what a PCF8591 is or what role an A/D convertor could play here.

If you have any improvements to the code or anything... you're always welcome.

maldex:
I actually did, and yes, the I2C address is changeable.

cheers
Josh

I wasn’t able to make your code work very well, but using it I was able to create a working prototype. I used two separate codes, one for changing the address, and one for displaying the temp/humid.

You can run a seemingly infinite number of sensors (though I wouldn’t use more then 10) using this process. Just set the address of each one individually following the instructions on my program and then choose the new address as the "#define"ed address in the display code.

I don’t know how to attach code… sorry… so here’s a copy/paste
*make sure to include the sensor’s library

ADDRESS PROGRAMMING:

/*

  • Set up:
  • Analog 4 ------ SDA (4) ----- I2C Data Line
  • Analog 5 ------ SCL (3) ----- I2C Clock Line
  • GND ----------- Vss (2) ----- Supply Ground
  • CONNECT VDD FROM CHIP TO DIGI 12 ON ARDUINO
  • MAKE SURE ALL GROUNDS ARE CONNECTED
  • How to use:
  • define the address to the new address.
  • manually insert new address l8er in file.
  • default addresses are 0x27
  • Instructional comments can be found in code
  • By Parker Hinton. Free to edit and distribute

*/

#define i2c_address 0x19 // This is the address you’re changing to

#include “HIH6130.h”

HIH6130 hih_normal; // runtime instance, read values
HIH6130_CMDMODE hih_cmdmode; // programming mode instance, change i2c address

void reset_i2c()
{ // we connected Vdd to Arduino digital PIN 12
pinMode(12, OUTPUT);
digitalWrite(12, LOW); // switch off power → reset
delay(666); // let power capacitors run empty
digitalWrite(12, HIGH); // switch power back on, 10ms remaining to enter cmdmode
}

void fetch(byte address)
{
hih_normal.begin(address);
Serial.print(“data from address 0x”);
Serial.println(address,HEX);

float humidity, temperature;

hih_normal.fetch_data(&humidity, &temperature);

Serial.print("Humidity: “);
Serial.print(humidity);
Serial.print(”% Temperature: ");
Serial.print(temperature);
Serial.println(“C”);

delay(500);

}

void reconfigure() // reconfigure I2C address
{

hih_cmdmode.begin(0x27, &reset_i2c); // first in put is old address
hih_cmdmode.write_i2c_address(0x19); // input is new I2c address
hih_cmdmode.end();

reset_i2c(); // let the config settle

}
void setup(void) {
{
Serial.begin(9600);

reset_i2c();

Wire.begin(); // start i2c
delay(500);
}

}

void loop(void) {

fetch(i2c_address);
reconfigure();

delay(1000);

}

-----------------------------------------END CODE-------------------------------------------------------------------

DATA DISPLAY:

/*

  • Wiring UNO HID6130 Description
  • Analog 4 ------ SDA (4) ----- I2C Data Line
  • Analog 5 ------ SCL (3) ----- I2C Clock Line
  • GND ----------- Vss (2) ----- Supply Ground
  • **** Connect VDD from sensor to a 5v power supply
  • Copyright (c) 2016 by Parker Hinton
  • Source code belongs to Josh Geisser <josh_dot_geisser_at_hyperwerk_dot_ch>
  • This file is free software; you can redistribute it and/or modify
  • it under the terms of the GNU General Public License as
  • published by the Free Software Foundation.

*/

#define i2c_address1 0x27
#define i2c_address2 0x18
#define i2c_address3 0x26
#define i2c_address4 0x19

#include “HIH6130.h”

HIH6130 hih_normal; // runtime instance, read values
HIH6130_CMDMODE hih_cmdmode; // programming mode instance, change i2c address

void scan_i2c();

void reset_i2c()
{
}

void fetch(byte address)
{
hih_normal.begin(address);
Serial.print(“data from 0x”);
Serial.println(address,HEX);

for (int i = 0; i < 3; i++)
{
float humidity, temperature;

hih_normal.fetch_data(&humidity, &temperature);

Serial.print("Humidity: “);
Serial.print(humidity);
Serial.print(”% Temperature: ");
Serial.print(temperature);
Serial.println(“C”);

delay(500);
}
}

void setup(void)
{
Serial.begin(9600);

reset_i2c();

Wire.begin(); // start i2c
delay(500);
}

void loop(void)
{

fetch(i2c_address1);

fetch(i2c_address2);

fetch(i2c_address3);

fetch(i2c_address4);

delay(1000);
}

HIH6130 hih_normal; // runtime instance, read values HIH6130_CMDMODE hih_cmdmode; // programming mode instance, change i2c address

gives me error

What library were you using This code doesn't seem to work anymore with the

include "HIH6130.h"

Last error that I got - error compiling for Arduino Micro. (I use Arduino Micro Pro.)

PLEASE HELP!

I downloaded this library. https://code.google.com/archive/p/arduino-hih61xx/downloads

Following this advice: http://playground.arduino.cc/Main/HoneywellHumidIconTMDigitalHumidity-TemperatureSensors

Got this error:

Arduino: 1.6.8 (Windows 8.1), Board: "Arduino/Genuino Micro"


"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10608 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XX" "-IC:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XXCommander" "C:\Users\VTolskiy\AppData\Local\Temp\build2635536b2aed4fd46194f0bc0aa20acb.tmp\sketch\example.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10608 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XX" "-IC:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XXCommander" "C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src\Wire.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10608 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XX" "-IC:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XXCommander" "C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src\utility\twi.c" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10608 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XX" "-IC:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XXCommander" "C:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XX\HIH61XX.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10608 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XX" "-IC:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XXCommander" "C:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XXCommander\HIH61XXCommander.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10608 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XX" "-IC:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XXCommander" "C:\Users\VTolskiy\AppData\Local\Temp\build2635536b2aed4fd46194f0bc0aa20acb.tmp\sketch\example.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10608 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XX" "-IC:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XXCommander" "C:\Users\VTolskiy\AppData\Local\Temp\build2635536b2aed4fd46194f0bc0aa20acb.tmp\sketch\example.ino.cpp" -o "C:\Users\VTolskiy\AppData\Local\Temp\build2635536b2aed4fd46194f0bc0aa20acb.tmp\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino10/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\VTolskiy\AppData\Local\Temp\build2635536b2aed4fd46194f0bc0aa20acb.tmp\preproc\ctags_target_for_gcc_minus_e.cpp"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10608 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR  -DUSB_VID=0x2341 -DUSB_PID=0x8037 '-DUSB_MANUFACTURER="Unknown"' '-DUSB_PRODUCT="Arduino Micro"' "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "-IC:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XX" "-IC:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XXCommander" "C:\Users\VTolskiy\AppData\Local\Temp\build2635536b2aed4fd46194f0bc0aa20acb.tmp\sketch\example.ino.cpp" -o "C:\Users\VTolskiy\AppData\Local\Temp\build2635536b2aed4fd46194f0bc0aa20acb.tmp\sketch\example.ino.cpp.o"
In file included from C:\Users\VTolskiy\Downloads\HIH6130_21.02.2017\HIH-0.2\HIH61XXCommander\example\example.ino:2:0:

C:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XX/HIH61XX.h:44:8: error: 'bool HIH61XX::isRunning() const' cannot be overloaded

  bool isRunning() const { return f & RunningFlag; }

       ^

C:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XX/HIH61XX.h:41:8: error: with 'bool HIH61XX::isRunning() const'

  bool isRunning() const { return f & RunningFlag; }

       ^

Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire 
Using library HIH61XX in folder: C:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XX (legacy)
Using library HIH61XXCommander in folder: C:\Users\VTolskiy\Documents\Arduino\libraries\HIH61XXCommander (legacy)
exit status 1
Error compiling for board Arduino/Genuino Micro.

If you want to use more sensors (say 8)on a I2C bus do you need a 2.2 Kohm resister on every sensor SDA and SCL, or just one time for all? The same question for the capacitor (0.22 muF)on the powerline?

Just one for each line, and place it at the end of the string of devices.

Pull up resistors are there for the I2C bus, not for the chip. So one set for one I2C bus.

Decoupling capacitors are there for the chip. So one on the VCC pin of each chip.

That sensor has one fixed I2C address, meaning only one chip can exist on one I2C bus at the time. How are you going to solve that.

An I2C bus can only do a limited distance (total wire length). What are you planning to do with eight sensors close together. Leo..

thank you very much for your fast answers. The resisters and capacitors are clear. Oh jee, I thought you can change the addresses. I used multiple other sensors on I2C and changed the adresses. If that's not possible perhaps I can try to switch Vdd on and off.

I planned to measure temp and humidity in different strategic places in a compost-heap. And then regulate an oxygenflow (air) and waterflow through the heap.

It seams not so handy to me that I2C sensors dont have a changeble address......

I found this, for pi, Does someone happen to have a code like that for Arduino?

Honeywell HumidIcon Sensor I2C Address Change (HIH6000, HIH7000, HIH8000, HIH9000)

September 2017

By LikesAChallenge & joan & Pelev (https://www.raspberrypi.org/forums/viewtopic.php?f=44&t=138845)

import time import pigpio

CHANGE HERE

OldAddress = 0x27

NewAddress = 0x28

def CheckAddress(): pi.i2c_write_device(sensor_id, [0x1C, 0x00, 0x00]) # Telling the sensore that you wish to read register 0x1C

count, data = pi.i2c_read_device(sensor_id, 3) # Reads 3 bytes from the sensor. (I.e. Previously specified what you want to read, now this is just getting the data)

status=bin(data[0])[2:-6] # Converts dec to binary and shifts to give Sensor Status. 10 = Command Mode diag=bin(data[0])[4:-2] # Converts dec to binary and shifts to give any Diagnostic bits. 0000 = Nothing wrong response=bin(data[0])[8:] # Converts dec to binary and shifts to give the sensors response, 01 = Successful.

print ("ID:",sensor_id,"- Bytes Read:",count,"- Status:",status,"- Diag:",diag,"- Resp:",response,"- Bits 15-8:",bin(data[1])[2:].zfill(8),"- Bits 7-0:",bin(data[2])[2:].zfill(8),"(",hex(data[2]),"-",data[2],")")

pi = pigpio.pi() #Connects to pigpio daemon. if not pi.connected: print("can't connect to pigpiod") exit(0)

sensor_id = pi.i2c_open(1, OldAddress, 0) # Open sensor session using device 0x27.

pi.write(27, 1) # Sets Pi GPIO 27 PWM to high (i.e. 3.3V, 100%)

time.sleep(0.001) # Let Sensor Start up (Max = 3ms!)

pi.i2c_write_device(sensor_id, [0xA0, 0x00, 0x00]) # enter command mode

CheckAddress()

DeltaTime = time.time() # fetches the time for later comparison

pi.i2c_write_device(sensor_id, [0x5C, 0x00, NewAddress]) # write 0x1C - WARNING: Wrong entry leads to sensor failure!!

time.sleep(1) # IMPORTANT!

CheckAddress()

pi.i2c_close(sensor_id) # Close sensor session, otherwise this will increment! pi.write(27, 0) # Sets Pi GPIO 27 to low (i.e. 0V, 0%) DeltaTime = (time.time() - DeltaTime)*1000 # gives the time passed since 'DeltaTime = time.time()' print ("time passed after writing: %.3f ms" %DeltaTime)

pi.stop () #Disconnects from pigpio daemon.

Digging a bit deeper I found some info here on the support tips tab that could possibly change the I2C address. Than you could be still stuck with the 400pF max wire capacitance of a standard I2C bus. Another solution could be an 8-channel I2C muxer (adafruit.com).

Next time read the forum guidelines before posting. So your code appears in a window and doesn't get mangled by the forum software. Leo..