10 years, 11 months ago.

Please help me with MPL3115A2 pressure sensor

Can anybody help me writing some code for MPL3115A2 sensor? I tried for 3 days to make this sensor works but i have no results on mbed. All i need it's just data from 3 registers 0x01, 0x02, 0x03 in pressure mode (0x26 - CTRL-REG1 set for pressure mode). without conversion in temp, just bytes date and I will make the conversion. On arduino it's work just fine. Here is the link with documentations: https://www.sparkfun.com/products/11084 (also the working code for arduino can be found there).

2 Answers

10 years, 11 months ago.

The MPL3115A2 is a pressure/altitude sensor with I2C interface. It should operate on 3V3 and GND from mbed (pin40, pin1). It also needs I2C SDA and SCL (eg pin 9, 10). Normally I2C needs some pull-up Rs (4k7) to 3V3, the sparkfun board has those installed already.

The I2C slave address for the mbed libs is 0xC0.

Writing a byte to a register in the sensor is done like this:

char data[2];

data[0]=regAddr;  //selects the register
data[1]=value;      //value written to the register
i2c.write(0xC0, data, 2);

Reading a byte from the sensor is done like this:

char data[2];

data[0]=regAddr;  //selects the register
i2c.write(0xC0, data, 1, true);   // last parameter indicates that a repeated start is needed for
                                  // the subsequent read operation

i2c.read(0xC0, data, 1);          //read from the selected register
value=data[0];

Accepted Answer

thats indeed exactly what you need, you have to read the users manual of your sensor to see how he wants to be spoken to: if you have to send some commands to start measuring or if you can just read out some registers. try maybe with reading out some registers, dont matters which one, just to see if its working

char data[1];
 data[0]=regAddr;  //selects the register
i2c.read(0xC0, data, 1);          //read from the selected register
posted by Adriaan Van Steendam 13 May 2013

Thank you very much. You've save my day. It's work just fine now.

posted by Alexandru Pahomi 13 May 2013
10 years, 11 months ago.

what kind of interface is it? try to look at other examples which work with this interface

It's an I2C sensor. There are some examples on mbed but they are for MPL115A2 sensor and they don't work for my sensor. All i need to do is to convert the functions from documentation and i tried for 3 days.

posted by Alexandru Pahomi 13 May 2013