BMP280 and XIAO SAMD21 compatibility issue

Hi,

I'm using the adafruit bmp 280 for some pressure measurements for a rocket launch. The problem is that when I run the below code nothing gets printed to the serial monitor at all. I know this is an issue with the bmp 280s because upon removal of their code it works just fine. Interestingly, everything I'm doing works on the Arduino Uno, which is somewhat strange. I also ran an I2C scan and the bmps are found on 0x76 and 0x77, so I feel like this might be a communication or wiring problem. I posted this same issue on the specific adafruit bmp 280 github.

Below is the code and a photo of my wiring. Any help would be greatly appreciated!

#include #include #include #include

Adafruit_BMP280 bmp; // Sensor 1
Adafruit_BMP280 bmp2; // Sensor 2
File dataFile;

void setup() {
Serial.begin(9600);
delay(500);
Serial.println("starting!!!");

Wire.begin(); // Initialize I2C communication

if (!bmp.begin(0x76)) {
Serial.println("Could not find a valid BMP280 sensor 1, check wiring!");
while (1);
}

if (!bmp2.begin(0x77)) {
Serial.println("Could not find a valid BMP280 sensor 2, check wiring!");
while (1);
}

Serial.println("Both BMP280 sensors initialized successfully.");

if (!SD.begin(7)) { // Initialize SD card
Serial.println("SD card initialization failed!");
while (1);
}
Serial.println("SD card initialized.");
}

void loop() {
float temperature1 = bmp.readTemperature();
float temperature2 = bmp2.readTemperature();
float altitude1 = bmp.readAltitude(1005);
float altitude2 = bmp2.readAltitude(1005);
float pressure1 = bmp.readPressure();
float pressure2 = bmp2.readPressure();

// Print sensor data to Serial Monitor
Serial.print("Temperature 1: ");
Serial.println(temperature1);
Serial.print("Temperature 2: ");
Serial.println(temperature2);
Serial.print("Altitude 1: ");
Serial.println(altitude1);
Serial.print("Altitude 2: ");
Serial.println(altitude2);
Serial.print("Pressure 1: ");
Serial.println(pressure1);
Serial.print("Pressure 2: ");
Serial.println(pressure2);
Serial.println("-------------------------");

// Write data to SD card
dataFile = SD.open("data.txt", FILE_WRITE);
if (dataFile) {
dataFile.print("Temperature 1: "); dataFile.println(temperature1);
dataFile.print("Temperature 2: "); dataFile.println(temperature2);
dataFile.print("Altitude 1: "); dataFile.println(altitude1);
dataFile.print("Altitude 2: "); dataFile.println(altitude2);
dataFile.print("Pressure 1: "); dataFile.println(pressure1);
dataFile.print("Pressure 2: "); dataFile.println(pressure2);
dataFile.println("-------------------------");
dataFile.close(); // Save the file
} else {
Serial.println("Error opening data.txt for writing.");
}

delay(1000);
}

![IMG_1336|281x500](upload://g8z2cYn5rl7aGluKD4THD3sogdg.jpeg) ![IMG_1338|281x500](upload://cD1gMdJOUl5jYSG56m2iQ2Ty2oS.jpeg)

Please read the forum guide in the sticky post at the top of the forum section and then edit your post above so that it no longer breaks forum rules.

Start with this to see if it is possible to print to serial at all

void setup() {
Serial.begin(9600);
delay(500);
Serial.println("starting!!!");

Spamming multiple forums with the exact same request is a great way to find yourself blocked on Reddit and ignored here.

1 Like

The Wire.begin(); should come before sensor initialization.
Try to add Wire.setClock(100000); after Wire.begin(); to explicitly set the I2C clock speed.

And what happened when you ran a basic sketch, no SD card etc, that read just one of the BMP280s and printed the results to the serial monitor ?

First things first: start with just one BMP280 and make sure that the standard library examples are working properly.

Then add the extras, one at a time, fixing each problem as you go.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.