Hello, i'm not sure to post at the right place ...
I have a circuit based on ESP32-S3 and i use arduino IDE. I would like to use BMP280 with i2c. The ESP32-S3 contain 2 i2c device. On this circuit on i2c device is used for an OLED and i would like to use the other one for BMP280. So i have to specify the pins used for I2C but i can't understand how it could be possible using adafruit BMP280 lib.
Thanks
ESP32-S3 I2C BMP280
Moderators: adafruit_support_bill, adafruit
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
- dastels
- Posts: 15653
- Joined: Tue Oct 20, 2015 3:22 pm
Re: ESP32-S3 I2C BMP280
As long as they have different addresses you can connect several devices to the I2C bus.
To use a different I2C bus you create an instance of the TwoWire class with those pins, and pass a pointer to it to the constructor of the Adafruit_BMP280 class. Normally you don't pass anything to the AdafruitBMP280 constructor and it defaults to using &Wire.
To create a TwoWire, you call the constructor with something referred to as a bus number. My guess is that this should be 2 to create a secondary bus, but maybe not. Once created, you call setPins with the pin numbers for SDA and SCL. Then you call begin on the new TwoWire object with no arguments. Then you can use it to create the BMP280 object.
But as I said, I highly doubt you need to do that.
Dave
To use a different I2C bus you create an instance of the TwoWire class with those pins, and pass a pointer to it to the constructor of the Adafruit_BMP280 class. Normally you don't pass anything to the AdafruitBMP280 constructor and it defaults to using &Wire.
To create a TwoWire, you call the constructor with something referred to as a bus number. My guess is that this should be 2 to create a secondary bus, but maybe not. Once created, you call setPins with the pin numbers for SDA and SCL. Then you call begin on the new TwoWire object with no arguments. Then you can use it to create the BMP280 object.
But as I said, I highly doubt you need to do that.
Dave
- tanguy_e
- Posts: 10
- Joined: Mon May 15, 2023 1:03 pm
Re: ESP32-S3 I2C BMP280
Thanks for the reply.
Yes i can use the i2c bus but in the sketch using OLED you can find "Wire.begin(sda,scl,freq)" to pass the sda and scl pins.
In the AdafruitBMP280 lib, i find the bmp280_sensortest sketch which use "Adafruit_BMP280 bmp;" to intialise and i can't see how to pass sda and scl pins.
Yes i can use the i2c bus but in the sketch using OLED you can find "Wire.begin(sda,scl,freq)" to pass the sda and scl pins.
In the AdafruitBMP280 lib, i find the bmp280_sensortest sketch which use "Adafruit_BMP280 bmp;" to intialise and i can't see how to pass sda and scl pins.
- dastels
- Posts: 15653
- Joined: Tue Oct 20, 2015 3:22 pm
Re: ESP32-S3 I2C BMP280
As I said, the BMO280 constructor will use &Wire by default which uses the default I2C pins/bus.
What OLED code?
Dave
What OLED code?
Dave
- tanguy_e
- Posts: 10
- Joined: Mon May 15, 2023 1:03 pm
Re: ESP32-S3 I2C BMP280
The OLED code is from
https://github.com/HelTecAutomation/Hel ... r/src/oled
https://github.com/HelTecAutomation/Hel ... rotate.ino
I'm sorry but i have some problem to understand what you mean about BMP280 constructor and to use it with non default I2C pins. I'm quiet a newbie ...
Eric
https://github.com/HelTecAutomation/Hel ... r/src/oled
https://github.com/HelTecAutomation/Hel ... rotate.ino
I'm sorry but i have some problem to understand what you mean about BMP280 constructor and to use it with non default I2C pins. I'm quiet a newbie ...
Eric
- dastels
- Posts: 15653
- Joined: Tue Oct 20, 2015 3:22 pm
Re: ESP32-S3 I2C BMP280
From the code you linked, it looks like you'll be ok if you set up the OLED first, then the BMP280. The OLED code configures Wire which the BMP280 will use by default.
Dave
Dave
- tanguy_e
- Posts: 10
- Joined: Mon May 15, 2023 1:03 pm
Re: ESP32-S3 I2C BMP280
Oh sorry, i explain bad. I don't want to use the OLED with the BMP280. I just take a look to a I2C code to see how it can be done.
Eric
Eric
- dastels
- Posts: 15653
- Joined: Tue Oct 20, 2015 3:22 pm
Re: ESP32-S3 I2C BMP280
Ah. That OLED code may not be the best example. Look at https://learn.adafruit.com/adafruit-bmp ... r-breakout for information and example code.
Dave
Dave
- tanguy_e
- Posts: 10
- Joined: Mon May 15, 2023 1:03 pm
Re: ESP32-S3 I2C BMP280
Thanks i just take a look.
If i add Wire.begin(sda,scl,freq) before Adafruit_BMP280 bmp it will be ok to initialize the sda and scl pins and bmp ?
Eric
If i add Wire.begin(sda,scl,freq) before Adafruit_BMP280 bmp it will be ok to initialize the sda and scl pins and bmp ?
Eric
- dastels
- Posts: 15653
- Joined: Tue Oct 20, 2015 3:22 pm
Re: ESP32-S3 I2C BMP280
You should not have to do anything with Wire. The defaults should work.
Dave
Dave
- tanguy_e
- Posts: 10
- Joined: Mon May 15, 2023 1:03 pm
Re: ESP32-S3 I2C BMP280
I make some tests.
If i use the I2C Wirescan example adding Wire.begin(41, 42) :
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 ):
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 :
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....
If i use the I2C Wirescan example adding Wire.begin(41, 42) :
Code: Select all
#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");
}
}
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 ):
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 :
Code: Select all
// 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);
}
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....
Last edited by dastels on Tue Jun 13, 2023 9:20 am, edited 1 time in total.
Reason: Please use code tags for embedded code
Reason: Please use code tags for embedded code
- dastels
- Posts: 15653
- Joined: Tue Oct 20, 2015 3:22 pm
Re: ESP32-S3 I2C BMP280
So you get no output at all from the BME280 test?
Dave
Dave
- tanguy_e
- Posts: 10
- Joined: Mon May 15, 2023 1:03 pm
Re: ESP32-S3 I2C BMP280
Nope, nothing as the microcontroller does not boot...
- dastels
- Posts: 15653
- Joined: Tue Oct 20, 2015 3:22 pm
Re: ESP32-S3 I2C BMP280
Where is this coming from:
Code: Select all
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
- tanguy_e
- Posts: 10
- Joined: Mon May 15, 2023 1:03 pm
Re: ESP32-S3 I2C BMP280
It comes from the serial monitor
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.