ESP32 scanner finds my sensors on GPIO32/33, the libraries do not
Custom board for a lighting cabinet logger: ESP32-WROOM-32, RS-485 transceiver on GPIO21/22 (the board was laid out before I added sensors, don’t ask), so the I2C sensors have to live on GPIO32 (SDA) and GPIO33 (SCL). Sensors are an SHT40 at 0x44 and an INA219 at 0x40 for the cabinet’s 24 V supply current. Everything reports to Hermetry over MQTT.
Here’s the confusing bit. The I2C scanner sketch, with Wire.begin(32, 33), finds both addresses every time. My real sketch does this:
Wire.begin(32, 33);
if (!sht4.begin()) Serial.println("SHT40 not found");
if (!ina219.begin()) Serial.println("INA219 not found");
and prints both “not found” lines. Same board, same wiring, a minute apart. Also the RS-485 side stops working once these lines run, which makes no sense to me.
Isn’t I2C fixed to 21 and 22 on the ESP32? I thought those were the I2C pins.
Following, I have the same board coming next week.
Not fixed, the ESP32 can route I2C to almost any pin through its GPIO matrix. The scanner working proves your wiring is fine.
What happens is that sht4.begin() and ina219.begin() with no arguments call Wire.begin() again inside the library, and a bare Wire.begin() puts the bus back on the default pins 21 and 22. That moves I2C away from your sensors and onto your RS-485 transceiver, which explains the second symptom too.
Give the libraries the bus you already started:
Wire.begin(32, 33);
Wire.setClock(100000);
if (!sht4.begin(&Wire)) Serial.println("SHT40 not found");
if (!ina219.begin(&Wire)) Serial.println("INA219 not found");
Most of the Adafruit libraries take a TwoWire*. If one does not, use Wire1 for the sensors and leave Wire alone.
On pin choice: 34 to 39 are input only, so never SDA or SCL. And stay off the strapping pins 0, 2, 12 and 15 if you can, a pull-up on 12 can stop the board from booting.
Didn’t know about 34 to 39 being input only, noted.
Same trap with a display library last year, it re-initialised the bus behind our back.
That was exactly it. Passing &Wire to both fixed the sensors, and the RS-485 side works again because 21/22 are left alone. Cabinet current and temperature are on the dashboard now. In case someone has the INA219 library I have: its begin() takes the pointer, but older versions did not, so update it first.
- Bu konuyu yanıtlamak için giriş yapmış olmalısınız.
Sohbete katılın
Soru sormak ve yanıtlamak, yararlı gönderileri beğenmek ve sorununuzu çözen yanıtı işaretlemek için oturum açın. Her katkı puan ve seviye kazandırır.

