ESP8266 with two BME280 Sensors over SPI

ESP8266 with two BME280s

I had a problem with the wiring on this one. With SPI you use the same pins for SCLK (SCL pin on the BME280 boards) , MOSI (SDA pin) and MISO (SDO pin) and then each SPI sensor has to have its own CS (CSB pin).

Originally I had MISO sharing the same pin (D4)  I used on the single sensor version. When I connected two MISO (SDO) connections the ESP8266 was not happy. At one point it wasn’t recognised over USB. Possibly due to D4 normally being the LED pin. I changed the pins and the sketch code so the MISO (SDO) connections are on D5 and changed D4  to the CS output for the second sensor.

You can see the wiring layout below. Basically both sensors have the same connectors for everything except the CSB connections on each BME280 have their own pin on the ESP8266. These are the white cables.

ESP8266 Two BME280s Wiring Diagram

ESP8266 with two BME280s Wiring Diagram

It’s possibly easier to see the wiring on the breadboard illustration below. Everything wired to the same pins except the white cables.

Diagram showing the ESP8266 wired to both BME280s on a breadboard.

ESP8266 with two BME280s Above

Image showing the ESP8266 with two BME280s on the breadboard

BME280 Connections

Connections on the BME280s

ESP8266 Connections

Connections on the ESP8266

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

// assign the ESP8266 pins to arduino pins
#define D1 5
#define D2 4
#define D3 0
#define D4 2
#define D5 14

// assign the SPI bus to pins
#define BME_SCK D1
#define BME_MISO D5
#define BME_MOSI D2
#define BME1_CS D3
#define BME2_CS D4

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme1(BME1_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
Adafruit_BME280 bme2(BME2_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

unsigned long delayTime;

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

    bool status;
    // default settings
    status = bme1.begin();
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor 1 , check wiring!");

    // default settings
    status = bme2.begin();
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor 2 , check wiring!");
    Serial.println("-- Default Test --");
    delayTime = 5000;


void loop() { 

void printValues() {
    Serial.print("Temperature = ");
    Serial.println(" *C");
    Serial.print("Temperature = ");
    Serial.println(" *C");    

    Serial.print("Pressure = ");
    Serial.print(bme1.readPressure() / 100.0F);
    Serial.println(" hPa");
    Serial.print("Pressure = ");
    Serial.print(bme2.readPressure() / 100.0F);
    Serial.println(" hPa");    

    Serial.print("Approx. Altitude = ");
    Serial.println(" m");
    Serial.print("Approx. Altitude = ");
    Serial.println(" m");    

    Serial.print("Humidity = ");
    Serial.println(" %");
    Serial.print("Humidity = ");
    Serial.println(" %");



Below are the results in the serial monitor. I don’t know why the altitude reading is different. The temperature and humidity readings are close and that’s all I’m going to use in the project this test is for.

Temperature = 30.53 *C
Temperature = 30.55 *C
Pressure = 1004.37 hPa
Pressure = 1004.05 hPa
Approx. Altitude = 74.21 m
Approx. Altitude = 76.87 m
Humidity = 65.61 %
Humidity = 65.08 %

4 Replies to “ESP8266 with two BME280 Sensors over SPI”

  1. Hayati Bolat says:

    I have 4 pin at my BME280 (SCL, SDA, VINN, GND). Can I connect as you told? Can you help me with this?

    1. WordBot says:

      It has an i2c connection. This video should help –

  2. Catalin says:

    Please help me with one problem.
    If I connect the two BME280 with short, equal cables (0.3 meters) everything work great.
    If I connect the two BME280 with one short cable (0.3 meters) and one long cable (6 meters), just one sensor work correct (the long cable sensor). The short one indicate values 0.
    What can I do?
    Thank you!

    1. WordBot says:

      That doesn’t really make sense. I’m surprised it works with a 6 meter cable. If you switch the sensor on the 6m cable does it still work?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

scroll to top