WiFi LoRa 32 (V3) and BMP280 Sensor

I’m trying to use BMP280 sensor with the adafruit library and i can’t achieve it.
If i use the I2C Wirescan example adding Wire.begin(41, 42) :
#include “Wire.h”

void setup() {
Serial.begin(115200);
Wire.begin(41, 42);
}

void loop() {
byte error, address;
int nDevices = 0;

delay(5000);

Serial.println(“Scanning for I2C devices …”);
for(address = 0x01; address < 0x7f; address++){
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0){
Serial.printf(“I2C device found at address 0x%02X\n”, address);
nDevices++;
} else if(error != 2){
Serial.printf(“Error %d at address 0x%02X\n”, error, address);
}
}
if (nDevices == 0){
Serial.println(“No I2C devices found”);
}
}

I obtain :

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x9 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x43c
load:0x403c9700,len:0xbec
load:0x403cc700,len:0x2a3c
SHA-256 comparison failed:
Calculated: dcde8d8a4817d9bf5d5d69a7247667264e4e10ac7493514868b61f5aa6146539
Expected: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Attempting to boot anyway…
entry 0x403c98d8
Scanning for I2C devices …
I2C device found at address 0x61
I2C device found at address 0x76

Which is correct because i have connected a scd30 and a BMP280 sensor

Trying to use the bmp280test example i obtain (adding Wire.begin(41, 42) or not ):
/***************************************************************************
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);
Wire.begin(41, 42);
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)); /* Adjusted to local forecast! */
Serial.println(" m");

Serial.println();
delay(2000);

}

Leads to :

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x9 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x43c
load:0x403c9700,len:0xbec
load:0x403cc700,len:0x2a3c
SHA-256 comparison failed:
Calculated: dcde8d8a4817d9bf5d5d69a7247667264e4e10ac7493514868b61f5aa6146539
Expected: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Attempting to boot anyway…
entry 0x403c98d8

If i try the same with the SCD30 :
// Basic demo for readings from Adafruit SCD30
#include <Adafruit_SCD30.h>

Adafruit_SCD30 scd30;

void setup(void) {
Serial.begin(115200);
while (!Serial) delay(10); // will pause Zero, Leonardo, etc until serial console opens

Serial.println(“Adafruit SCD30 test!”);
Wire.begin(41, 42);
// Try to initialize!
if (!scd30.begin()) {
Serial.println(“Failed to find SCD30 chip”);
while (1) { delay(10); }
}
Serial.println(“SCD30 Found!”);

// if (!scd30.setMeasurementInterval(10)){
// Serial.println(“Failed to set measurement interval”);
// while(1){ delay(10);}
// }
Serial.print(“Measurement Interval: “);
Serial.print(scd30.getMeasurementInterval());
Serial.println(” seconds”);
}

void loop() {
if (scd30.dataReady()){
Serial.println(“Data available!”);

if (!scd30.read()){ Serial.println(“Error reading sensor data”); return; }

Serial.print(“Temperature: “);
Serial.print(scd30.temperature);
Serial.println(” degrees C”);

Serial.print(“Relative Humidity: “);
Serial.print(scd30.relative_humidity);
Serial.println(” %”);

Serial.print(“CO2: “);
Serial.print(scd30.CO2, 3);
Serial.println(” ppm”);
Serial.println("");
} else {
//Serial.println(“No data”);
}

delay(100);
}

It works fine :
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x9 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x43c
load:0x403c9700,len:0xbec
load:0x403cc700,len:0x2a3c
SHA-256 comparison failed:
Calculated: dcde8d8a4817d9bf5d5d69a7247667264e4e10ac7493514868b61f5aa6146539
Expected: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Attempting to boot anyway…
entry 0x403c98d8
Adafruit SCD30 test!
SCD30 Found!
Measurement Interval: 2 seconds
Data available!
Temperature: 26.42 degrees C
Relative Humidity: 52.42 %
CO2: 762.479 ppm

So i can’t figure out why it does not work correctly with BMP280…

You probably need to tell the library to use “Wire” as the connection for your BMP280

Try changing:
Adafruit_BMP280 bmp;
to:
Adafruit_BMP280 bmp(&Wire);

By the way, you can check in the library, which options are available:


Adafruit_BMP280(TwoWire *theWire = &Wire);
Adafruit_BMP280(int8_t cspin, SPIClass *theSPI = &SPI);
Adafruit_BMP280(int8_t cspin, int8_t mosipin, int8_t misopin, int8_t sckpin);

Hope this helps. Have a nice day

Thanks
Have a nice day

I found this BME280 works. Sparkfun BME280 script the Basic Reading.

/*

  Get basic environmental readings from the BME280

  By: Nathan Seidle

  SparkFun Electronics

  Date: March 9th, 2018

  License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

  Feel like supporting our work? Buy a board from SparkFun!

  https://www.sparkfun.com/products/14348 - Qwiic Combo Board

  https://www.sparkfun.com/products/13676 - BME280 Breakout Board

 

  This example shows how to read humidity, pressure, and current temperature from the BME280 over I2C.

  Hardware connections:

  BME280 -> Arduino

  GND -> GND

  3.3 -> 3.3

  SDA -> A4

  SCL -> A5

*/

#include <Wire.h>

#include "SparkFunBME280.h"

BME280 mySensor;

void setup()

{

  Serial.begin(115200);

  Serial.println("Reading basic values from BME280");

  Wire.begin();

  if (mySensor.beginI2C() == false) //Begin communication over I2C

  {

    Serial.println("The sensor did not respond. Please check wiring.");

    while(1); //Freeze

  }

}

void loop()

{

  Serial.print("Humidity: ");

  Serial.print(mySensor.readFloatHumidity(), 0);

  Serial.print(" Pressure: ");

  Serial.print(mySensor.readFloatPressure(), 0);

  Serial.print(" Alt: ");

  //Serial.print(mySensor.readFloatAltitudeMeters(), 1);

  Serial.print(mySensor.readFloatAltitudeFeet(), 1);

  Serial.print(" Temp: ");

  //Serial.print(mySensor.readTempC(), 2);

  Serial.print(mySensor.readTempF(), 2);

  Serial.println();

  delay(50);

}

Thank you.

I had to change the SDA and SCL pins to 19 and 20, and the I2C address to 0x76 (in the library).
But I can confirm it works on WSL V3.

Sorry I cannot find in which file I have to change the SDA and SCL pins. Moreover in the Adafruit_BME280.h library as far as I understand both addresses 0x76 and 0x77 are allowed, sure the address needs to be changed to 0x76?

P.S: I found another thread on a different forum here https://randomnerdtutorials.com/esp32-web-server-with-bme280-mini-weather-station/ where it seems it is possible to change the SDA and SCL pin assignment from the sketch without the need to edit the library, I tried adding
#define I2C_SDA 3
#define I2C_SCL 4
and changing Adafruit_BME280 bme --> Adafruit_BME280 bme(I2C_SDA, I2C_SCL) but I got an error
(BTW I have a BME280 not BMP280 but that should not make difference about I2C communication…)

So, has anybody then found a definitive/reliable method of reading from a BME280 and presenting the details on the OLED screen of a plain WiFi kit Dev Board (using “HT_SSD1306Wire.h”). Full code would really be appreciated :slight_smile: or are well all just wasting one-another’s time here?

Here is a code that works with a Lora v3 WiFi; I added a TwoWire for the second i2c.

TwoWire Wire2(1);

In the setup:

Wire2.begin(41,42); /* (GPIO SDA and SCL) */
status = bme.begin(0x76, &Wire2);

This is the only modification to make.!

20:57:15.814 ->

20:57:16.783 -> Temperature = 21.99 °C

20:57:16.827 -> Pressure = 975.40 hPa

20:57:16.827 -> Approx. Altitude = 320.02 m

20:57:16.827 -> Humidity = 61.26 %

20:57:16.827 ->

/***************************************************************************

This is a library for the BME280 humidity, temperature & pressure sensor

Designed specifically to work with the Adafruit BME280 Breakout

----> http://www.adafruit.com/products/2650

These sensors use I2C or SPI to communicate, 2 or 4 pins are required

to interface. The device’s I2C address is either 0x76 or 0x77.

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

See the LICENSE file for details.

***************************************************************************/

#include <Wire.h>

#include <SPI.h>

#include <Adafruit_Sensor.h>

#include <Adafruit_BME280.h>

#include “HT_SSD1306Wire.h”

#include “images.h”

#define SEALEVELPRESSURE_HPA (1013.25)

TwoWire Wire2(1);

//#define RST_OLED 16 //OLED Reset pin, requires manual reset, otherwise it will not be displayed

#define OLED_UPDATE_INTERVAL 500 //OLED screen refresh interval ms

//SSD1306 display(0x3C, 4, 15); //Pins 4 and 5 are bound to the motherboard of Kit 32 and cannot be used for other purposes

static SSD1306Wire display(0x3c, 500000, SDA_OLED, SCL_OLED, GEOMETRY_128_64, RST_OLED); // addr , freq , i2c group , resolution , rst

;

Adafruit_BME280 bme; // I2C

unsigned long delayTime;

void setup() {

Serial.begin(115200);

while(!Serial);    // time to get serial running

display.init();

display.clear();

display.display();



display.setContrast(255);

display.drawString(0, 0, "BME280 test...");

Serial.println(F("BME280 test"));

unsigned status;



// default settings

// You can also pass in a Wire library object like &Wire2

Wire2.begin(41,42);



status = bme.begin(0x76, &Wire2);

if (!status) {

    Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");

    Serial.print("SensorID was: 0x"); Serial.println(bme.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);

}



delayTime = 1000;

Serial.println();

}

void loop() {

printValues();

delay(delayTime);

}

void printValues() {

display.clear();

display.setFont(ArialMT_Plain_10);        //Set font size

display.setTextAlignment(TEXT_ALIGN_LEFT);//Set font alignment

display.drawString(0, 20, "Température : " + String(bme.readTemperature()) + " C°");

display.drawString(0, 30, "Pression : " + String((bme.readPressure() + 4312 )/ 100.0F)  + " hPa");

display.drawString(0, 40, "Humidité : " +  String(bme.readHumidity()) + " %");

display.display();



Serial.println("Pression avant correction : " + String(bme.readPressure() + 4312)  + " hPa");

Serial.println("Température : " + String(bme.readTemperature()) + " C°");

Serial.println("Pression : " + String((bme.readPressure() + 4312) / 100.0F)  + " hPa");

Serial.println("Humidité : " +  String(bme.readHumidity()) + " %");

delay(3000);

display.clear();

display.display();



Serial.println();

}

keen to get tis going - thank you for your very swift response

You absolute STAR!!!
I’ve been bashing at this for days.
There is a meal/drinks waiting for you if you are ever in Hereford or Cardiff.