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.
It’s possibly easier to see the wiring on the breadboard illustration below. Everything wired to the same pins except the white cables.
#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.begin(9600); 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; Serial.println(); } void loop() { printValues(); delay(delayTime); } void printValues() { Serial.print("Temperature = "); Serial.print(bme1.readTemperature()); Serial.println(" *C"); Serial.print("Temperature = "); Serial.print(bme2.readTemperature()); 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.print(bme1.readAltitude(SEALEVELPRESSURE_HPA)); Serial.println(" m"); Serial.print("Approx. Altitude = "); Serial.print(bme2.readAltitude(SEALEVELPRESSURE_HPA)); Serial.println(" m"); Serial.print("Humidity = "); Serial.print(bme1.readHumidity()); Serial.println(" %"); Serial.print("Humidity = "); Serial.print(bme2.readHumidity()); Serial.println(" %"); 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 %
Buy Me A Coffee
If you found something useful above please say thanks by buying me a coffee here...
I have 4 pin at my BME280 (SCL, SDA, VINN, GND). Can I connect as you told? Can you help me with this?
It has an i2c connection. This video should help – https://www.youtube.com/watch?v=qoc7N6Yg5jk
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!
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?