m4rtin
August 9, 2022, 1:53pm
1
Hallo,
I can't connect to my BMP280, I ran the sample code:
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10
Adafruit_BMP280 bme; // I2C
//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
void setup() {
Serial.begin(9600);
Serial.println(F("BMP280 test"));
if (!bme.begin()) {
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1);
}
}
void loop() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure());
Serial.println(" Pa");
Serial.print("Approx altitude = ");
Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcase
Serial.println(" m");
Serial.println();
delay(2000);
}
and got this error:
Could not find a valid BMP280 sensor, check wiring!
--------------- CUT HERE FOR EXCEPTION DECODER ---------------
Soft WDT reset
>>>stack>>>
ctx: cont
sp: 3ffffdf0 end: 3fffffc0 offset: 01a0
3fffff90: 3fffdad0 00000000 3ffee6fc 40201068
3fffffa0: feefeffe feefeffe 3ffee750 40203304
3fffffb0: feefeffe feefeffe 3ffe85e0 40100e21
<<<stack<<<
My BMP280 is a GY-BME/P 280 with 6 PINs. The ESP8266 is a NodeMCU ESP8266 board.
I connected
VCC -> 3V3
GND -> GND
D1 -> SCL
D2 -> SDA
Do you know what's wrong?
pylon
August 9, 2022, 4:19pm
2
Change the line
m4rtin:
if (!bme.begin()) {
to
if (!bme.begin(0x76)) {
You're using the Adafruit BMP280 library but you're not using a sensor board from Adafruit. Their circuit pulls SD0 HIGH resulting in an I2C address of 0x77. You're board pulls that signal LOW, so the address is 0x76 which you have to tell to the library.
m4rtin
August 9, 2022, 5:21pm
3
That looks better, now the output is
Temperature = 27.16 *C
Pressure = 67836.06 Pa
Approx altitude = 3258.85 m
but that's not quite right, the temperature is about 25°C and altitude about sea level.
m4rtin
August 9, 2022, 5:31pm
4
I now tested all three bmp280s I have got (I want to use 2 of them on the esp8266 later).
The first shows:
Temperature = 31.50 *C
Pressure = 102811.74 Pa
Approx altitude = -123.05 m
second:
Temperature = 31.36 *C
Pressure = 102902.24 Pa
Approx altitude = -130.50 m
third:
Temperature = 32.53 *C
Pressure = 102409.08 Pa
Approx altitude = -89.87 m
right would still be 25°C and about see level
pylon
August 9, 2022, 6:55pm
5
The sensor cannot detect the actual altitude it can only detect altitude differences. You defined the current altitude at sea level in your sketch:
Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcase
If that's wrong the sensor will give you a wrong altitude of course.
The temperature is in a range where I would guess that it got some hot air from your PC or you touched the sensor which also warms it up.