FREESCALE MPL3115A2 PRESSURE SENSOR

Hi everybody,
I'm new with Arduino IDE and i would like to develop a digital barometer with the MPL3115A2 Freescale pressure sensor. This sensor is I2c communication protocol based, but i can't make it communicate with my Arduino Uno r3 easily. I try to modify the library provided by the ADAFRUIT group, which is been used for a similar I2C pressure sensor (the MPL115A2), but without any results.
Can you help me to make it run??

More info for the MPL3115A2 sensor you can find at:

Thank you all for your help.

Really appreciate!

Without a schematic and your modified source we are going to have difficulty helping you.

Hi,
thank you for your soon answer!
I try to understand the MPL115A2 library, but i haven't modify it yet because I haven't understand it very well. I've been trying to modify those equipped by ADAFRUIT to its sensor. The library files are attached in the zip file. Can You help me?
I'm keep working on it, to get any kind of brilliant idea or solution.

MPL115A2.zip (7.96 KB)

Is the problem due to connection issues between Arduino and sensor or is it software related. How have you got the sensor wired up to your Arduino?

Hi,
the problem is software related, because I don't know how to make Arduino and the sensor communicate each other. I'm trying to understand the sensor's Application Note (got it from Freescale website, and post before in this discussion), but it's really hard to understand to me, because I'm really new with this technology. I've connected the sensor to pin A4(SDA) and A5(SCL) of Arduino Uno r3, using the right Pu resistor and the correct capacitors (as wrote in the sensor datasheet). Now I've to fight with the code! =(

Thank You for your support!

Now I'm trying to receive the content of Data_PMSB_reg.
Here is my test:

#include <Wire.h>



void setup(){
/*Start communication */
Wire.begin();
Serial.begin(9600);
  	// Put sensor as standby
    Wire.beginTransmission(0x60); //0x60 is sensor address
    Wire.write(0x26); //ctrl_reg
    Wire.write(0x00); //reset_reg
    Wire.endTransmission();
    delay(10);

	// start sensor as Barometer Active
    Wire.beginTransmission(0x60);
    Wire.write(0x26);
    Wire.write(0x01); //start sensor as barometer
    Wire.endTransmission();
    delay(10);
    }

void getdata(byte *a, byte *b, byte *c){
   Wire.beginTransmission(0x60); 
   Wire.write(0x01);        // Data_PMSB_reg address
   Wire.endTransmission(); 
   // now get the data from the sensor
   Wire.requestFrom(0x60, 3); // "please send me the contents of your first three registers"
   *a = Wire.read(); // first received byte stored here
   *b = Wire.read(); // second received byte stored here
   *c = Wire.read(); // third received byte stored here
}


void loop(){
  byte aa,bb,cc;
  getdata(&aa,&bb,&cc);
  Serial.println(aa); //print aa for example
  delay(500);
}

I would like to give you some news:
with this code i could receive some strange value:

#include <Wire.h>

void setup(){
  Serial.begin(9600);
/*Start communication */
Wire.begin();

    }

void getdata(byte *a, byte *b, byte *c){
   Wire.beginTransmission(0x60); 
   Wire.write(0x01);        // Data_PMSB_reg address
   Wire.endTransmission(); 
   // now get the data from the sensor
   Wire.requestFrom(0x60, 3); // "please send me the contents of your first three registers"
   while(Wire.available()==0){
   *a = Wire.read(); // first received byte stored here
   *b = Wire.read(); // second received byte stored here
   *c = Wire.read(); // third received byte stored here
}}


void loop(){
    Serial.println("bli"); //print aa for example

    	// Put sensor as standby
    Wire.beginTransmission(0x60); //0x60 is sensor address
    Wire.write(0x26); //ctrl_reg
    Wire.write(0x00); //reset_reg
    Wire.endTransmission();
    delay(10);

	// start sensor as Barometer Active
    Wire.beginTransmission(0x60);
    Wire.write(0x26);
    Wire.write(0x01); //start sensor as barometer
    Wire.endTransmission();
    delay(10);
    
  byte aa,bb,cc;
  getdata(&aa,&bb,&cc);
  Serial.println(aa); //print aa for example
  Serial.println(bb); //print bb for example
  Serial.println(cc); //print cc for example
  Serial.println("bla"); //print aa for example

  delay(500);
}

("bli" and "bla" are test strings)

Value obtained by mine are "222 0 222" (E0 0 E0), and they never change even i change the barometer pressure. How can You explain this?

OK! I found where is the error!
I feel a little bit silly.... :astonished:
Here the correct code to communicate with the sensor

#include <Wire.h>

void setup(){
  Serial.begin(9600);
/*Start communication */
Wire.begin();

    }

void getdata(byte *a, byte *b, byte *c){
   Wire.beginTransmission(0x60); 
   Wire.write(0x01);        // Data_PMSB_reg address
   Wire.endTransmission(); 
   // now get the data from the sensor
   Wire.requestFrom(0x60, 3); // "please send me the contents of your first three registers"
   while(Wire.available()==0);
   *a = Wire.read(); // first received byte stored here
   *b = Wire.read(); // second received byte stored here
   *c = Wire.read(); // third received byte stored here
}

void loop(){
    	// Put sensor as standby
    Wire.beginTransmission(0x60); //0x60 is sensor address
    Wire.write(0x26); //ctrl_reg
    Wire.write(0x00); //reset_reg
    Wire.endTransmission();
    delay(10);

	// start sensor as Barometer Active
    Wire.beginTransmission(0x60);
    Wire.write(0x26);
    Wire.write(0x01); //start sensor as barometer
    Wire.endTransmission();
    delay(10);
    
  byte aa,bb,cc;
  getdata(&aa,&bb,&cc);
  Serial.println(aa,HEX); //print aa for example
  Serial.println(bb,HEX); //print bb for example
  Serial.println(cc,HEX); //print cc for example

  delay(5000);
}

Now i would like to convert the HEX value into Pascal: i need to create a library to do it. As wrote in the datasheet i must use this code:

void SCI_s18decun_Out (tbar_18 data)
{
byte a, b, c, d, e, f, g, h;
dword r;
/*
** Calculate
*/
a = (byte)((data.LWord>>6) / 10000000); //shift by 6
r = (data.LWord>>6) % 10000000;
b = (byte)(r / 1000000);
r %= 1000000;
c = (byte)(r / 100000);
r %= 100000;
d = (byte)(r / 10000);
r %= 10000;
e = (byte)(r / 1000);
r %= 1000;
f = (byte)(r / 100);
r %= 100;
g = (byte)(r / 10);
h = (byte)(r % 10);
** Format
*/
if (a == 0)
{
a = 0xF0;
if (b == 0)
{
b = 0xF0;
if (c == 0)
{
c = 0xF0;
if (d == 0) {
d = 0xF0;
if (e==0){
e = 0xF0;
if (f == 0){
f = 0xF0;
if ( g == 0 ) {
g = 0xF0;
}
}
}
}
}
}
}
/*
** Output result
*/
SCI_NibbOut (d);
SCI_NibbOut (e);
SCI_NibbOut (f);
SCI_NibbOut (g);
SCI_NibbOut (h);
}

and this:

void SCI_s2fracun_Out (tword data)
{
BIT_FIELD value;
word result;
byte a, b, c, d;
word r;
SCI_CharOut ('.');
/*
** Determine mantissa value
*/
result = 0;
value.Byte = data.Byte.hi;
if (value.Bit._5 == 1)
result += FRAC_2d1;
if (value.Bit._4 == 1)
result += FRAC_2d2;
/*
** Convert mantissa value to 2 decimal places
*/
r = result % 1000;
a = (byte)(result / 1000);
b = (byte)(r / 100);
r %= 100;
c = (byte)(r / 10);
d = (byte)(r % 10);
/*
** Output mantissa
*/
SCI_NibbOut (a);
SCI_NibbOut (b);
}

to convert the fractional component in OUT_P_LSB.

Could someones help me to create the ".CPP" library file?
Thank You all!

Nones could help me realizing the library for this sensor?? =(

Hi everybody,
this post reply only because I'v fixed my problem using the I2C library provided by this man! Thanks for the support!