Hi there,
I'm a novice to Arduino and have been trying to get up and running using the various online tutorials and forum threads - they have been very useful thanks.
At the moment, I'm trying to get my setup working which involves x6 BMP280's on the same bus...
I have been using dig pins to alternately drive the address of each sensor high and change the address of the sensor which I want to read... hopefully this isn't a flawed idea and I haven't fallen over at the first hurdle...?!
I started with a single BMP280 to prove the code and have slowly added the to the bus.
I'm now reading sensible temp and pressure values from all six.
However, as I have changed the code to read all of the sensors sequentially, their returned readings shift.
If I read more of the sensors, the pressure readings increase.
Both tests were run withing a couple of minutes of each other and are repeatable - I can run an A-B-A test and the results shift up and back down again.
I will paste the code and sensor readouts below...
Both tests were run with exactly the same wiring setup, I simply changed the array which defines which/how many dig pins to drive high and hence which/how many sensors to read.
Bus capacitance; I haven't changed the wiring for either test - the same number of sensors are on the bus for both, I'm just not driving the SDO pin and reading the redundant sensors.
Address; This confused me to begin with - this particular board uses a different address as default, so I have changed the library accordingly
Pull-up resistor; these seem to be 10k onboard
Hardware; I have tried this on my Arduino Uno R3 and also on the board pictured - both demonstrate the same behaviour
Now, the absolute change in the pressure reading is only quite small... I could calibrate these out and I might consider this, but I need to understand what is causing it for when I change to a more permanent setup, because there will be several different configurations.
The sensor outputs for pressure seem to be good, I can determine a change in altitude of about a meter just by standing up / sitting down with it and plotting the results.
Any help or guidance would be very much appreciated!
Code here>>>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp; // I2C Interface
// timer defines interval between ptx array reads
int setuptime = 250; // Setup time for initialising ptx
int timer = 20; // The higher the number, the slower the timing.
int ptxPins[] = {2, 3, 4}; // an array of pin numbers to which ptxPin is driven high
int pinCount = 3; // the number of pins (i.e. the length of the array)
int maxsamples = 10; // number of samples taken on each sensor - total readings is pinCount * maxsamples
unsigned long time;
void setup()
{
// set up serial comms and test communication
Serial.begin(9600);
Serial.println();
Serial.println(F("BMP280 test"));
time = millis();
//Serial.println(time);
// array defines which ptxPin to drive from 0 to (pinCount - 1).
// for loop to initialize each pin as an output:
for (int thisPin = 0; thisPin < pinCount; thisPin++)
{
pinMode(ptxPins[thisPin], OUTPUT);
}
for (int thisPin = 0; thisPin < pinCount; thisPin++)
{
// turn the pin on:
digitalWrite(ptxPins[thisPin], HIGH);
delay(setuptime);
if (!bmp.begin())
{
Serial.print("Pin# ");
Serial.print(thisPin);
Serial.println(" is NOK - Check wiring");
while (1);
}
/* Default settings from datasheet. */
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X1, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X1, /* Pressure oversampling */
Adafruit_BMP280::FILTER_OFF, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_1); /* Standby time. */
delay(setuptime);
Serial.print("Pin# ");
Serial.print(thisPin);
Serial.println(" is OK");
digitalWrite(ptxPins[thisPin], LOW);
}
// loop 1 from the lowest pin to the highest:
Serial.print("Timer set to ");
Serial.println(timer);
time = millis();
Serial.println(time);
for (int samples = 0; samples < maxsamples; samples++)
{
for (int thisPin = 0; thisPin < pinCount; thisPin++)
{
// turn the pin on:
digitalWrite(ptxPins[thisPin], HIGH);
delay(timer);
//Serial.print(F("Pressure = "));
Serial.print(bmp.readPressure()/100); //displaying the Pressure in hPa, you can change the unit
Serial.print(", ");
Serial.print(bmp.readTemperature());
Serial.print(", ");
//Serial.println();
//delay(timer);
//Serial.println(" hPa");
// turn the pin off:
digitalWrite(ptxPins[thisPin], LOW);
}
Serial.println();
}
time = millis();
Serial.println(time);
}
void loop()
{
}
Results from Tests here>>>
As you can see, sensor 1 reads ~1060mbar on the first test but ~980mbar on the second test, purely by changing
int ptxPins[] = {2, 3, 4, 5, 6, 7}; to int ptxPins[] = {2, 3, 4};
int pinCount = 6; to int pinCount = 3;
Test 1 - addressing all 6 sensors
BMP280 test
Pin# 0 is OK
Pin# 1 is OK
Pin# 2 is OK
Pin# 3 is OK
Pin# 4 is OK
Pin# 5 is OK
Timer set to 20
3651
1059.25, 27.64, 963.70, 23.76, 1091.15, 23.36, 1040.03, 26.21, 884.54, 27.65, 1012.20, 24.69,
1059.19, 27.64, 963.73, 23.76, 1091.08, 23.35, 1040.08, 26.21, 884.59, 27.66, 1012.17, 24.69,
1059.24, 27.64, 963.67, 23.76, 1091.10, 23.36, 1040.08, 26.21, 884.61, 27.65, 1012.17, 24.69,
1059.21, 27.63, 963.67, 23.76, 1091.12, 23.36, 1040.03, 26.21, 884.62, 27.66, 1012.22, 24.68,
1059.16, 27.64, 963.72, 23.77, 1091.10, 23.36, 1040.08, 26.21, 884.64, 27.65, 1012.21, 24.70,
1059.18, 27.64, 963.71, 23.77, 1091.06, 23.36, 1040.01, 26.20, 884.60, 27.66, 1012.13, 24.69,
1059.19, 27.64, 963.65, 23.76, 1091.11, 23.35, 1040.03, 26.21, 884.61, 27.65, 1012.16, 24.68,
1059.23, 27.64, 963.70, 23.76, 1091.15, 23.36, 1040.03, 26.21, 884.59, 27.66, 1012.22, 24.69,
1059.19, 27.64, 963.67, 23.76, 1091.10, 23.37, 1040.01, 26.20, 884.57, 27.66, 1012.21, 24.68,
1059.21, 27.64, 963.75, 23.76, 1091.12, 23.36, 1040.09, 26.20, 884.62, 27.66, 1012.23, 24.69,
5057
Test 2 - addressing only 3 sensors
BMP280 test
Pin# 0 is OK
Pin# 1 is OK
Pin# 2 is OK
Timer set to 20
1825
980.11, 28.85, 886.87, 25.00, 1011.93, 24.61,
979.99, 28.86, 886.88, 25.00, 1011.87, 24.60,
980.07, 28.87, 886.89, 25.01, 1011.84, 24.60,
980.04, 28.86, 886.93, 25.00, 1011.94, 24.61,
980.03, 28.85, 886.89, 25.01, 1011.88, 24.61,
980.10, 28.85, 886.93, 25.00, 1011.88, 24.61,
980.05, 28.85, 886.96, 25.00, 1011.84, 24.60,
980.01, 28.87, 886.87, 25.01, 1011.93, 24.61,
980.07, 28.85, 886.94, 25.01, 1011.93, 24.61,
980.03, 28.86, 886.90, 25.00, 1011.90, 24.61,
Any help greatly appreciated
