Hello. I am currently working on a project using an Arduino Mega (ATmega2560) with BME280 sensors to collect temperature, humidity, and pressure. I am also using an RS232 to TTL converter to collect lab scale data, and the ethernet shield 2 for to display live data and save to an SD card.
The issue I am having is using multiple BME280 sensors over SPI. I am opting for SPI for the longer cable length, and I am currently using 8-pin M12 cables to transfer the data. I would ideally like to use four BME280 sensors simultaneously, however I get erratic readings when using more than one. Depening on the number of sensors attached, I get anywhere from 20 degrees to 140 degrees off from the readings. The cable lengths are roughly 1m each, with about 0.25 M of wires coming from the M12 receptacles mounted on my enclosure to a solder board.
I have been able to get multiple BME sensors working with longer M12 cable lengths before, but I believe the issues are arising from the ethernet shield since it also uses SPI for communication. The issue applies even when I use the example sketch for the BME sensors below:
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define BME_SCK 7
#define BME_MISO 6
#define BME_MOSI 5
#define BME_CS 4
#define BME_CS2 3
#define BME_CS3 2
#define BME_CS4 1
#define SEALEVELPRESSURE_HPA (1013.25)
//Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
Adafruit_BME280 bme2(BME_CS2, BME_MOSI, BME_MISO, BME_SCK); // software SPI
Adafruit_BME280 bme3(BME_CS3, BME_MOSI, BME_MISO, BME_SCK); // software SPI
Adafruit_BME280 bme4(BME_CS4, BME_MOSI, BME_MISO, BME_SCK); // software SPI
unsigned long delayTime;
void setup() {
Serial.begin(9600);
while (!Serial)
; // time to get serial running
Serial.println(F("BME280 test"));
unsigned status;
unsigned status2;
unsigned status3;
unsigned status4;
// default settings
status = bme.begin();
status2 = bme2.begin();
status3 = bme3.begin();
status4 = bme4.begin();
// You can also pass in a Wire library object like &Wire2
// status = bme.begin(0x76, &Wire2)
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
Serial.print("SensorID was: 0x");
Serial.println(bme.sensorID(), 16);
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
Serial.print(" ID of 0x60 represents a BME 280.\n");
Serial.print(" ID of 0x61 represents a BME 680.\n");
while (1) delay(10);
}
Serial.println("-- Default Test --");
delayTime = 8000;
Serial.println();
}
void loop() {
printValues();
delay(delayTime);
}
void printValues() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" °C");
Serial.print("Temperature 2 = ");
Serial.print(bme2.readTemperature());
Serial.println(" °C");
Serial.print("Temperature 3 = ");
Serial.print(bme3.readTemperature());
Serial.println(" °C");
Serial.print("Temperature 4 = ");
Serial.print(bme4.readTemperature());
Serial.println(" °C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Pressure 2 = ");
Serial.print(bme2.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.print("Humidity 2 = ");
Serial.print(bme2.readHumidity());
Serial.println(" %");
Serial.print("Humidity 3 = ");
Serial.print(bme3.readHumidity());
Serial.println(" %");
Serial.println();
Serial.print("Humidity 4 = ");
Serial.print(bme4.readHumidity());
Serial.println(" %");
}
I have not included images of the breadboard since there are several other components on it and it will be unhelpful in determining the issue. All 4 ports work on their own, but the issue only arises when multiple sensors are connected.
Any help or direction would be very appreciated.