This project is an example on how to use the Adafruit MPL115A2 Barometric Pressure + Temperature Sensor in Raspberry PI and Windows 10 IoT Core.
This sensor is great for all sorts of weather/environmental sensing. This pressure sensor is a great low-cost sensing solution for measuring barometric pressure with 1.5 hPa resolution.
https://www.adafruit.com/products/992
Temperature is calculated in degrees C, you can convert this to F by using the classic F = C * 9/5 + 32 equation.
Pressure is returned in the SI units of Pascals. 100 Pascals = 1 hPa = 1 millibar. As thi is not very precise sensor, it is not recommended to use for altimeter.
To connect this sensor to Raspberry PI you need 4 wires. Two of the wires used for voltage VDD (+3V from Raspberry) and ground GND and remaining two are used for data. As this is digital sensor, it uses I2C protocol to communicate with the Raspberry. For I2C we need two wires, Data (SDA) and Clock (SCL). Connect sensor SDA and SCL pins accordingly to Raspberry SDA and SCL pins.
I made it very simple for you. You just need to add NuGet package RobootikaCOM.MPL115A2 to your project and you are almost done :)
After adding these NuGet packages, you just need to write 3 lines of code.
- Add reference to this module
using RobootikaCOM.MPL115A2;
- Create an object for sensor:
private MPL115A2 MPL115A2Sensor = new MPL115A2();
- Write a while-loop, to read data from the sensor every 1 sec.
while (true)
{
double pressure = MPL115A2Sensor.getPressure(); //kPa
double temperature = MPL115A2Sensor.getTemperature();
Task.Delay(1000).Wait();
}
Final code looks like this.
If you run it, you do not see anything, because it just reads the data, but it doesnt show it anywhere. You need to integrate this project with my other example, where I teach how to send this data into Azure.
using System;
using Windows.ApplicationModel.Background;
using System.Threading.Tasks;
using RobootikaCOM.MPL115A2;
namespace LessonTempertureMPL115A2
{
public sealed class StartupTask : IBackgroundTask
{
// MPL115A2 Sensor
private MPL115A2 MPL115A2Sensor = new MPL115A2();
public void Run(IBackgroundTaskInstance taskInstance)
{
while (true)
{
double pressure = MPL115A2Sensor.getPressure(); //kPa
double temperature = MPL115A2Sensor.getTemperature();
Task.Delay(1000).Wait();
}
}
}
}
I2C address is used to communicate with the sensor. Many sensors have I2C address hardcoded, and this sensor exactly this. You cannot change I2C address, it is fixed to 0x60.
- PCB weight: 0.61g
- Vin: 2.4 to 5.5 VDC
- Logic: 3 to 5V compliant
- Pressure sensing range: 500-1150 hPa (up to 10Km altitude)
- 1.5 hPa / 50 m altitude resolution
- This board/chip uses I2C 7-bit address 0x60