FAQ
TL;DR: DHT12 returns NaN because BMP280_DEV switches the I2C bus from 100 kHz to 400 kHz; as one expert notes, the DHT12/RTClib "must be 100000". Fix by setting 100 kHz after bmp280.begin, then dht12.begin. [Elektroda, khoam, post #18538714]
Why it matters: For ESP32 users combining DHT12, BMP280, and RTClib on one I2C bus, this eliminates NaN readings and boot-time conflicts.
Quick Facts
- ESP32 DevKit V1 default I2C pins: SDA=21, SCL=22; bmp280.begin() already performs Wire.begin, so duplicating it is unnecessary. [Elektroda, khoam, post #18538400]
- I2C addresses: DHT12 default 0x5C; BMP280 selectable 0x77 or 0x76. [Elektroda, Askabius, post #18538340]
- BMP280_DEV defaults to 400 kHz; DHT12/RTClib assume 100 kHz, which can cause DHT12 NaN readings. [Elektroda, khoam, post #18538714]
- Working fix: call bmp280.begin(address), then bmp280.setClock(100000), then dht12.begin(). [Elektroda, khoam, post #18538649]
- After initializing slower devices, you can restore 400 kHz with Wire.setClock(400000). [Elektroda, khoam, post #18538770]
How do I fix the DHT12 and BMP280 I2C conflict on ESP32?
Match I2C speed to the slowest device during init. Initialize BMP280 first, then lower the I2C clock, then start DHT12. This prevents DHT12 from returning NaN. How-To: 1. bmp280.begin(0x77 or 0x76). 2. bmp280.setClock(100000). 3. dht12.begin(). [Elektroda, khoam, post #18538649]
Why does DHT12 show NaN after calling bmp280.begin()?
BMP280_DEV sets the I2C clock to 400 kHz by default. DHT12 and RTClib assume 100 kHz and fail at 400 kHz, causing NaN. As noted, they "must be 100000" during operation. Lower the speed after bmp280.begin, then start DHT12. [Elektroda, khoam, post #18538714]
Do I need to pass the Wire instance or address to DHT12?
Yes. Use DHT12(&Wire) to ensure all devices share the same I2C bus. If your sensor uses a non-default address, pass DHT12(&Wire, address). This avoids hidden Wire instances that break multi-device operation. [Elektroda, khoam, post #18538400]
Are there I2C address conflicts between DHT12 and BMP280?
No. DHT12 uses 0x5C. BMP280 uses 0x77 or 0x76, depending on the module’s solder bridge or configuration. These addresses do not overlap on the same bus. [Elektroda, Askabius, post #18538340]
Should I call Wire.begin() explicitly on ESP32 DevKit V1?
Not when you use the default pins. bmp280.begin() already performs Wire.begin internally, so an extra Wire.begin(21,22) is redundant. Keep SDA=21 and SCL=22 for simplicity. [Elektroda, khoam, post #18538400]
What I2C speed should I use with DHT12, BMP280, and RTClib?
Use 100 kHz while initializing DHT12 and RTC to ensure stable transfers. After their begin calls, you can restore fast-mode. "It is possible to restore the I2C bus speed to 400000" using Wire.setClock(400000). [Elektroda, khoam, post #18538770]
Do I need startNormalConversion() to get BMP280 readings?
Yes. After bmp280.begin(), set a standby time, then call startNormalConversion(). This starts continuous measurements. Example: setTimeStandby(TIME_STANDBY_1000MS); startNormalConversion(). It complements the speed fix but is not the root cause of NaN. [Elektroda, n6210, post #18538521]
Will BMP280 work at 100 kHz if I lower the I2C speed?
Yes. The BMP280 still reports valid readings at 100 kHz. The user confirmed success after lowering the bus and then starting DHT12. "It works!" [Elektroda, Askabius, post #18538695]
How do I set the BMP280 to address 0x76 instead of 0x77?
Pass the address to bmp280.begin(). Example: bmp280.begin(0x76). The library accepts either 0x77 or 0x76, matching common BMP280 modules. [Elektroda, Askabius, post #18538340]
Can I change ESP32 I2C pins and still use these libraries?
DHT12 and RTClib rely on Wire defaults. If you change SDA/SCL pins, those libraries may fail without modification. Keep defaults or update the libraries to use a passed-in TwoWire instance. [Elektroda, khoam, post #18538770]
Why did some GPIOs go HIGH once at boot when using Blynk?
Blynk.syncAll triggers all BLYNK_WRITE handlers on connect, toggling outputs as if buttons were pressed. The user observed GPIO 13, 23, 2, 12, and 25 going HIGH once. Remove syncAll or guard first-run logic to prevent unintended activation. [Elektroda, Askabius, post #18539333]
Does BMP280_DEV support I2C on ESP32, or only SPI?
It supports both. The library provides I2C examples, and constructing BMP280_DEV without SPI parameters uses I2C. Use begin(), setTimeStandby(), and startNormalConversion() as shown in the example. [Elektroda, Askabius, post #18538554]