I'm using BMP280 with ESP32 ,library provided code. The problem is that the serial monitor says can't find the BMP280, check wiring.
code :
#include <Adafruit_BMP280.h>
/***************************************************************************
This is a library for the BMP280 humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BMP280 Breakout
----> http://www.adafruit.com/products/2651
These sensors use I2C or SPI to communicate, 2 or 4 pins are required
to interface.
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
***************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
#define BMP_SCK (13)
#define BMP_MISO (12)
#define BMP_MOSI (11)
#define BMP_CS (10)
Adafruit_BMP280 bmp; // I2C
//Adafruit_BMP280 bmp(BMP_CS); // hardware SPI
//Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
void setup() {
Serial.begin(9600);
while ( !Serial ) delay(100); // wait for native usb
Serial.println(F("BMP280 test"));
unsigned status;
//status = bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID);
status = bmp.begin();
if (!status) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
"try a different address!"));
Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(),16);
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
Serial.print(" ID of 0x60 represents a BME 280.\n");
Serial.print(" ID of 0x61 represents a BME 680.\n");
while (1) delay(10);
}
/* Default settings from datasheet. */
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
}
void loop() {
Serial.print(F("Temperature = "));
Serial.print(bmp.readTemperature());
Serial.println(" *C");
Serial.print(F("Pressure = "));
Serial.print(bmp.readPressure());
Serial.println(" Pa");
Serial.print(F("Approx altitude = "));
Serial.print(bmp.readAltitude(1013.25));
Serial.println(" m");
Serial.println();
delay(2000);
}
Then I tried to find the I2C address of the sensor using below code:
#include <Wire.h> //include Wire.h library
void setup()
{
Wire.begin(); // Wire communication begin
Serial.begin(9600); // The baudrate of Serial monitor is set in 9600
}
void loop()
{
byte error, address; //variable for error and I2C address
int devicecount;
Serial.println("Scanning...");
devicecount = 0;
for (address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address < 16)
Serial.print("0");
Serial.print(address, HEX);
Serial.println(" !");
devicecount++;
}
else if (error == 4)
{
Serial.print("Unknown error at address 0x");
if (address < 16)
Serial.print("0");
Serial.println(address, HEX);
}
}
if (devicecount == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for the next I2C scan
}
But the serial monitor shows "NO I2C DEVICE FOUND"
Breadboards have bad contacts and jumper wires can be broken. When you look at your project, assume that everything is wrong, can check it step by step.
/* Interfacing Arduino with BMP280 temperature and pressure sensor.
* Temperature and pressure values are displayed on 16x2 LCD.
* This is a free software with NO WARRANTY.
* https://simple-circuit.com/
*/
// ESP32 SDA to D21 SCL to D22
// ESP8266 SDA to D2 SCL to D1
#include <Wire.h> // include Wire library, required for I2C devices
#include <Adafruit_Sensor.h> // include Adafruit sensor library
#include <Adafruit_BMP280.h> // include adafruit library for BMP280 sensor
// define device I2C address: 0x76 or 0x77 (0x77 is library default address)
#define BMP280_I2C_ADDRESS 0x76
Adafruit_BMP280 bmp280;
void setup() {
Serial.begin(115200);
Serial.println(F("Arduino + BMP280"));
if (!bmp280.begin(BMP280_I2C_ADDRESS))
{
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1);
}
Serial.println("Found BMP280 sensor!");
}
void loop() {
// get temperature, pressure and altitude from library
float temperature = bmp280.readTemperature(); // get temperature
float pressure = bmp280.readPressure(); // get pressure
float altitude_ = bmp280.readAltitude(1013.25); // get altitude (this should be adjusted to your local forecast)
// print data on the serial monitor software
// 1: print temperature
Serial.print("Temperature = ");
Serial.print(temperature);
Serial.println(" °C");
// 2: print pressure
Serial.print("Pressure = ");
Serial.print(pressure/100);
Serial.println(" hPa");
// 3: print altitude
Serial.print("Approx Altitude = ");
Serial.print(altitude_);
Serial.println(" m");
Serial.println(); // start a new line
delay(2000); // wait 2 seconds
}
a run om a ESP-WROOM-32 gives
18:36:50.779 -> Arduino + BMP280
18:36:50.914 -> Found BMP280 sensor!
18:36:50.914 -> Temperature = 27.56 °C
18:36:50.914 -> Pressure = 1020.95 hPa
18:36:50.914 -> Approx Altitude = -63.93 m
18:36:50.914 ->
18:36:52.917 -> Temperature = 27.59 °C
18:36:52.917 -> Pressure = 1021.01 hPa
18:36:52.917 -> Approx Altitude = -64.39 m
18:36:52.917 ->
18:36:54.919 -> Temperature = 27.28 °C
18:36:54.919 -> Pressure = 1021.02 hPa
18:36:54.919 -> Approx Altitude = -64.50 m
ok, thanks. I'm basically building a spirometer using this sensor. for that I need to remove the atmospheric pressure and just take the pressure applied by the blow. Can u help?
is it an actual, factual BMP280, or is it a BME280?
is it marked BME/BMP280, like all of mine?
have you tried the BME280 library?
I tried that yesterday, and just like that my "BMP280" works. sort of. the temperature seems right. the pressure is way off ( 25.92 inches of mercury ), and it shows my "altitude" ( which is properly elevation when you are on the ground ) as 45,000 meters, but it is no longer inert