I want to use several Arduino Modulino Thermo modules in one project and therefore change the default I2C addresses of the sensors. On the internet, I find conflicting info about if this is possible.
According to the datasheet of the HS3003 sensor, this is not possible, but there is a separate application note for the sensor that describes how the address can be changed by entering a "programming mode" and overwriting the address in a certain register. Does anyone know, why there is this conflicting information?
I decided to just test it and ordered a sensor. From the application note, I came up with the following Arduino sketch to change the address:
#include <Wire.h>
#define OLD_ADDR 0x44
#define NEW_ADDR 0x45
void setup() {
// we need to bring the sensor into programming mode in the first 10ms after startup with the command A0|00|00
Wire.beginTransmission(OLD_ADDR);
Wire.write(0xA0);
Wire.write(0x00);
Wire.write(0x00);
uint8_t err = Wire.endTransmission();
Serial.begin(9600);
if (err != 0) {
Serial.println("Error: could not enter programming mode.");
return;
}
// we have to wait until address registers are available (150us according to datasheet)
// wait 1ms just to be sure
delay(1);
Wire.beginTransmission(OLD_ADDR);
Wire.write(0x1C);
Wire.write(0x00);
Wire.write(0x00);
err = Wire.endTransmission();
if (err != 0) {
Serial.println("Error: could not write the register address.");
return;
}
// request content of address register
Wire.requestFrom(OLD_ADDR, 3);
uint8_t s = Wire.read();
uint8_t v_msb = Wire.read();
uint8_t v_lsb = Wire.read();
if (s != 0x81) {
Serial.println("Error: did not receive success from sensor.");
return;
}
// insert new address at bits [6:0]
v_lsb = (v_lsb & uint8_t(0x80)) | (uint8_t(NEW_ADDR) & uint8_t(0x7F));
// write back new address
Wire.beginTransmission(OLD_ADDR);
Wire.write(0x5C);
Wire.write(v_msb);
Wire.write(v_lsb);
err = Wire.endTransmission();
if (err != 0) {
Serial.println("Error: could not write the new address.");
return;
}
// wait for 15ms to write data into non volatile memory before doing anything else
delay(15);
}
void loop() {
// nothing to do here
}
I get the error "Error: did not receive success from sensor.", meaning that the sensor answers to the I2C requests, but I do not get the expected data. So either the address cannot be changed, or I messed something up. One concern I have is that the programming mode needs to be entered in the first 10ms after the sensor gets power. How can I ensure this? If I plug in the Arduino, it might be that the sensor gets power, but it takes more than 10ms until the Arduino starts running and sends the necessary I2C requests to enter the mode.
Would be nice, if someone can share their experiences with this module, or an Arduino sketch for changing the address that worked for them. Worst case I will use a multiplexer, but changing the addresses would be cleaner.