Hello everyone.
I recently bought a weird BMP280 sensor, but I'm having some problems with it. It has 6 pins, while most images I've seen on the internet have 4 only, so I'm now using these 4 pins (VCC, GND, SDA, SCL). There is two more pins labeled CSB and SDO, don't know if I should be using these.
I've also seen that the default I2C address of the BMP sensor is 0x77, and BME is 0x76. My sensor has an address of 0x76, so I tried to use the Adafruit BME280 library but got nan readings, while BMP280 library works just fine.
But after around 5-10 minutes of running (sometimes up to 20), the sensor starts showing very weird values, like 170°C and negative pressures. When I unplug my board from my computer and replug it, the code restarts and the values are fine, but it starts showing these wrong values again after some time. I'm using a NodeMCU.
I've been trying to solve this problem for some days, searching over the internet, I tried many solutions but none of them seem to work. This is my current code in the loop() function:
Serial.println();
Serial.println("Reading from BMP280 Sensor");
Serial.println();
float bmp_temp = bmp.readTemperature();
float pressure = bmp.readPressure() / 100.0F;
float altitude = bmp.readAltitude(SEALEVELPRESSURE_HPA);
if (bmp_temp > 100 || pressure < 0) {
Serial.println("BMP280 ERROR");
Serial.print("Temperature = ");
Serial.println(bmp_temp);
Serial.println();
Serial.print("Pressure = ");
Serial.println(pressure);
Serial.println();
Serial.print("Altitude = ");
Serial.println(altitude);
Serial.println();
Serial.println("Resetting BMP280 sensor...");
Serial.println();
bmp.reset();
delay(1500);
Serial.println("Restarting loop...");
delay(1500);
return;
}
I made this if condition to detect wrong readings and try to reset the sensor, but the bmp.reset() doesn't seem to do anything.
I also saw these functions:
bmp280.initialize();
bmp280.setEnabled(0);
But when compiling the code, I got an error that they don't exist.
This is the current output of the code as I'm posting:
22:01:04.617 -> Reading from BMP280 Sensor
22:01:04.663 ->
22:01:04.663 -> Temperature = 26.49°C
22:01:04.663 -> Pressure = 994.00hPa
22:01:04.710 -> Altitude = 186.34m
22:01:06.621 ->
22:01:06.759 ->
22:01:06.759 -> Reading from BMP280 Sensor
22:01:06.806 ->
22:01:06.806 -> BMP280 ERROR
22:01:06.946 ->
22:01:06.946 -> Temperature = 180.32
22:01:06.946 ->
22:01:06.946 -> Pressure = -135.30
22:01:06.992 ->
22:01:06.992 -> Altitude = nan
22:01:06.992 ->
22:01:06.992 -> Resetting BMP280 sensor...
22:01:07.039 ->
22:01:08.392 -> Restarting loop...
22:01:09.882 ->
22:01:10.024 -> Reading from BMP280 Sensor
22:01:10.072 ->
22:01:10.072 -> BMP280 ERROR
22:01:10.213 ->
22:01:10.213 -> Temperature = 180.32
22:01:10.213 ->
22:01:10.213 -> Pressure = -135.30
22:01:10.259 ->
22:01:10.259 -> Altitude = nan
22:01:10.259 ->
22:01:10.259 -> Resetting BMP280 sensor...
22:01:10.306 ->
22:01:11.662 -> Restarting loop...
22:01:13.154 ->
If this helps, I'm using pins D1 and D2 on my NodeMCU for I2C, and I also have an I2C LCD connected to these same pins on the breadboard.
Any help is appreciated. Thanks in advance!