MPL3115A2 Digital Altitude / Pressure / Temperature Sensor

Wiring Up

All modules listed below appear to have I2C pullup resistors, so you need to connect VCC, GND, and SDA and SCL (INT lines are not required).

As an example, for the Pico you could use the following. Note that SDA and SCL should be connected to two pins capable of using the same I2C device (see your board's documentation page).

Pin Espruino
GND GND
VCC 3.3v (see note below)
SDA B4
SCL A8

Note: the Adafruit module has a voltage regulator, so you should connect Vin to 5V on the Espruino, and should leave 3.3v unconnected.

Software

Because measurements can take a while, the module uses callbacks when data is available.

For instance to get the altitude:

I2C3.setup({sda:B4,scl:A8});
var mpl = require("MPL3115A2").connect(I2C3);
mpl.getAltitude(function(x) {
  console.log("Altitude "+x+" m");
});

You can't set measurements going concurrently, so if you want to measure all 3, you'll need to nest your callbacks:

I2C3.setup({sda:B4,scl:A8});
var mpl = require("MPL3115A2").connect(I2C3);
mpl.getPressure(function(x) {
  console.log("Pressure "+x+" pa");
  mpl.getAltitude(function(x) {
    console.log("Altitude "+x+" m");
      mpl.getTemperature(function(x) {
      console.log("Temperature "+x+" C");
    });
  });
});

Reference

// Internal function: read register
MPL3115A2.prototype.r = function (addr, cnt) { ... }

// Internal function: write register
MPL3115A2.prototype.w = function (addr, data) { ... }

// pressure in Pascals (not kPa)
MPL3115A2.prototype.getPressure = function (callback) { ... }

// get altitude in m above sea level
MPL3115A2.prototype.getAltitude = function (callback) { ... }

// temperature in centigrade
MPL3115A2.prototype.getTemperature = function (callback) { ... }

exports.connect = function (i2c) { ... }

Using

No tutorials use this yet.

Buying

The MPL3115A2 comes in some modules that are easy to interface:

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.