MPL115A2 Pressure and Temp Breakout - bad readings below 22*C

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
kellyf
 
Posts: 2
Joined: Sat Sep 29, 2012 10:59 am

MPL115A2 Pressure and Temp Breakout - bad readings below 22*C

Post by kellyf »

I just received the MPL115A2-IC2 breakout from you and the sample "getpressure" sketch works above ~22.6*C, but below this I'm getting strange readings like -12041.0*C. Is there a narrow usable range for this sensor or do you think something else if going on?

Here is a sample from the serial monitor as it cools off a bit:

Temp (*C): 23.7 *C
Pressure (kPa): 102.2354 kPa
Temp (*C): 23.5 *C
Pressure (kPa): 102.1922 kPa
Temp (*C): 23.3 *C
Pressure (kPa): 102.1922 kPa
Temp (*C): 23.3 *C
Pressure (kPa): 102.2985 kPa
Temp (*C): 23.3 *C
Pressure (kPa): 102.1489 kPa
Temp (*C): 23.1 *C
Pressure (kPa): 102.2985 kPa
Temp (*C): 22.9 *C
Pressure (kPa): 102.2747 kPa
Temp (*C): 23.1 *C
Pressure (kPa): 102.2747 kPa
Temp (*C): 22.9 *C
Pressure (kPa): 102.2313 kPa
Temp (*C): 22.9 *C
Pressure (kPa): 102.2313 kPa
Temp (*C): 22.6 *C
Pressure (kPa): -2694.5083 kPa
Temp (*C): 22.6 *C
Pressure (kPa): -2694.5083 kPa
Temp (*C): -12035.9 *C
Pressure (kPa): -2697.3217 kPa
Temp (*C): -12036.1 *C
Pressure (kPa): -2697.3217 kPa
Temp (*C): -12036.1 *C
Pressure (kPa): -2700.0920 kPa
Temp (*C): -12036.1 *C
Pressure (kPa): -2697.4084 kPa
Temp (*C): -12036.5 *C
Pressure (kPa): -2700.1787 kPa
Temp (*C): -12036.7 *C
Pressure (kPa): -2697.4084 kPa
Temp (*C): -12036.5 *C

I ordered 2 of these and get the same results with each.

Thanks for your help

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

Re: MPL115A2 Pressure and Temp Breakout - bad readings below 22*C

Post by adafruit_support_bill »

Hmmm. :? In the library, near the end of Adafruit_MPL115A2.cpp, there is the following section of code:

Code: Select all

  pressure = ((i2cread() << 8) | i2cread()) >> 6;
  temp = ((i2cread() << 8) | i2cread()) >> 6;
  //Serial.print("t = "); Serial.println(temp, HEX);
  float centigrade = temp;
  centigrade -= 498;
  centigrade /= -5.35;
  centigrade += 25;
Un-comment the "Serial.print" line. Run your test again and post the output.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: MPL115A2 Pressure and Temp Breakout - bad readings below 22*C

Post by adafruit_support_rick »

There's something about the library I don't quite understand, but I don't have one these sensors here to test with.

If you would, go into the library, and in function readCoefficients, comment out the following lines

Code: Select all

  _mpl115a2_c12 = (float)c12coeff;
  _mpl115a2_c12 /= 4194304.0;
and replace them with an assignment of 0 to _mpl115a2_c12:

Code: Select all

//  _mpl115a2_c12 = (float)c12coeff;
//  _mpl115a2_c12 /= 4194304.0;
  _mpl115a2_c12 = 0.0;
Run that and see if your anomalous behavior goes away.

User avatar
rberni
 
Posts: 1
Joined: Tue Oct 23, 2012 10:05 pm

Re: MPL115A2 Pressure and Temp Breakout - bad readings below 22*C

Post by rberni »

Having the exact same problem, did as suggested with no change. Any other ideas?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: MPL115A2 Pressure and Temp Breakout - bad readings below 22*C

Post by adafruit_support_rick »

Can you try uncommenting the debug output as adafruit_support suggested above?

User avatar
sellensr
 
Posts: 47
Joined: Tue Nov 06, 2012 9:41 pm

Re: MPL115A2 Pressure and Temp Breakout - bad readings below 22*C

Post by sellensr »

I have the same problem and uncommented the line. It looks like temp is wrapping to a negative value (FE00). The bit shifting seems to be failing as a translation. Casting the result to a longer data type (e.g. long or unsigned or uint16_t) before the left shift makes room for things to work out. You need to change these two lines in both the pressure and temperature functions in the library from

pressure = ((i2cread() << 8) | i2cread()) >> 6;
temp = ((i2cread() << 8) | i2cread()) >> 6;

to

pressure = (((uint16_t)i2cread() << 8) | i2cread()) >> 6;
temp = (((uint16_t)i2cread() << 8) | i2cread()) >> 6;

I trust somebody from adafruit is watching and the mod will find its way into the posted library.

I may have just learned how to fork a github repository and make an update at https://github.com/sellensr/Adafruit_MPL115A2. At least I hope I didn't break anything ;-)

Old Output:

t = 1FF
Temp (*C): 22.6 *C
Pressure (kPa): 101.4271 kPa
t = 1FE
Temp (*C): 22.8 *C
Pressure (kPa): 101.4271 kPa
t = 1FE
Temp (*C): 22.8 *C
Pressure (kPa): 101.2062 kPa
t = 1FF
Temp (*C): 22.6 *C
Pressure (kPa): 101.3800 kPa
t = FE00
Temp (*C): -12035.9 *C
Pressure (kPa): 101.3166 kPa
t = 1FF
Temp (*C): 22.6 *C
Pressure (kPa): -2930.0664 kPa
t = 1FE
Temp (*C): 22.8 *C
Pressure (kPa): 101.2062 kPa
t = 1FE
Temp (*C): 22.8 *C
Pressure (kPa): 101.1592 kPa
t = FE00
Temp (*C): -12035.9 *C
Pressure (kPa): 101.4271 kPa
t = 1FF
Temp (*C): 22.6 *C
Pressure (kPa): 101.3166 kPa
t = 1FE
Temp (*C): 22.8 *C
Pressure (kPa): 101.2062 kPa
t = 1FF
Temp (*C): 22.6 *C
Pressure (kPa): 101.2696 kPa
t = 1FF
Temp (*C): 22.6 *C
Pressure (kPa): 101.1592 kPa
t = 1FE
Temp (*C): 22.8 *C
Pressure (kPa): -2927.3835 kPa
t = 1FF
Temp (*C): 22.6 *C
Pressure (kPa): 101.2062 kPa
t = 1FF
Temp (*C): 22.6 *C
Pressure (kPa): 101.3800 kPa
t = 1FE
Temp (*C): 22.8 *C
Pressure (kPa): -2930.0664 kPa
t = FE00
Temp (*C): -12035.9 *C
Pressure (kPa): -2930.0664 kPa

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

Re: MPL115A2 Pressure and Temp Breakout - bad readings below 22*C

Post by adafruit_support_bill »

If you post your fix as an issue to Github it will get onto our To-Do list. :D

User avatar
sellensr
 
Posts: 47
Joined: Tue Nov 06, 2012 9:41 pm

Re: MPL115A2 Pressure and Temp Breakout - bad readings below 22*C

Post by sellensr »

I posted it to Github, along with another fix to retrieve both T and P on the same call. It shows up on the repository as an issue and a pull request. Let me know if I got the process right, as this is my first try uploading to Github.

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

Re: MPL115A2 Pressure and Temp Breakout - bad readings below 22*C

Post by adafruit_support_bill »

Thanks. It's in the system now, so it won't fall off our radar. :)

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

Return to “Other Products from Adafruit”