Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong pressure reported when using a BMP388 and BMP390 at the same time #18

Closed
theswordsmith opened this issue Jun 16, 2021 · 9 comments

Comments

@theswordsmith
Copy link

When attempting to run the simpletest for an Adafruit BMP390 and Adafruit BMP388 at the same time, the pressure reported back on one device will always be wrong. This was tested on one I2C bus with a BMP390 at 0x77 and a BMP388 at 0x76.

The same issue occurs when attempting to run this across two different I2C buses as well. The bug appears to affect whichever sensor is started second, which becomes the erroneous pressure sensor. If either pressure sensor is run by itself, the correct pressure is always reported.

These were the Serial results are from a Teensy 4.1 compiled in Arduino 1.8.13, however it should replicate on any Arduino.

Example Output:
BMP388 Sensor #1 using &Wire  0x76 
Temperature = 26.56 *C
Pressure = 1012.74 hPa
Approx. Altitude = 3.88 m

BMP390 Sensor #2  using &Wire1 0x77
Temperature = 27.25 *C
Pressure = 958.15 hPa   <===========[WRONG PRESSURE REPORTED]
Approx. Altitude = 468.74 m
Example Output if starting of sensors order is reversed:
BMP388 Sensor #1 &Wire 0x76
Temperature = 25.97 *C
Pressure = 1109.57 hPa   <===========[WRONG PRESSURE REPORTED]
Approx. Altitude = -772.71 m

BMP390 Sensor #2 using &Wire1 0x77 
Temperature = 26.65 *C
Pressure = 1012.26 hPa
Approx. Altitude = 8.30 m

bmp3xx_simpletest example code to replicate the issue:

 /*   Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
modified to attempt collection from a BMP388 and BMP390 at the same time
 ***************************************************************************/

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP3XX.h"

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BMP3XX bmp;
Adafruit_BMP3XX bmp2;

void setup() {
  Wire.setSCL(19);
  Wire.setSDA(18);
  Wire.begin();
    
  Wire1.setSCL(16);
  Wire1.setSDA(17);
  Wire1.begin();
    
  Serial.begin(115200);
  while (!Serial);
  Serial.println("Adafruit BMP388 / BMP390 test");

  if (!bmp.begin_I2C(0x76, &Wire)) {   // hardware I2C mode, can pass in address & alt Wire
    Serial.println("Could not find a valid BMP3 sensor, check wiring!");
    while (1);
  }
  if (!bmp2.begin_I2C(0x77, &Wire1)) {   // hardware I2C mode, can pass in address & alt Wire
    Serial.println("Could not find a valid BMP3 sensor, check wiring!");
    while (1);
  }
  
  // Set up oversampling and filter initialization
  bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
  bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
  bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
  bmp.setOutputDataRate(BMP3_ODR_50_HZ);

  // Set up oversampling and filter initialization
  bmp2.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
  bmp2.setPressureOversampling(BMP3_OVERSAMPLING_4X);
  bmp2.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
  bmp2.setOutputDataRate(BMP3_ODR_50_HZ);
}

void loop() {
  if (! bmp.performReading()) {
    Serial.println("Failed to perform reading :(");
    return;
  }
  Serial.println("BMP388 Sensor #1 using &Wire 0x76");
  Serial.print("Temperature = ");
  Serial.print(bmp.temperature);
  Serial.println(" *C");

  Serial.print("Pressure = ");
  Serial.print(bmp.pressure / 100.0);
  Serial.println(" hPa");

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

  Serial.println();

  if (! bmp2.performReading()) {
    Serial.println("Failed to perform reading :(");
    return;
  }
  Serial.println("BMP390 Sensor #2 using &Wire1 0x77 ");
  Serial.print("Temperature = ");
  Serial.print(bmp2.temperature);
  Serial.println(" *C");

  Serial.print("Pressure = ");
  Serial.print(bmp2.pressure / 100.0);
  Serial.println(" hPa");

  Serial.print("Approx. Altitude = ");
  Serial.print(bmp2.readAltitude(SEALEVELPRESSURE_HPA));
  Serial.println(" m");
  Serial.println();
  
  delay(2000);
}

@ladyada
Copy link
Member

ladyada commented Jun 16, 2021

correct, same as
#16
you cannot run two of these at the same time... no ETA on when it would be changed/fixed

@theswordsmith
Copy link
Author

Thanks for getting back so quickly ladyada,

Is there a super easy way to clone the library and create an Adafruit_BMP388.h and Adafruit_BMP390.h, so that each sensor utilizes it's own library as a temporary work-around? I'm not sure if this would even work, but willing to try if there is some chance of success.

@ladyada
Copy link
Member

ladyada commented Jun 16, 2021

goodness.. maybe? you'd have to rename everything tho.

@ladyada
Copy link
Member

ladyada commented Jun 21, 2021

you can try #19

@caternuson
Copy link
Contributor

Please update to the 2.1.0 release and see if that resolves this issue:
https://github.com/adafruit/Adafruit_BMP3XX/releases/tag/2.1.0

@heliophagus
Copy link

The issue is not resolved, at least as far as pressure is concerned. In the example showing 2-sensor operation, only temperature was printed. My 2 BMP390 sensors agreed closely on temperature, but differed completely (by >1250 Pa) in pressure. If the sensors are operated solo (with no attempt to replicate sensors) their pressure readings agree almost perfectly -within a few Pa. My best guess is that the voluminous sensor-specific calibration data are not being applied correctly to the appropriate sensor, & that the corrections being applied are significantly more critical for pressure than for temperature.

@heliophagus
Copy link

Hmmm... After removing & reinstalling the Adafruit_BMPXX library, & ensuring (again) that I had the latest build, I am getting matching to within an excellent ~2-4 Pa between the two sensors, which are MUXed on a TCA9548 (because reasons). And each sensor faithfully responds to separate pressure changes. So, this appears to have been a false alarm. Apologies!

@heliophagus
Copy link

Well, after re-compiling, the large difference between the sensors reappeared. Here is a sample of what this looks like (units are kPa):

BMP #1 = 100.0097
BMP #2 = 101.1965
BMP #1 = 100.0099
BMP #2 = 101.1959
BMP #1 = 100.0101
BMP #2 = 101.1961
BMP #1 = 100.0098
BMP #2 = 101.1971
BMP #1 = 100.0097
BMP #2 = 101.1966

Ah well, don't have the time to chase this down. It was nice while it lasted! I was going to average 2 sensors but will now abandon that plan for the moment.

@caternuson
Copy link
Contributor

Closing. Support for using more than one BMP3xx sensor was added with #19. An example sketch showing usage was added with #29.

Please open new issue(s) for anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants