Greetings to all residents of Habr!
I want to talk about a new and unexpected way of connecting several HTU21 sensors on an I2C bus without using additional chips.
This sensor is still popular among various DIY craftsmen, and deservedly so: it is more accurate than its predecessor and is small in size (which is convenient for embedding into 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 was the option 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 HTU21 sensor has a 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:
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 everything ingenious is simple!
Listing attached:
/* , HTU21 BME280 */ void greenhouseHT() { delay(30); rooms[3].TempA = bme.readTemperature(); delay(30); rooms[3].HumA = bme.readHumidity(); delay(30); for (int i=0; i<3; i++) { digitalWrite(HTU21_pins[i], HIGH); delay(30); rooms[i].HumA = myGreenhouseHumidity.readHumidity(); rooms[i].TempA = myGreenhouseHumidity.readTemperature(); delay(30); digitalWrite(HTU21_pins[i], LOW); delay(30); } digitalWrite(pin_HTU21_1, HIGH); }
Source: https://habr.com/ru/post/425541/
All Articles