MPL115A2 pressure temperature sensor

by travish on Tue Nov 27, 2012 2:03 pm

I recently bought the MPL115A2 sensor (https://www.adafruit.com/products/992) and am having several problems.

First of all the product page states "simply connect the VIN pin to the 5V voltage pin, GND to ground, SCL to I2C Clock (Analog 5 on an UNO) and SDA to I2C Data (Analog 4 on an UNO)". If I connect the VIN to the 5V pin I am connecting the arduino to itself and the sensor will receive no power. I am guessing that this is typo and that VIN must refer to either SDWN, RST, or VDD on the sensor but I do not know which.

The second problem is that none of the example code will run with the arduino software. Both example codes get_pt and get_pressure generate the error 'Adafruit_MPL115A2' does not name a type.

I am not trying to do anything complicated with this sensor, i would just like it to display pressure and temperature readings in the serial viewer, and maybe eventually once a certain pressure or temperature is reached to trigger a separate piece of code.
travish
 
Posts: 5
Joined: Tue Nov 20, 2012 9:08 am

Re: MPL115A2 pressure temperature sensor

by adafruit_support_bill on Tue Nov 27, 2012 4:33 pm

Yes, that is a typo :oops: I'll make sure it is fixed. What it should say is: connect the VDD pin on the module to the +5v pin on the Arduino.

'Adafruit_MPL115A2' does not name a type.

This is usually because the library was not found. Make sure you have the latest version of the library: https://github.com/adafruit/Adafruit_MPL115A2
And that it is installed in the correct location: http://www.ladyada.net/library/arduino/libraries.html

Finally, you must close all instances of the Arduino IDE, then re-open it before it will recognize the newly installed library.
User avatar
adafruit_support_bill
 
Posts: 25598
Joined: Sat Feb 07, 2009 9:11 am

Re: MPL115A2 pressure temperature sensor

by travish on Thu Dec 06, 2012 9:11 pm

Thank you for your quick response, I got it working immediately after I read you answer.

I have a second question though. I am trying to modifiy the "IfStatementConditional" example code to work with this sensor, but I am having trouble finding the place in the "Adafruit_MPL115A2" or "GetPressure" codes in which the analog reading is converted into pressure and temperature.
travish
 
Posts: 5
Joined: Tue Nov 20, 2012 9:08 am

Re: MPL115A2 pressure temperature sensor

by adafruit_support_bill on Fri Dec 07, 2012 6:26 am

It is here in Adafruit_MPL115A2.cpp. The pressure compensation calculation is described in the data sheet.

Code: Select all
void Adafruit_MPL115A2::getPT(float *P, float *T) {
  uint16_t pressure, temp;
  float pressureComp;

  // Get raw pressure and temperature settings
  Wire.beginTransmission(MPL115A2_ADDRESS);
  i2cwrite((uint8_t)MPL115A2_REGISTER_STARTCONVERSION);
  i2cwrite((uint8_t)0x00);
  Wire.endTransmission();

  // Wait a bit for the conversion to complete (3ms max)
  delay(5);

  Wire.beginTransmission(MPL115A2_ADDRESS);
  i2cwrite((uint8_t)MPL115A2_REGISTER_PRESSURE_MSB); // Register
  Wire.endTransmission();

  Wire.requestFrom(MPL115A2_ADDRESS, 4);
  pressure = (( (uint16_t) i2cread() << 8) | i2cread()) >> 6;
  temp = (( (uint16_t) i2cread() << 8) | i2cread()) >> 6;

  // See datasheet p.6 for evaluation sequence
  pressureComp = _mpl115a2_a0 + (_mpl115a2_b1 + _mpl115a2_c12 * temp ) * pressure + _mpl115a2_b2 * temp;

  // Return pressure and temperature as floating point values
  *P = ((65.0F / 1023.0F) * pressureComp) + 50.0F; // kPa
  *T = ((float) temp - 498.0F) / -5.35F +25.0F; // C
 
}

User avatar
adafruit_support_bill
 
Posts: 25598
Joined: Sat Feb 07, 2009 9:11 am

Re: MPL115A2 pressure temperature sensor

by travish on Sun Dec 09, 2012 9:11 pm

Thank you!
travish
 
Posts: 5
Joined: Tue Nov 20, 2012 9:08 am

Re: MPL115A2 pressure temperature sensor

by charlesp on Fri Mar 01, 2013 12:23 pm

Where did the equation for the temperature come from? The documentation only discusses the pressure calculation.
charlesp
 
Posts: 1
Joined: Fri Jan 25, 2013 4:48 pm

Re: MPL115A2 pressure temperature sensor

by adafruit_support_rick on Fri Mar 01, 2013 1:02 pm

I don't know. Doesn't quite look right, assuming that 0..1023 represents the operational temperature range of 105C..-40C. The datasheet doesn't seem to say anything definite about it. Perhaps it was empirically derived.

Again, if 0..1023 linearly represents 105C..-40C, then I'd expect the calculation to be
(((float)Tadc - 512.0) / -7.062) + 32.5

I don't have one here, so I can't do a reality check on that.
User avatar
adafruit_support_rick
 
Posts: 8613
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: MPL115A2 pressure temperature sensor

by park on Mon Mar 25, 2013 9:37 pm

I know this thread is a little old, but I ran across it because, for our sensor, the MPL115A2 is reporting temperatures that are about 3C too low. I assumed this might be due to the argument in the previous poster's equation. I used the stored data set my son took, reversed the calculation to get the equivalent of tadc, and then tried the suggested equation. As you can see in the graph below, neither the direct reading (labeled MPL) nor the converted reading (MPL2) are correct.

Any chance the Adafruit author of the MPL code is around to consult for temperature?

My R code, which converts the reading from what the Adafruit library produces back to the measurement, and then to proposed measurement is:
Code: Select all
tadc = (d$tempmpl_C - 25)*(-5.35) + 498
d$tempmpl_C2 = ((tadc - 512.0) / -7.062) + 32.5


Image
park
 
Posts: 13
Joined: Wed Dec 28, 2011 3:12 pm

Re: MPL115A2 pressure temperature sensor

by adafruit on Tue Mar 26, 2013 11:34 am

Hi, the temperature code was grabbed from a few app notes and a little experimentation - its not actually something that is documented officially, that's why we have the following note in the product page

"There's a basic temperature sensor inside but there's no specifications in the datasheet so we're not sure how accurate it is. "

We don't think its calibrated from one sensor to another, so each sensor must have its own slightly different equasion (?)
User avatar
adafruit
 
Posts: 11511
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: MPL115A2 pressure temperature sensor

by park on Tue Mar 26, 2013 11:29 pm

Well, here's what I can offer for our particular sensor. Maybe a few other people can gather similar data. Our data is not over a very large range, but it looks like the conversion is linear.
I fitted the thermistor temperature to the back-calculated "tadc" value, and produced a linear model for temperature (Fahrenheit) as a function of the tadc value. You all probably have a better way to handle these numbers without precision loss; I just did this floating point.

T_F = -0.307 * tadc + 234.1
or, in Celsius,
T_C = -0.1706 + 112.27

The results are consistent over our data range, as shown below.

Image

Nice little sensor, by the way. Very cute.
park
 
Posts: 13
Joined: Wed Dec 28, 2011 3:12 pm

Re: MPL115A2 pressure temperature sensor

by park on Tue Mar 26, 2013 11:32 pm

Woops, I meant to mention that the adjusted R-squared is 0.974, and I suspect would be better without the wide thermistor excursions at the beginning of the data series. Here's my R transcript, for any statisticians who also happen to be Arduino fans looking to squeeze more juice out of an MPL115A2...

Call:
lm(formula = thrmist_F ~ tadc, data = d)

Residuals:
Min 1Q Median 3Q Max
-1.3587 -0.3028 -0.0789 0.1966 9.2625

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.341e+02 2.981e-01 785.3 <2e-16 ***
tadc -3.070e-01 5.398e-04 -568.8 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.5024 on 8616 degrees of freedom
Multiple R-squared: 0.9741, Adjusted R-squared: 0.9741
F-statistic: 3.235e+05 on 1 and 8616 DF, p-value: < 2.2e-16

Cheers!
park
 
Posts: 13
Joined: Wed Dec 28, 2011 3:12 pm