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);
}