MPL3115A2 Incorrect Altitude (?)

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
cmhippy
 
Posts: 15
Joined: Tue Feb 04, 2014 9:17 pm

MPL3115A2 Incorrect Altitude (?)

Post by cmhippy »

I'm testing the MPL3115A2 (inside my one story home) using the Adafruit link on the product page. Library loaded and etc.
I live in Miami, FL. I'm practically at sea level if not a half meter or so below in my area.
Altitude reading from the MPL3115A2/library/sketch is 6549x.xx meters.
The reading is definitely incorrect.
Temperature inside the house is OK.
I guess the barometer is OK also. 77.57 Inches (HG)
What is going on?
How do I correct this?
Thanks!
CMHippy

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: MPL3115A2 Incorrect Altitude (?)

Post by adafruit_support_bill »

Altitude reading from the MPL3115A2/library/sketch is 6549x.xx meters.
That looks like a software bug in the library. It looks like the library doesn't handle negative altitudes correctly.

The :getAltitude() function reads the raw altitude value as an unsigned integer, so negative numbers would appear as very large numbers. I don't have one here to test, but I suspect if you change the uint32_t to a int, it would give you a more realistic reading.

Code: Select all

float Adafruit_MPL3115A2::getAltitude() {
  uint32_t alt;

  write8(MPL3115A2_CTRL_REG1, 
	 MPL3115A2_CTRL_REG1_SBYB |
	 MPL3115A2_CTRL_REG1_OS128 |
	 MPL3115A2_CTRL_REG1_ALT);

  uint8_t sta = 0;
  while (! (sta & MPL3115A2_REGISTER_STATUS_PDR)) {
    sta = read8(MPL3115A2_REGISTER_STATUS);
    delay(10);
  }
  Wire.beginTransmission(MPL3115A2_ADDRESS); // start transmission to device 
  Wire.write(MPL3115A2_REGISTER_PRESSURE_MSB); 
  Wire.endTransmission(false); // end transmission
  
  Wire.requestFrom((uint8_t)MPL3115A2_ADDRESS, (uint8_t)3);// send data n-bytes read
  alt = Wire.read(); // receive DATA
  alt <<= 8;
  alt |= Wire.read(); // receive DATA
  alt <<= 8;
  alt |= Wire.read(); // receive DATA
  alt >>= 4;

  float altitude = alt;
  altitude /= 16.0;
  return altitude;
}

cmhippy
 
Posts: 15
Joined: Tue Feb 04, 2014 9:17 pm

Re: MPL3115A2 Incorrect Altitude (?)

Post by cmhippy »

Still having a problem with altitude. I loaded a different library and I'm still getting an incorrect altitude reading. I even went to a building and on the 4th floor I get a small negative number. The temperature reading is correct.

Is there a simplified library that I can use to further test this sensor? What else can I do to verify?

Thanks!

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”