MPL115A1 barometer for the BBC micro:bit
MicroPython program for the BBC micro:bit that displays pressure and temperature readings from the NXP MPL115A1 SPI-connected sensor.
The program was adapted for the micro:bit from this code for the I2C version of the sensor (MPL115A2): https://github.com/FaBoPlatform/FaBoBarometer-MPL115-Python
Connect the MPL115A1 to the micro:bit. The default micro:bit SPI pins are shown below, but you can select different pins in the program.
|MPL115A1 pin||micro:bit pin|
Edit the program to set
MY_ALTITUDE to your altitude (metres above mean sea level).
Flash the program onto the micro:bit.
Check the values displayed:
Tshould be sensible.
Pshould be 1000hPa plus or minus 100.
P0should be lower than
If you are using a ready-made MPL115A1 breakout board, the following connections may already have been taken care of. If not, connect the pins as shown.
|CAP||1uF capacitor to GND|
The MPL115A1 datasheet says ...
The sensor die is sensitive to light exposure. Direct light exposure through the port hole can lead to varied accuracy of pressure measurement. Avoid such exposure to the port during normal operation.
Two items need further investigation:
Forum threads about the MPL115A1 somewhere that claimed the temperature calculation algorithm in the datasheet is wrong, giving consistently low readings. See https://github.com/hackscribble/microbit-MPL115A1-barometer/issues/1
This version of the code retains the formula for calculating sea level pressure (P0) that was used in the original program. It is different from that shown in source  below, which factors in temperature as well as altitude. See https://github.com/hackscribble/microbit-MPL115A1-barometer/issues/2
1.0 (5 May 2017)
Background on MicroPython SPI: https://learn.adafruit.com/micropython-hardware-spi-devices/spi-master.
Information about adjusting pressure for altitude: http://keisan.casio.com/exec/system/1224575267