BME280 Working on Arduino Uno but not on Mega

Hello,

I am working on an automatic data acquisition system that uses the BME280 to measure temperature, pressure and humidity.

I have been primarily constructing the project on an Arduino Mega, and was having trouble interfacing with the BME chip, hooked up in the configuration outlined below (BME280 Pinout:Arduino Mega)

Vin:3.3V
GND:GND
SCL: Pin 21 (SCL)
SDA: Pin 20 (SDA)

I have been running this code to test the sensor;

#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

float temperature;
float humidity;
float pressure;

#define ALTITUDE 0

Adafruit_BME280 bme; // I2C

void setup(void) {
  Serial.begin(9600);
  bool status;
    
    // default settings
    status = bme.begin(0x76);  //The I2C address of the sensor I use is 0x76
    if (!status) {
        Serial.print("Sensor not working, check connections");
        while (1);
    }
}

void loop() {
  
 delay(2000);

getPressure();
getHumidity();
getTemperature();
 
  
 
 //Printing Temperature
 String temperatureString = String(temperature,1);
 Serial.write("T:"); 
 Serial.print(temperatureString);
 Serial.write((char)223);
 Serial.write("C ");
 Serial.println();
 
 //Printing Humidity
 String humidityString = String(humidity,0); 
 Serial.write("H: ");
 Serial.print(humidityString);
 Serial.write("%");
 Serial.println();
 
 //Printing Pressure
 Serial.write("P: ");
 String pressureString = String(pressure,2);
 Serial.print(pressureString);
 Serial.write(" hPa");
 Serial.println();
}

float getTemperature()
{
  temperature = bme.readTemperature();
}

float getHumidity()
{
  humidity = bme.readHumidity();
}

float getPressure()
{
  pressure = bme.readPressure();
  pressure = bme.seaLevelForAltitude(ALTITUDE,pressure);
  pressure = pressure/100.0F;
}

I get an output of "Sensor not working, check connections" on the serial monitor.

When I run the same code on an Arduino Uno, with

Vin:3.3V
GND:GND
SDA:Analog 4
SCL:Analog 5

It works. What can I try to solve this? I found this on Stack Overflow:
"Might not be working and would need reprogramming. See the Programming section on the info page, you will need the firmware and Atmel-compatible DFU (device firmware update) software on your computer to reflash the target."
But I am unfamiliar with what this even means.

Thank you

please post pictures of the connection to UNO vs MEGA. I'm guessing it's wiring issue.

Are you using level shifters (or does the BME280 module include them) to drop the 5V SCL/SDA lines down to 3.3V.

@OP

1. Your program is running well in my MEGA.
Sm63.png

2. This is the BME280 which I am using; it has a built-in 5V/3.3V regulator. So, it has to be operated from 5V and not from 3.3V.
bme280Module.png

Sm63.png

bme280.png

Wolframore, please see attached images of my wiring schematics. I have tried both 3.3V and 5V for Vin as the BME chip I am using has a built in voltage regulator.

Riva, I know the chip has a built in regulator, not sure if that is the level shifter you are referring to.

GolamMustafa, I am using the same BME sensor, I could get it to work running 3.3V to it. I just tried 5V from the Mega and got the same output.

Thanks for all your suggestions so far.

Arduino Mega BME.PNG

Arduino Uno BME.PNG

please double check SCL and SDA connections on the Mega

The SDA/SCL pins on the sensor are connected to the SDA/SCL ports on the MEGA respectively. Unless the Sensor SDA should be going to the Mega SCL and vice versa.

No it’s right. The illustration must have different pin outs than the actual picture.

Does it show up using an I2C scanner sketch?

@wolframore Yeah sorry, the image available for the board on fritz is different than the chip than I have, I couldnt find the actual one.

@Riva, it does, at address 0x76, which is what I have been specifically assigning to the sensor in my sketch

GodOfHammers:
@Riva, it does, at address 0x76, which is what I have been specifically assigning to the sensor in my sketch

That's good. It means your connected and the module responds okay using I2C on the Mega (assuming you did the test on the Mega) so the problem is somewhere in the code.
Maybe try the Sparkfun library for the BME280 to see if it fairs better.

If you search for this then do you see an image that looks correct?

Ok I will try a different library, but wouldn't the fact that the code works on the Uno with the same libraries I am trying to use on the Mega?

And yes, the BME280 I have is the same as the one GolamMostafa posted above.

If golem has it working you sure it isn’t a wiring issue?

wolframore:
If golem has it working you sure it isn’t a wiring issue?

Good point, I use the Adafruit BME280 library but have only ever used it on UNO, 32u4 & ESP. I was wondering if the library fails on the MEGA.

Reread Golam’s reply. He has the BME working on his Mega using 5v.

wolframore:
Reread Golam’s reply. He has the BME working on his Mega using 5v.

Yes I had read it, hence the 'Good point' statement. I was just point out what I was hoping to be the problem.
If the OP has tested the module on the Mega with the I2C scanner and found it I can think of no other sensible reason for it not to work on the Mega but work on the UNO.

GolamMostafa:
2. This is the BME280 which I am using; it has a built-in 5V/3.3V regulator. So, it has to be operated from 5V and not from 3.3V.
bme280Module.png

It seems to me that the module your picture shows has neither a 3.3V regulator nor any level shifting.
Do you have a picture of the backside of the module to support your claim "it has a built-in 5V/3.3V regulator"?

Voltage regulator & level shifting.

Thanks for the clarification.

Very unusual double sided arrangement, most of the modules I've seen were single sided.

Whandall:
Very unusual double sided arrangement, most of the modules I've seen were single sided.

I like them because you can get a good weatherproof seal when fitting in a small project box with a drilled hole for the sensor.