Adafruit BME280 library [PORTED]

I have tested it with many other programs. Even with the hello world it’s working perfectly fine. I’m not sure what’s wrong.
I think I’m just going to switch to another library and use the I2C protocol instead.
Thanks everyone for the assitance.

I would double check that you have the data lines hooked up correctly since it is easy to swap data in and data out:

A2 (CS) goes to the sensor CSB
A3 (SCK) goes to the sensor SCK
A4 (MISO) goes to the sensor SDO
A5 (MOSI) goes to the sensor SDI

plus power and ground of course.

@Alli, I believe the issue is with the CSB pin on your BME280 board. It needs to be set as follows:

Interface selection is done automatically based on CSB (chip select) status. If CSB is connected to VDDIO, the I²C interface is active. If CSB is pulled down, the SPI interface is activated. After CSB has been pulled down once (regardless of whether any clock cycle occurred), the I²C interface is disabled until the next power-on-reset. This is done in order to avoid inadvertently decoding SPI traffic to another slave as I²C data. Since the device startup is deferred until both VDD and VDDIO are established, there is no risk of incorrect protocol detection because of the power-up sequence used. However, if I²C is to be used and CSB is not directly connected to VDDIO but is instead connected to a programmable pin, it must be ensured that this pin already outputs the VDDIO level during power-on-reset of the device. If this is not the case, the device will be locked in SPI mode and not respond to I²C commands.

So for SPI operation, CSB must be connected to GND. :wink:

1 Like

@peekay123 @bko
Hello. Thank you for the advice and assistance but nothing seems to be working to resolve this issue. I decided to use I2C with the Control everything library instead and everything is working great.

Thank you all for your time and help. i really appreciate the support i received from the particle community.

@Alli I am a newbie in microcontroller programming and encountered the same problem when using SPI interface with CS as A2 as recommended by @Postler and even performed as using D1,D2… but no luck.
will be grateful to you if able to get assistance on I2C programming for this sensor.
(P.S. I am needing it for my school project)

Hello @manjil123

Firstly, make sure that you have connected your BME280 correctly to your particle device. I used a particle photon, thus pins D0 and D1 (SDA and SCL) are the I2C pins as shown in the pinout diagram in this link:

Ensure that your BME280 is connected to the photon as shown in this link:

You will need to include the CE_BME280 library in your project first. Then use these instructions in your program to poll measurements from your BME280:

Pressure = (bme.readPressure()/100);                 //Pressure measurements in hPa
Temperature = bme.readTemperature();
Humidity = bme.readHumidity();

Its as simple as that. If you are still having a problem, post the program you created so that we can see what you are doing and try to help :+1:t2:

Here is a sample program that displays to the serial monitor:

#include <CE_BME280.h>                                          
#define Addr 0x77                            //BME280 address 119 (decimal) for the Sparkfun board

float Temperature;
float Pressure;
float Humidity;

void GetBME280SensorData(void);                //Get BME280 Sensor data
void DisplayOnSerialMonitor();

byte BME280SensorConnected=0;

CE_BME280 bme;                                      // I2C

void setup() {
    Serial.println("BME280 sensor detection test");         


void loop() {
    if(!bme.begin(Addr)){          //If a BME280 sensor is not available at that Address than print this 
        Serial.println("BME280 sensor not connected");
    else if(bme.begin(Addr)){
        Serial.println("BME280 sensor is connected and setup is complete"); 



void GetBME280SensorData(){

    Temperature = bme.readTemperature();
    Humidity = bme.readHumidity();
    Pressure = (bme.readPressure()/100);                    //To convert to hPa

void DisplayOnSerialMonitor(){
    Serial.print("Temperature ");     
    Serial.println(" C");
    Serial.print("Humidity ");
    Serial.println(" %");
    Serial.print("Pressure ");
    Serial.println(" hPa");

Basically i was trying SPI interface with the example .ino provided by particle. With no success, i wanted to shift to I2C but even your the code provided by you is not working.I think its the problem of the I2C address but performed the I2C scanner and used different address like 0 D0, 077 and 0*76 no luck.
Even used some pull up resistors of 4.7 k for I2C interface between 3v3 to SCA AND SCL and CSB to 3V3 but no luck.
(P.S. my sensor is GY-BME/P280.)

Alright i will need more information in order to help you. Please show the code you are using and also draw the circuit of the connection you are using between the BME280 and the particle device.

Even used some pull up resistors of 4.7 k for I2C interface between 3v3 to SCA AND SCL and CSB to 3V3 but no luck.

I don’t quite understand how you are connecting the sensor to the particle device. Infact this connection sounds completely wrong. You connect 3V3 to the power pin of the sensor only. SDA of the sensor connects to SDA of yhe particle device and SCL of the sensor connects to SCL of the particle device.:face_with_raised_eyebrow:
Also can you provide a link for the version of the BME280 sensor you are using. Are you using the particle photon ? Also when you ran your I2C scanner which address did the sensor respond to ?

P.S you only need 2 connections for data transmission with I2C: SDA and SCL.

Don’t know whats happening but after i tested my photon with example ino of web ide named bmetest.ino its been breathing green.
Now i am trying to get results on electron so hope i will succeed.
For the connection, as stated by @

Basically i was trying SPI interface with the example .ino provided by particle.

You said you were using the example for SPI here. I have no idea what example you are referring to and it will be easier to help you if you put all the information here for us to see.

For I2C you only need 4 connections: 2 for power and 2 for communication and nothing else. Did you try connecting it the same i suggested which is also the way its suggested in the website for the I2C connection ( SDA photon to SDA BME280 and SCL photon to SCL BME280)? VCC of the sensor connects to 3.3V of the photon and GND of the photon connects to GND of the BME280. Have you done this? Those are all the connections you require.

Generally a breathing green implies a problem with cloud connection i.e. you are not connected to particles cloud. Please connect the sensor to your photon the way i suggested and run the code i provided using the library i suggested. If you are unsure of the address connect the sensor as i suggested and run the I2C scanner to find the address. Without the correct address it will not work. If your photon is breathing green still try upgrading the software of your photon from the particle dash board.

I am trying it with the next photon i bought and got this result with I2C interface and had scanned too my I2C which is 0*76.
Device photon and sensor GY-BME/P280.
Seriously in need of help…

I had issues using the adafruit library also. That’s why I changed to the control everything library and suggested that you try theirs out. It worked for me. Did you try the program I suggested in conjunction with the library I suggested ?

It’s not 0*76 which would equate to zero (anything mulitplied by 0 will be 0) but it it 0x76 which is the C/C++ way of denoting hexadecimal numbers.

i connected the D0 and D1 with SDA and SCL and copied your whole code with that specified library, even it is not functioning.

Thanks for your reply. that was the silly mistake but even using right way of address, it is not functioning.

Did you try the code I provided with the correction ScruffR pointed out ?

I am open to correction but i think the adafruit library for the BME280 works best with the adafruit BME280 sensor. Control Everything’s library worked with all the BME280 sensors I tried. You said you tried the code I suggest with the library I suggested. Can you tell us what went wrong with it ? So we can try to identify the problem.

Sorry for digging up an old thread. Trying to compile, using the GitHub library (on SPI), but at the cloud compile stage (from Particle Workbench) it derives errors. Principal of these, is the use of the Arduino function in the BME280.h header.

Has anyone else come across this?

Yes, I had this problem as well. Have not been able to get my sensor working.

Good Day everyone… Thanks for the useful advice above. I was able to get my 280 up and running first try. Now I’d like to add a second BME280 using the CE_BME280 lib. I’ve done this before with DHT22’s on their lib’s and have found examples on the web for other BME280 library’s but am not skilled enough to know what to do (or if it will work with this library). I’d appreciate any direction you can offer.