El HTU21D responde al escaneo pero cada lectura de humedad llega vacía
Traducido del English por IA ·
Es un detalle pequeño, pero me está volviendo loco. Una MKR WiFi 1010 en un refugio de cabezal de pozo lee un breakout de humedad HTU21D en 0x40 y envía los datos a Hermetry cada minuto. La temperatura funciona. La humedad funciona quizá una lectura de cada diez.El escáner I2C encuentra 0x40 siempre. Analizador lógico: mi escritura de 0xF5 (humedad, sin hold) recibe un ACK, luego la dirección de lectura 0x81 recibe un NACK y Wire.requestFrom(0x40, 3) devuelve 0. En el panel, la humedad tiene huecos por todas partes.
Wire.beginTransmission(0x40);
Wire.write(0xF5);
Wire.endTransmission();
delay(15);
uint8_t n = Wire.requestFrom(0x40, 3); // n == 0 most of the time
Small one but it’s driving me nuts. MKR WiFi 1010 in a wellhead shelter reading an HTU21D humidity breakout at 0x40, posting to Hermetry every minute. Temperature works. Humidity works maybe one read in ten.
I2C scanner finds 0x40 every time. Logic analyser: my write of 0xF5 (humidity, no hold) gets an ACK, then the read address 0x81 gets a NACK and Wire.requestFrom(0x40, 3) returns 0. On the dashboard humidity has holes all over it.
Wire.beginTransmission(0x40);
Wire.write(0xF5);
Wire.endTransmission();
delay(15);
uint8_t n = Wire.requestFrom(0x40, 3); // n == 0 most of the time
Traducido del English por IA ·
¿Las resistencias pull-up? Tenía lecturas inestables hasta que añadí 4.7k
pull-ups? I had flaky reads until I added 4.7k
Traducido del English por IA ·
Ya tengo 4,7k en el breakout, y el escáner nunca falla, así que dudo que sea el cableado.
4.7k on the breakout already, and the scanner never misses, so I doubt wiring.
Traducido del English por IA ·
Tuve lo mismo con un BME280 y era la dirección, 0x76 frente a 0x77.
Had the same with a BME280 and it was the address, 0x76 vs 0x77.
Traducido del English por IA ·
¿El breakout está a 3,3 V? Perdona si es obvio, quemé uno con 5 V el mes pasado.
Is the breakout 3.3V? Sorry if obvious, I fried one on 5V last month.
Traducido del English por IA ·
El cableado está bien, tu lectura llega demasiado pronto. En modo no-hold, el HTU21D responde NACK a su dirección de lectura hasta que termina la medición, justo lo que muestra el analizador. Una lectura de humedad de 12 bits tarda hasta unos 16 ms; con la resolución por defecto y un poco de margen, conviene esperar más de 15. La temperatura es la lenta, con 50 ms, y probablemente copiaste el retardo de un ejemplo solo de humedad y tuviste suerte en sentido contrario.Consulto el sensor en lugar de adivinar:
Wire.beginTransmission(0x40);
Wire.write(0xF5);
Wire.endTransmission();
uint8_t n = 0;
for (int i = 0; i < 10 && n < 3; i++) {
delay(10);
n = Wire.requestFrom(0x40, 3);
}
if (n < 3) { /* skip humidity this round */ }
Y cuando una lectura sigue fallando, omite la clave en el mensaje de ese minuto o envía null. No envíes 0: Hermetry lo guarda como un 0 % real y tu regla de alarma se va a aprovechar de ello. null solo significa que no hay lectura.
Wiring is fine, your read is too early. In no-hold mode the HTU21D NACKs its read address until the measurement is done, which is exactly what the analyser shows. A 12-bit humidity reading takes up to about 16 ms, and with the default resolution and some margin you want more than 15. Temperature is the slow one at 50 ms, and you probably copied the delay from a humidity-only example and got lucky the other way round.
I poll instead of guessing:
Wire.beginTransmission(0x40);
Wire.write(0xF5);
Wire.endTransmission();
uint8_t n = 0;
for (int i = 0; i < 10 && n < 3; i++) {
delay(10);
n = Wire.requestFrom(0x40, 3);
}
if (n < 3) { /* skip humidity this round */ }
And when a read still fails, leave the key out of that minute’s message or send null. Don’t send 0, Hermetry stores it as a real 0 % and your alarm rule will love that. null just means no reading.
Traducido del English por IA ·
Bucle de sondeo implementado, n llega a 3 en el segundo o tercer intento, es decir, unos 20-30 ms. Dos días sin huecos. También enviaba 0 en los fallos, lo que explica las extrañas caídas en el gráfico. Gracias Daniel.
Polling loop in, n hits 3 on the second or third try, so about 20-30 ms. Two days without a hole. I was also sending 0 on failures, which explains the weird dips on the chart. Thanks Daniel.
- 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.

