How quickly and without unnecessary chips to bypass the immutability of the address at the sensor HTU21

Greetings to all residents of Habr!

I want to talk about a new and unexpected way of connecting multiple HTU21 sensors on an I2C bus without using additional chips.

This sensor is still popular among all kinds of DIY-masters, and deservedly so: it is more accurate than its predecessor and is small in size (which is convenient for embedding in devices).

Most recently, I, like many users, was puzzled by the inability to change the address of this sensor. Google, of course, issued a bunch of articles about all sorts of multiplexers for the I2C bus from “buy in a well-known Chinese online store” to “make a circuit with your own hands”. Nowhere were there any options without a soldering iron and additional costs. This could not but upset because it was necessary to solve the problem here and now (customers are such customers). I want to talk about an easier and more relaxed, very simple way out of this situation. Intrigued? Then I tell.

Baseline: Arduino mega and 4 HTU21 sensors.

Task: it is necessary to connect all htu sensors via the I2C bus and read the values. Moreover, these sensors are not the only slave devices on this bus (there are also LCD screens and other sensors in the plans).

What do we know? The sensor HTU21 fixed address on the bus - 0x40 1 . How, having a microcontroller and 4 sensors with the same addresses on the bus, can I access a specific device without unnecessary microcircuits?

Everything turns out to be quite simple:

  1. connect the ground, scl and sda as usual (do not forget about the pull-up resistors for the data line and synchronization);
  2. We connect the power cable of each sensor to the digital input on the Arduino (you probably already understood where I am)
  3. alternately, we apply HIGH to each digital input supplying a separate sensor and, after a delay, read the value from the powered sensor.
  4. send a LOW signal for this sensor and repeat the cycle for other sensors.

Of course, in this method there are also disadvantages, for example, the required number of free digital or analog outputs may simply be absent. But for use in projects, this principle works, and works at sufficient distances from the microcontroller. I hope this article will help you save your nerves, money and time.

No wonder it says that all ingenious is simple!

Listing attached:

/* функция, считывающая значение температуры
и влажности с датчиков HTU21 и датчика BME280 */voidgreenhouseHT()
    rooms[3].TempA = bme.readTemperature();
    rooms[3].HumA = bme.readHumidity(); 
  for (int i=0; i<3; i++)
    digitalWrite(HTU21_pins[i], HIGH);
    rooms[i].HumA   = myGreenhouseHumidity.readHumidity(); 
    rooms[i].TempA  = myGreenhouseHumidity.readTemperature(); 
    digitalWrite(HTU21_pins[i], LOW);
  digitalWrite(pin_HTU21_1, HIGH);

Also popular now: