HTU21D answers the scan but every humidity read comes back empty
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
pull-ups? I had flaky reads until I added 4.7k
4.7k on the breakout already, and the scanner never misses, so I doubt wiring.
Had the same with a BME280 and it was the address, 0x76 vs 0x77.
Is the breakout 3.3V? Sorry if obvious, I fried one on 5V last month.
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.
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.
- You must be logged in to reply to this topic.
Join the conversation
Sign in to ask and answer, like helpful posts and mark the reply that solved your problem. Every contribution earns points and levels.

