Arduino code for the MPL115A1 Pressure Sensor (SPI)

Your source for all things Atmel.

Moderator: phalanx

Arduino code for the MPL115A1 Pressure Sensor (SPI)

Postby miah » Thu Sep 30, 2010 8:54 pm

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:
http://www.sparkfun.com/commerce/produc ... ts_id=9721

Freescale product page:
http://www.freescale.com/webapp/sps/sit ... 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.
http://www.miah.com/files/ArdMPL115A1.zip
Last edited by miah on Wed Jan 04, 2012 12:17 pm, edited 3 times in total.
miah
 
Posts: 4
Joined: Thu Sep 30, 2010 8:33 pm

Re: Arduino code for the MPL115A1 Pressure Sensor (SPI)

Postby mitchind » Wed Oct 13, 2010 10:00 am

Nice - very easy to read and understand.
Thanks for posting. :D
User avatar
mitchind
 
Posts: 57
Joined: Thu Oct 08, 2009 9:10 am

Re: Arduino code for the MPL115A1 Pressure Sensor (SPI)

Postby lovearduino » Fri Nov 12, 2010 4:29 am

hi,
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.
thanks
Phil
lovearduino
 
Posts: 1
Joined: Wed Sep 22, 2010 9:24 am

Re: Arduino code for the MPL115A1 Pressure Sensor (SPI)

Postby miah » Fri Nov 12, 2010 9:02 am

Phil,

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!
miah
 
Posts: 4
Joined: Thu Sep 30, 2010 8:33 pm

Re: Arduino code for the MPL115A1 Pressure Sensor (SPI)

Postby cyberteque » Fri Nov 26, 2010 7:20 pm

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?
cyberteque
 
Posts: 3
Joined: Fri Nov 26, 2010 6:19 pm

Re: Arduino code for the MPL115A1 Pressure Sensor (SPI)

Postby pythoncoder » Fri Jan 28, 2011 10:39 am

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
pythoncoder
 
Posts: 1
Joined: Fri Jan 28, 2011 10:18 am

Re: Arduino code for the MPL115A1 Pressure Sensor (SPI)

Postby serge » Sun Aug 21, 2011 3:23 pm

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.
serge
 
Posts: 1
Joined: Sun Aug 21, 2011 3:12 pm

Re: Arduino code for the MPL115A1 Pressure Sensor (SPI)

Postby chumann » Tue Nov 08, 2011 2:15 pm

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.
chumann
 
Posts: 1
Joined: Tue Nov 08, 2011 1:04 pm

Re: Arduino code for the MPL115A1 Pressure Sensor (SPI)

Postby huinink » Sat Dec 24, 2011 1:09 pm

Maybe this updated datasheet can help you out. I'm trying myself right now.
http://huinink.info/wp-content/uploads/ ... 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() {
  Serial.begin(115200);

  // start the SPI library:
  SPI.begin();   

  // 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 : ");
   Serial.println(baropPessure());
   delay(1000);


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

//read pressure
float baropPessure(){
  digitalWrite(chipSelectPin, LOW);
  delay(3);
    SPI.transfer(0x24);
    SPI.transfer(0x00);
    digitalWrite(chipSelectPin, HIGH);
    delay(3);
  digitalWrite(chipSelectPin, LOW);
    SPI.transfer(PRESH);
    unsigned int presH = SPI.transfer(0x00);
        delay(3);
    SPI.transfer(PRESL);
    unsigned int presL = SPI.transfer(0x00);
        delay(3);
    SPI.transfer(TEMPH);
    unsigned int tempH = SPI.transfer(0x00);
        delay(3);
    SPI.transfer(TEMPL);
    unsigned int tempL = SPI.transfer(0x00);
        delay(3);
    SPI.transfer(0x00);
      delay(3);
  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;

return(preskPa);
}
huinink
 
Posts: 1
Joined: Sat Dec 24, 2011 1:06 pm

Re: Arduino code for the MPL115A1 Pressure Sensor (SPI)

Postby radu022003 » Wed Aug 15, 2012 8:46 am

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.
radu022003
 
Posts: 5
Joined: Wed May 20, 2009 1:57 pm

Re: Arduino code for the MPL115A1 Pressure Sensor (SPI)

Postby radu022003 » Wed Aug 15, 2012 10:43 am

At least my pressure and temperature values are 0.
radu022003
 
Posts: 5
Joined: Wed May 20, 2009 1:57 pm

Re: Arduino code for the MPL115A1 Pressure Sensor (SPI)

Postby aml25 » Sun Oct 21, 2012 7:52 pm

Thank you so much for this example code. Saved me many many hours!
aml25
 
Posts: 11
Joined: Tue Mar 27, 2012 5:50 pm

Re: Arduino code for the MPL115A1 Pressure Sensor (SPI)

Postby dredwerker » Mon Feb 25, 2013 3:43 pm

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.
dredwerker
 
Posts: 1
Joined: Mon Feb 25, 2013 3:34 pm

Re: Arduino code for the MPL115A1 Pressure Sensor (SPI)

Postby MSHoerberJr » Sun Mar 10, 2013 5:25 pm

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.
MSHoerberJr
 
Posts: 1
Joined: Sun Mar 10, 2013 5:24 pm

Re: Arduino code for the MPL115A1 Pressure Sensor (SPI)

Postby jremington » Sun Mar 10, 2013 7:45 pm

I suppose that MSHoerberJr was trying to be helpful, but (s)he hasn't read the data sheet. The functionality of the MPL115A1 requires it to measure the package temperature, and that measurement is available to the user. See http://www.freescale.com/files/sensors/ ... L115A1.pdf
jremington
 
Posts: 1050
Joined: Fri Jun 15, 2007 9:41 pm
Location: Eugene, Or

Next

Return to Code

Who is online

Users browsing this forum: No registered users and 1 guest

cron