0

MPL3115A2 Registers Altitude Decline When Not Moving, Temp/P
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

MPL3115A2 Registers Altitude Decline When Not Moving, Temp/P

by doberhaus on Sun Aug 11, 2019 9:50 am

Hey all,

I left my MPL3115A2 altimeter running in my room overnight. When I looked at the data, the pressure and temperature looked correct, but as you can see in this chart (red line), the device registered a steady loss of altitude over the course of the night, despite remaining stationary on my desk.

Any idea why this is happening or how to correct for it?

chart (1).png
chart (1).png (22.52 KiB) Viewed 116 times

doberhaus
 
Posts: 4
Joined: Sun Aug 11, 2019 12:40 am

Re: MPL3115A2 Registers Altitude Decline When Not Moving, Te

by doberhaus on Sun Aug 11, 2019 12:56 pm

So after doing some reading, it seems like this could be due to fluctuations in the pressure inside. So I took the device outside for awhile and got more consistent altitude (it was sitting on a table, so this looks about right).

Still, it was registering an altitude of -30m. I'm just above sealevel (~11m).

Any idea why it would be returning these values and how to calibrate?

chart (2).png
chart (2).png (17.11 KiB) Viewed 106 times

doberhaus
 
Posts: 4
Joined: Sun Aug 11, 2019 12:40 am

Re: MPL3115A2 Registers Altitude Decline When Not Moving, Te

by adafruit_support_mike on Sun Aug 11, 2019 2:25 pm

Altitude is calculated using the pressure sensor, and changes with the barometric pressure.

If you know the sensor is staying at the same altitude, you can use the changes to estimate changes in the barometric pressure.

If you have the option to connect to a weather service and get a current pressure reading, you can use that to compensate the altitude readings.

adafruit_support_mike
 
Posts: 58798
Joined: Thu Feb 11, 2010 2:51 pm

Re: MPL3115A2 Registers Altitude Decline When Not Moving, Te

by doberhaus on Fri Aug 30, 2019 12:05 pm

Thanks do you have a link that would show how to go about compensating for the pressure in the code once I have the reading from the local weather service?

The problem is that the barometric pressure reading seems to be correct on the MPL3115A2. For example, I've attached a graph that shows the reading after leaving it outside for 11 hours last night.

Blue = barometer, which is correct (1.01 bar)
Yellow = temperature in C (shows correct variation throughout the night)
Red = altitude (totally incorrect, starts off negative and shows the device moving significantly lower throughout the night even though the device wasn't moving)

chart (3).png
chart (3).png (12.5 KiB) Viewed 57 times



Here is the code that is running on the arduino:

Code: Select all | TOGGLE FULL SIZE
#include <DS3231.h>
#include <SD.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_MPL3115A2.h>
int switchState = 0;
DS3231  rtc(SDA, SCL);
File myFile;
int pinCS = 10;
Adafruit_MPL3115A2 baro = Adafruit_MPL3115A2();
void setup() {
  pinMode(3, OUTPUT);
  pinMode(2, INPUT);
  Serial.begin(9600); // Start the serial terminal
  pinMode(pinCS, OUTPUT);
 
  Serial.println("ASAN APHRODITE III ALTIMETER");
  Serial.println();
 
 // SD Card Initialization
if (SD.begin())
  {
    Serial.println("SD card is ready to use.");
  } else
  {
    Serial.println("SD card initialization failed");
    return;
  }
  rtc.begin();
  rtc.setTime(0, 0, 0);     // Set the time to 12:00:00 (24hr format)
}
void loop() {
 switchState = digitalRead(2);
  if (switchState == HIGH) {
  digitalWrite(3, HIGH);
Serial.println(rtc.getTimeStr());
if (! baro.begin()) {
    Serial.println("Couldnt find sensor");
    return;
  }
 
  float pascals = baro.getPressure();
  Serial.print(pascals/100000); Serial.println(" bar");
  float altm = baro.getAltitude();
  Serial.print(altm); Serial.println(" meters");
  float tempC = baro.getTemperature();
  Serial.print(tempC); Serial.println("*C");
   myFile = SD.open("test.txt", FILE_WRITE);
  if (myFile) {   
    myFile.print(rtc.getTimeStr());
    myFile.print(",  ");
    myFile.print(pascals/100000);
    myFile.print(", ");
    myFile.print(altm);
    myFile.print(", ");
    myFile.println(tempC);
    myFile.close(); // close the file
  }
 else {
    Serial.println("error opening test.txt");
  }
  }
 else {digitalWrite(3, LOW);
  delay(250);
 
 
 }}
Last edited by doberhaus on Fri Aug 30, 2019 12:15 pm, edited 1 time in total.

doberhaus
 
Posts: 4
Joined: Sun Aug 11, 2019 12:40 am

Re: MPL3115A2 Registers Altitude Decline When Not Moving, Te

by millercommamatt on Fri Aug 30, 2019 12:15 pm

To determine altitude with a pressure sensor you need to know temperature and the equivalent mean sea-level pressure. Pressure and temperature change all the time so you have to constantly update the values you use. If your project has internet connectivity, you could query something like the DarkSky API. Expect errors on the order of dozens of meters.

If you only need your project to be accurate for a short amount of time (< 60 min.), you can hard code the values in your code. You'll get the best results if you get everything working at a known altitude so you can make adjustments since the location you are using as a reference will likely have a different MSLP and temp even if it's close by.

millercommamatt
 
Posts: 410
Joined: Tue Jul 31, 2018 4:57 pm

Re: MPL3115A2 Registers Altitude Decline When Not Moving, Te

by doberhaus on Fri Aug 30, 2019 12:18 pm

Thanks! I'm pretty new to this--do you have an example of how these values could be hard coded into the arduino code?

The problem is this is going to be used on a high altitude balloon to track altitude. Since we're talking ~100,000 ft, a few meters won't make a big difference, but it would be nice to get it as accurate as possible. Obviously the balloon flight precludes getting pressure/temp values from the internet, so I'm assuming I'd just have to add the values into the code directly before we launch it.

doberhaus
 
Posts: 4
Joined: Sun Aug 11, 2019 12:40 am

Re: MPL3115A2 Registers Altitude Decline When Not Moving, Te

by millercommamatt on Fri Aug 30, 2019 12:29 pm

You're going to want GPS for balloon altitude. This sensors is only good up to 500 hPa. 100,000 feet is around 11 hPa.

millercommamatt
 
Posts: 410
Joined: Tue Jul 31, 2018 4:57 pm

Please be positive and constructive with your questions and comments.