El escáner de ESP32 encuentra mis sensores en GPIO32/33, las bibliotecas no
Traducido del English por IA ·
Placa propia para un registrador de un armario de iluminación: ESP32-WROOM-32, transceptor RS-485 en GPIO21/22 (la placa se diseñó antes de que añadiera sensores, no preguntes), así que los sensores I2C tienen que ir en GPIO32 (SDA) y GPIO33 (SCL). Los sensores son un SHT40 en 0x44 y un INA219 en 0x40 para la corriente de la alimentación de 24 V del armario. Todo informa a Hermetry por MQTT.Aquí está lo confuso: el boceto de escaneo I2C, con Wire.begin(32, 33), encuentra ambas direcciones siempre. Mi boceto real hace esto:
Wire.begin(32, 33);
if (!sht4.begin()) Serial.println("SHT40 not found");
if (!ina219.begin()) Serial.println("INA219 not found");
e imprime las dos líneas de «not found». Misma placa, mismo cableado, con un minuto de diferencia. Además, el lado RS-485 deja de funcionar en cuanto se ejecutan estas líneas, lo cual no tiene sentido para mí.
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.
Traducido del English por IA ·
¿No está el I2C fijado a los pines 21 y 22 del ESP32? Pensaba que esos eran los pines I2C.
Isn’t I2C fixed to 21 and 22 on the ESP32? I thought those were the I2C pins.
Traducido del English por IA ·
Sigo el hilo: tengo la misma placa que llega la próxima semana.
Following, I have the same board coming next week.
Traducido del English por IA ·
No está resuelto: el ESP32 puede enrutar I2C a casi cualquier pin mediante su matriz GPIO. Que el escáner funcione demuestra que su cableado está bien.Lo que ocurre es que sht4.begin() e ina219.begin() sin argumentos llaman de nuevo a Wire.begin() dentro de la biblioteca, y un Wire.begin() sin parámetros devuelve el bus a los pines predeterminados 21 y 22. Así, I2C se aleja de sus sensores y pasa a su transceptor RS-485, lo que también explica el segundo síntoma.Pase a las bibliotecas el bus que ya inició:
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");
La mayoría de las bibliotecas de Adafruit aceptan un TwoWire*. Si alguna no lo acepta, use Wire1 para los sensores y deje Wire como está.Sobre la elección de pines: los pines 34 a 39 son solo de entrada, así que nunca los use para SDA o SCL. Y evite los pines de strapping 0, 2, 12 y 15 si puede; una resistencia pull-up en el 12 puede impedir que la placa arranque.
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.
Traducido del English por IA ·
No sabía que de la 34 a la 39 son solo de entrada, lo anoto.
Didn’t know about 34 to 39 being input only, noted.
Traducido del English por IA ·
La misma trampa con una biblioteca de pantalla el año pasado: reinicializó el bus a nuestras espaldas.
Same trap with a display library last year, it re-initialised the bus behind our back.
Traducido del English por IA ·
Eso era exactamente. Pasar &Wire a ambos arregló los sensores, y el lado RS-485 vuelve a funcionar porque 21/22 no se tocan. La corriente y la temperatura del armario ya están en el panel. Por si alguien tiene la biblioteca INA219 que tengo yo: su begin() recibe el puntero, pero las versiones antiguas no, así que actualícela primero.
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.
- Debes estar registrado para responder a este debate.
Únete a la conversación
Inicia sesión para preguntar y responder, dar me gusta a las publicaciones útiles y marcar la respuesta que resolvió tu problema. Cada aportación suma puntos y niveles.

