SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By miah
This sketch shows how to read pressure and temperature from the MPL115A1 Pressure Sensor (SPI version) and as a bonus throws in a simple altimeter. I got the breakout board with this device on it yesterday and found the provided sample code a little complex for my simple mind. This sketch should be very cut-pasteable for those who just want to get data from the thing.

SparkFun product page: ... ts_id=9721

Freescale product page: ... de=MPL115A

The document AN3785 from the Freescale page was very helpful for understanding how to use this device.

[Edit] It seems the forum file attachments are not working. I've posted the file elsewhere.
Last edited by miah on Wed Jan 04, 2012 12:17 pm, edited 3 times in total.
By lovearduino
I have your code running (thanks!), but i'm not seeing any activity from the sensor. I get the same result (7.25 psi) if I have the sensor connected or or not. I probably somehow burned up the sensor (i have a warehouse full of electronic things I have bricked), but if you have seen this before, i'd appreciate any advice.
By miah

I can really only offer generic advice. The value that you're showing (7.25 psi) is what you get when the software reads zeros off the device. The range is 50-115 kPa which is 7.25-16.68 psi. So either the part is dead or not connected correctly. Here are some suggestions:

1. Check the PCB. I had to actually re-solder one of the surface mount components on mine, the two caps on the board had been accidentally connected together on one end during the surface mount process. So make sure the layout and soldering job matches the schematic for the board. The schematic is on the sparkfun product page.

2. Check your wiring job. Make sure you're using 5V for VCC on a 5V Arduino or 3.3V for VCC on a 3.3V Arduino. Make sure your connections are good. I ended up soldering on headers and plugging the thing into a breadboard because my IC test clips were flakey. Make sure you've connected the right pins, it's way too easy to get them mixed up.

Good Luck!
By cyberteque
I'm trying the example code on my Arduino Mega, running the breakout board @5V.
But the temperature and pressure sensors are reading low.
Right now the MPL115A1 is reporting 14C and a alcohol thermometer on my desk is showing 19C.
The pressure reading is 97.7kPa, 733mmHg, but the nearest automated weather station is reporting 1010.9hPa or 101.09kPa.

Here are 4 lines of output from the sketch

1176 ft | 358 m | 28.78 in Hg | 731 mm Hg | 14.14 psia | 97.5 kPa | 13.6 C | 56.5 F
1194 ft | 363 m | 28.77 in Hg | 731 mm Hg | 14.13 psia | 97.4 kPa | 13.6 C | 56.5 F
1105 ft | 336 m | 28.86 in Hg | 733 mm Hg | 14.17 psia | 97.7 kPa | 13.8 C | 56.8 F
1141 ft | 347 m | 28.82 in Hg | 732 mm Hg | 14.15 psia | 97.6 kPa | 13.6 C | 56.5 F

When I take my other Mega outside that has an EM-406 GPS module, the altitude reads as 320m.

On the FreeScale site there is a warning about shining direct light through the MPL115A1's window.
When I soldered some header pins onto the breakout board I used my desklamp.
I was wondering how much light is too much?

Has anyone else seen this behaviour in the MPL115A1?
By pythoncoder
I have used this code to interface the MPL1151A1 sensor to Arduino. I'm finding that the pressure readings are accurate, but the temperature consistently reads approximately 6 degrees Celcius too low. I've gone through the code carefully comparing it to the datasheet: I can find no fault. I also tried allowing the chip more time to perform the conversion but nothing makes any difference. Oddly the datasheet doesn't specify the temperature accuracy, but six degrees seems a long way out.

It seems odd that the chip can do the hard job of reading pressure yet yield poor results on temperature. My query is more from curiosity than anything else: I'd be much more concerned if the pressure readings were wrong and decent temperature sensors are cheap enough. But has anyone else encountered this problem?

As for the effects of light, my reading of the datasheet and my understanding of semiconductor technology is that the effects are not permanent - it can simply affect the reading.

Regards, Pete
By serge
Concerning the real temperature computation, the datasheet is misleading. It incorrectly states that sensor ADC count at 25C is 472. In my case the count at 24C is 510 and the sensor sensitivity is about 5.5 counts/C vs. 5.35 from the datasheet. This way for the ADC count K one gets K = 510 - 5.5*(T - 24), and computing temperature from this equation becomes accurate. For your sensor the constants 510 and 5.5 might be different. A calibration in two temperature points is needed to resolve the issue.
By huinink
Maybe this updated datasheet can help you out. I'm trying myself right now. ... 1_10_6.pdf

this is the code I came up with. It works nicely and is off 0,2% near by measurement:
Programming is bad though. Just started programming....
Code: Select all
MPL115A1 sparkfun breakout baropressure meter
 SDN       : pin 7
 CSN       : pin 10
 SDI/MOSI  : pin 11
 SDO/MISO  : pin 12
 SCK       : pin 13

// the sensor communicates using SPI, so include the library:
#include <SPI.h>

#define PRESH	0x80
#define	PRESL	0x82
#define	TEMPH	0x84
#define	TEMPL	0x86

#define A0MSB	0x88
#define A0LSB	0x8A
#define B1MSB	0x8C
#define B1LSB	0x8E
#define	B2MSB	0x90
#define B2LSB	0x92
#define C12MSB	0x94
#define	C12LSB	0x96

#define CONVERT	0x24	

#define chipSelectPin 10
#define shutDown 7

float A0_;
float B1_;
float B2_;
float C12_;

void setup() {

  // start the SPI library:

  // initalize the data ready and chip select pins:
  pinMode(shutDown, OUTPUT);
  digitalWrite(shutDown, HIGH);
  pinMode(chipSelectPin, OUTPUT);
  digitalWrite(chipSelectPin, HIGH);
  delay (10);
  // read registers that contain the chip-unique parameters to do the math
  unsigned int A0H = readRegister(A0MSB);
  unsigned int A0L = readRegister(A0LSB);
         A0_ = (A0H << 5) + (A0L >> 3) + (A0L & 0x07) / 8.0;
  unsigned int B1H = readRegister(B1MSB);
  unsigned int B1L = readRegister(B1LSB);
          B1_ = ( ( ( (B1H & 0x1F) * 0x100)+B1L) / 8192.0) - 3 ;
  unsigned int B2H = readRegister(B2MSB);
  unsigned int B2L = readRegister(B2LSB);
          B2_ = ( ( ( (B2H - 0x80) << 8) + B2L) / 16384.0 ) - 2 ;
  unsigned int C12H = readRegister(C12MSB);
  unsigned int C12L = readRegister(C12LSB);
          C12_ = ( ( ( C12H * 0x100 ) + C12L) / 16777216.0 )  ;

void loop() {
   Serial.print("de druk is : ");

//Read registers
unsigned int readRegister(byte thisRegister ) {
  unsigned int result = 0;   // result to return
  digitalWrite(chipSelectPin, LOW);
    result = SPI.transfer(0x00);
  digitalWrite(chipSelectPin, HIGH);

//read pressure
float baropPessure(){
  digitalWrite(chipSelectPin, LOW);
    digitalWrite(chipSelectPin, HIGH);
  digitalWrite(chipSelectPin, LOW);
    unsigned int presH = SPI.transfer(0x00);
    unsigned int presL = SPI.transfer(0x00);
    unsigned int tempH = SPI.transfer(0x00);
    unsigned int tempL = SPI.transfer(0x00);
  digitalWrite(chipSelectPin, HIGH);

  unsigned long press = ((presH *256) + presL)/64;
  unsigned long temp  = ((tempH *256) + tempL)/64;

  float pressure = A0_+(B1_+C12_*temp)*press+B2_*temp;
  float preskPa = pressure*  (65.0/1023.0)+50.0;

By radu022003
Hello, i just started to work with this sensor MPL115A1 and an ARM M4 from ST Microelectronics.

My main issue is that when i'm sending the convert command to the sensor via SPI it shuts down or blocks.

I can read the coefficients, but only when i'm sendig the 0x24 command, it goes off.

I need to shutdown (from button) and then back to normal to read the coefficients again, other wise i can't read the coefficients from sensor.

Where could be the problem?

Thank you.
By dredwerker
chumann wrote:The example code referenced for download in the first post no longer seems to be available for download. By any chance does some one have this that they could repost? Thanks.
I second that. I wouldnt mind the temperature part.

Thanks for the barometric code that is there.

Mine seems to be saying 52.03 all the time. Any ideas what valid ranges should be ? I am in Melbourne.
By MSHoerberJr
I do not believe there is a temp sensor on this board. Im using a DC18B20 OneWire digital temp sensor and works great!
I am wrong. Good to know. I am trying to get this thing to work with my Nano 328. I am using the SPI files from the download site.

I am getting:

stk500_getsync(): not in sync: resp=0x30
Last edited by MSHoerberJr on Sun Mar 10, 2013 8:52 pm, edited 1 time in total.
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]