Hi,
I set an Arduino Uno with a BMP 280 sensor to act as a weather station. After a few hours operating smoothly, the BMP280 starts to operate erratically, presenting strange values, and coincidentally always freeze at the same values of temperature (-137.76 .C), altitude (-767.71 m) and pressure (1108.92 hPa). When I restart the board, the operation go back to normal, only to freeze again after a while in an intermittent time interval, anywhere between few minutes to one time a day or a week.
Naturally, I tested some hypothesis, but I was not successful at all:
a) I checked the connections, replaced the breadboard jumper wires, resoldered the PCB pin connector;
b) Checked the voltages (3.3VDC for sensor);
c) I replaced the USB charger, the USB cable and even connected directly to the computer USB port to eliminate voltage fluctuations from the AC power source;
d) Tried both I2C address (0x76 and 0x77);
e) Changed the Arduino Uno board and connected the BMP280 to a Weimos ESP32 dev board;
f) The serial output to the Arduino IDE, a LCD display or remote communication to a Blynk server keep working, only the sensor reading remains at the same values cited above.
So, apparently, the problem is neither software nor the boards because the system is not freezing.
My last attempt will be to solder the sensor to the board instead of using jumpers to eliminate some kind of bad contact, or use some sort of shielding, but frankly, I'm not confident that this will solve anything.
Am I missing something here? Is there any way to test the sensor or debug to find out what happens in this situation? Or I shouldn't even waste time, give up and buy another sensor?
Connections:
VCC = 3.3V
GND = GND
SCL = GPIO22 (for ESP32) / A5 (Arduino)
SDA = GPIO21 (for ESP32) / A4 (Arduino)
CSB = Not used
SDO = Disconnected - (0x76) for LOW level / connected in 3.3V (0x77) for HIGH level
Code:
// Programa : Sensor de temperatura e pressao BMP280
// Autor : Baseado no código de FILIPEFLOP - https://www.filipeflop.com/blog/temperatura-pressao-bmp180-arduino/
#include <Wire.h>
#include <Adafruit_BMP280.h>
#include <Adafruit_Sensor.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(2,3, 4, 5, 6, 7);
Adafruit_BMP280 bmp280;
int mostrador = 0;
void setup()
{
Serial.begin(9600);
lcd.begin(20,4);
if (!bmp280.begin(0x77)) // Conectado em interface I2C, pino SDO em nível alto
{
Serial.println("Sensor nao encontrado !!");
while (1) {}
}
}
void loop()
{
lcd.setCursor(0, 1);
lcd.print("Temp. : ");
Serial.print("Temperatura : ");
if ( bmp280.readTemperature() < 10)
{
lcd.print(" ");
lcd.print(bmp280.readTemperature());
Serial.print(bmp280.readTemperature());
Serial.println(" C");
}
else
{
lcd.print(bmp280.readTemperature(),2);
Serial.print(bmp280.readTemperature(),2);
Serial.println(" C");
}
lcd.print(" ");
lcd.print((char)223);
lcd.print("C ");
if (mostrador == 0)
{
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print("Altit.: ");
Serial.print("Altitude : ");
lcd.print(bmp280.readAltitude());
Serial.print(bmp280.readAltitude());
Serial.println(" m");
lcd.print(" m");
}
if (mostrador == 1)
{
lcd.setCursor(0, 3);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.print("Press.: ");
Serial.print("Pressao : ");
lcd.print(bmp280.readPressure()/100);
Serial.print(bmp280.readPressure()/100);
Serial.println(" hPa");
lcd.print(" hPa");
}
delay(3000);
mostrador = !mostrador;
}