Remarks
Mpl3115a2 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The MPL3115A2 is a barometric pressure sensor capable of reading both temperature and temperature compensated pressure reading. This sensor includes the following features:
- I2C digital interface
- 24-bit ADC
- Altitude and pressure measurements
- Temperature sensor
Sample projects available on GitHub
Purchasing
The MPL3115A2 is available on breakout boards and a weather shield:
Code Example
Mpl3115a2? sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
sensor = new Mpl3115a2(Device.CreateI2cBus());
var consumer = Mpl3115a2.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
},
filter: result =>
{
if (result.Old?.Temperature is { } oldTemp &&
result.New.Temperature is { } newTemp)
{
return (newTemp - oldTemp).Abs().Celsius > 0.5; // returns true if > 0.5°C change.
}
return false;
}
);
sensor.Subscribe(consumer);
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Temperature: {result.New.Temperature?.Celsius:N2}C");
Resolver.Log.Info($" Pressure: {result.New.Pressure?.Bar:N2}bar");
};
return Task.CompletedTask;
}
public override async Task Run()
{
if (sensor == null) { return; }
var conditions = await sensor.Read();
Resolver.Log.Info($"Temperature: {conditions.Temperature?.Celsius}°C, Pressure: {conditions.Pressure?.Pascal}Pa");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Interrupt Mode
The application below connects the MPL3115A2 to two interrupt handlers. These interrupt handlers (events) will display the Temperature
and Pressure
properties when the handlers are triggered. The sensor is checked every 100 milliseconds (the default for the updatePeriod
).
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Interrupt Example");
var mpl3115a2 = new MPL3115A2(temperatureChangeNotificationThreshold: 0.1F);
mpl3115a2.TemperatureChanged += (s, e) =>
{
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2"));
};
mpl3115a2.PressureChanged += (s, e) =>
{
Console.WriteLine("Pressure: " + mpl3115a2.Pressure.ToString("f2"));
};
Thread.Sleep(Timeout.Infinite);
}
}
Polling Mode
The following application reads the temperature and pressure every second and displays the result on the debug console:
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Polling Example");
var mpl3115a2 = new MPL3115A2(updateInterval: 0);
while (true)
{
mpl3115a2.Update();
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2") + ", Pressure: " + mpl3115a2.Pressure.ToString("f2"));
Thread.Sleep(1000);
}
}
}
Wiring Example
MPL3115A2 configured for polling more data reads:
Syntax
public class Mpl3115a2 : ByteCommsSensorBase<(Temperature? Temperature, Pressure? Pressure)>, IObservable<IChangeResult<(Temperature? Temperature, Pressure? Pressure)>>, ISamplingSensor<(Temperature? Temperature, Pressure? Pressure)>, ISensor<(Temperature? Temperature, Pressure? Pressure)>, IDisposable, ITemperatureSensor, ISamplingSensor<Temperature>, ISensor<Temperature>, IBarometricPressureSensor, ISamplingSensor<Pressure>, ISensor<Pressure>, II2cPeripheral
Constructors
Mpl3115a2(II2cBus, byte)
Create a new MPL3115A2 object with the default address and speed settings
Declaration
public Mpl3115a2(II2cBus i2cBus, byte address = 96)
Parameters
Type | Name | Description |
---|---|---|
II2cBus | i2cBus | I2cBus (Maximum is 400 kHz) |
byte | address | Address of the sensor (default = 0x60) |
Remarks
Mpl3115a2 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The MPL3115A2 is a barometric pressure sensor capable of reading both temperature and temperature compensated pressure reading. This sensor includes the following features:
- I2C digital interface
- 24-bit ADC
- Altitude and pressure measurements
- Temperature sensor
Sample projects available on GitHub
Purchasing
The MPL3115A2 is available on breakout boards and a weather shield:
Code Example
Mpl3115a2? sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
sensor = new Mpl3115a2(Device.CreateI2cBus());
var consumer = Mpl3115a2.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
},
filter: result =>
{
if (result.Old?.Temperature is { } oldTemp &&
result.New.Temperature is { } newTemp)
{
return (newTemp - oldTemp).Abs().Celsius > 0.5; // returns true if > 0.5°C change.
}
return false;
}
);
sensor.Subscribe(consumer);
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Temperature: {result.New.Temperature?.Celsius:N2}C");
Resolver.Log.Info($" Pressure: {result.New.Pressure?.Bar:N2}bar");
};
return Task.CompletedTask;
}
public override async Task Run()
{
if (sensor == null) { return; }
var conditions = await sensor.Read();
Resolver.Log.Info($"Temperature: {conditions.Temperature?.Celsius}°C, Pressure: {conditions.Pressure?.Pascal}Pa");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Interrupt Mode
The application below connects the MPL3115A2 to two interrupt handlers. These interrupt handlers (events) will display the Temperature
and Pressure
properties when the handlers are triggered. The sensor is checked every 100 milliseconds (the default for the updatePeriod
).
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Interrupt Example");
var mpl3115a2 = new MPL3115A2(temperatureChangeNotificationThreshold: 0.1F);
mpl3115a2.TemperatureChanged += (s, e) =>
{
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2"));
};
mpl3115a2.PressureChanged += (s, e) =>
{
Console.WriteLine("Pressure: " + mpl3115a2.Pressure.ToString("f2"));
};
Thread.Sleep(Timeout.Infinite);
}
}
Polling Mode
The following application reads the temperature and pressure every second and displays the result on the debug console:
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Polling Example");
var mpl3115a2 = new MPL3115A2(updateInterval: 0);
while (true)
{
mpl3115a2.Update();
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2") + ", Pressure: " + mpl3115a2.Pressure.ToString("f2"));
Thread.Sleep(1000);
}
}
}
Wiring Example
MPL3115A2 configured for polling more data reads:
Properties
DefaultI2cAddress
The default I2C address for the peripheral
Declaration
public byte DefaultI2cAddress { get; }
Property Value
Type | Description |
---|---|
byte |
Remarks
Mpl3115a2 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The MPL3115A2 is a barometric pressure sensor capable of reading both temperature and temperature compensated pressure reading. This sensor includes the following features:
- I2C digital interface
- 24-bit ADC
- Altitude and pressure measurements
- Temperature sensor
Sample projects available on GitHub
Purchasing
The MPL3115A2 is available on breakout boards and a weather shield:
Code Example
Mpl3115a2? sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
sensor = new Mpl3115a2(Device.CreateI2cBus());
var consumer = Mpl3115a2.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
},
filter: result =>
{
if (result.Old?.Temperature is { } oldTemp &&
result.New.Temperature is { } newTemp)
{
return (newTemp - oldTemp).Abs().Celsius > 0.5; // returns true if > 0.5°C change.
}
return false;
}
);
sensor.Subscribe(consumer);
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Temperature: {result.New.Temperature?.Celsius:N2}C");
Resolver.Log.Info($" Pressure: {result.New.Pressure?.Bar:N2}bar");
};
return Task.CompletedTask;
}
public override async Task Run()
{
if (sensor == null) { return; }
var conditions = await sensor.Read();
Resolver.Log.Info($"Temperature: {conditions.Temperature?.Celsius}°C, Pressure: {conditions.Pressure?.Pascal}Pa");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Interrupt Mode
The application below connects the MPL3115A2 to two interrupt handlers. These interrupt handlers (events) will display the Temperature
and Pressure
properties when the handlers are triggered. The sensor is checked every 100 milliseconds (the default for the updatePeriod
).
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Interrupt Example");
var mpl3115a2 = new MPL3115A2(temperatureChangeNotificationThreshold: 0.1F);
mpl3115a2.TemperatureChanged += (s, e) =>
{
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2"));
};
mpl3115a2.PressureChanged += (s, e) =>
{
Console.WriteLine("Pressure: " + mpl3115a2.Pressure.ToString("f2"));
};
Thread.Sleep(Timeout.Infinite);
}
}
Polling Mode
The following application reads the temperature and pressure every second and displays the result on the debug console:
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Polling Example");
var mpl3115a2 = new MPL3115A2(updateInterval: 0);
while (true)
{
mpl3115a2.Update();
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2") + ", Pressure: " + mpl3115a2.Pressure.ToString("f2"));
Thread.Sleep(1000);
}
}
}
Wiring Example
MPL3115A2 configured for polling more data reads:
Pressure
The pressure, from the last reading.
Declaration
public Pressure? Pressure { get; }
Property Value
Type | Description |
---|---|
Pressure? |
Remarks
Mpl3115a2 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The MPL3115A2 is a barometric pressure sensor capable of reading both temperature and temperature compensated pressure reading. This sensor includes the following features:
- I2C digital interface
- 24-bit ADC
- Altitude and pressure measurements
- Temperature sensor
Sample projects available on GitHub
Purchasing
The MPL3115A2 is available on breakout boards and a weather shield:
Code Example
Mpl3115a2? sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
sensor = new Mpl3115a2(Device.CreateI2cBus());
var consumer = Mpl3115a2.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
},
filter: result =>
{
if (result.Old?.Temperature is { } oldTemp &&
result.New.Temperature is { } newTemp)
{
return (newTemp - oldTemp).Abs().Celsius > 0.5; // returns true if > 0.5°C change.
}
return false;
}
);
sensor.Subscribe(consumer);
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Temperature: {result.New.Temperature?.Celsius:N2}C");
Resolver.Log.Info($" Pressure: {result.New.Pressure?.Bar:N2}bar");
};
return Task.CompletedTask;
}
public override async Task Run()
{
if (sensor == null) { return; }
var conditions = await sensor.Read();
Resolver.Log.Info($"Temperature: {conditions.Temperature?.Celsius}°C, Pressure: {conditions.Pressure?.Pascal}Pa");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Interrupt Mode
The application below connects the MPL3115A2 to two interrupt handlers. These interrupt handlers (events) will display the Temperature
and Pressure
properties when the handlers are triggered. The sensor is checked every 100 milliseconds (the default for the updatePeriod
).
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Interrupt Example");
var mpl3115a2 = new MPL3115A2(temperatureChangeNotificationThreshold: 0.1F);
mpl3115a2.TemperatureChanged += (s, e) =>
{
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2"));
};
mpl3115a2.PressureChanged += (s, e) =>
{
Console.WriteLine("Pressure: " + mpl3115a2.Pressure.ToString("f2"));
};
Thread.Sleep(Timeout.Infinite);
}
}
Polling Mode
The following application reads the temperature and pressure every second and displays the result on the debug console:
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Polling Example");
var mpl3115a2 = new MPL3115A2(updateInterval: 0);
while (true)
{
mpl3115a2.Update();
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2") + ", Pressure: " + mpl3115a2.Pressure.ToString("f2"));
Thread.Sleep(1000);
}
}
}
Wiring Example
MPL3115A2 configured for polling more data reads:
Standby
Check if the part is in standby mode or change the standby mode.
Declaration
public bool Standby { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Changes the SBYB bit in Control register 1 to put the device to sleep or to allow measurements to be made.
Status
Get the status register from the sensor
Declaration
public byte Status { get; }
Property Value
Type | Description |
---|---|
byte |
Remarks
Mpl3115a2 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The MPL3115A2 is a barometric pressure sensor capable of reading both temperature and temperature compensated pressure reading. This sensor includes the following features:
- I2C digital interface
- 24-bit ADC
- Altitude and pressure measurements
- Temperature sensor
Sample projects available on GitHub
Purchasing
The MPL3115A2 is available on breakout boards and a weather shield:
Code Example
Mpl3115a2? sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
sensor = new Mpl3115a2(Device.CreateI2cBus());
var consumer = Mpl3115a2.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
},
filter: result =>
{
if (result.Old?.Temperature is { } oldTemp &&
result.New.Temperature is { } newTemp)
{
return (newTemp - oldTemp).Abs().Celsius > 0.5; // returns true if > 0.5°C change.
}
return false;
}
);
sensor.Subscribe(consumer);
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Temperature: {result.New.Temperature?.Celsius:N2}C");
Resolver.Log.Info($" Pressure: {result.New.Pressure?.Bar:N2}bar");
};
return Task.CompletedTask;
}
public override async Task Run()
{
if (sensor == null) { return; }
var conditions = await sensor.Read();
Resolver.Log.Info($"Temperature: {conditions.Temperature?.Celsius}°C, Pressure: {conditions.Pressure?.Pascal}Pa");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Interrupt Mode
The application below connects the MPL3115A2 to two interrupt handlers. These interrupt handlers (events) will display the Temperature
and Pressure
properties when the handlers are triggered. The sensor is checked every 100 milliseconds (the default for the updatePeriod
).
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Interrupt Example");
var mpl3115a2 = new MPL3115A2(temperatureChangeNotificationThreshold: 0.1F);
mpl3115a2.TemperatureChanged += (s, e) =>
{
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2"));
};
mpl3115a2.PressureChanged += (s, e) =>
{
Console.WriteLine("Pressure: " + mpl3115a2.Pressure.ToString("f2"));
};
Thread.Sleep(Timeout.Infinite);
}
}
Polling Mode
The following application reads the temperature and pressure every second and displays the result on the debug console:
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Polling Example");
var mpl3115a2 = new MPL3115A2(updateInterval: 0);
while (true)
{
mpl3115a2.Update();
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2") + ", Pressure: " + mpl3115a2.Pressure.ToString("f2"));
Thread.Sleep(1000);
}
}
}
Wiring Example
MPL3115A2 configured for polling more data reads:
Temperature
The temperature, from the last reading.
Declaration
public Temperature? Temperature { get; }
Property Value
Type | Description |
---|---|
Temperature? |
Remarks
Mpl3115a2 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The MPL3115A2 is a barometric pressure sensor capable of reading both temperature and temperature compensated pressure reading. This sensor includes the following features:
- I2C digital interface
- 24-bit ADC
- Altitude and pressure measurements
- Temperature sensor
Sample projects available on GitHub
Purchasing
The MPL3115A2 is available on breakout boards and a weather shield:
Code Example
Mpl3115a2? sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
sensor = new Mpl3115a2(Device.CreateI2cBus());
var consumer = Mpl3115a2.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
},
filter: result =>
{
if (result.Old?.Temperature is { } oldTemp &&
result.New.Temperature is { } newTemp)
{
return (newTemp - oldTemp).Abs().Celsius > 0.5; // returns true if > 0.5°C change.
}
return false;
}
);
sensor.Subscribe(consumer);
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Temperature: {result.New.Temperature?.Celsius:N2}C");
Resolver.Log.Info($" Pressure: {result.New.Pressure?.Bar:N2}bar");
};
return Task.CompletedTask;
}
public override async Task Run()
{
if (sensor == null) { return; }
var conditions = await sensor.Read();
Resolver.Log.Info($"Temperature: {conditions.Temperature?.Celsius}°C, Pressure: {conditions.Pressure?.Pascal}Pa");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Interrupt Mode
The application below connects the MPL3115A2 to two interrupt handlers. These interrupt handlers (events) will display the Temperature
and Pressure
properties when the handlers are triggered. The sensor is checked every 100 milliseconds (the default for the updatePeriod
).
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Interrupt Example");
var mpl3115a2 = new MPL3115A2(temperatureChangeNotificationThreshold: 0.1F);
mpl3115a2.TemperatureChanged += (s, e) =>
{
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2"));
};
mpl3115a2.PressureChanged += (s, e) =>
{
Console.WriteLine("Pressure: " + mpl3115a2.Pressure.ToString("f2"));
};
Thread.Sleep(Timeout.Infinite);
}
}
Polling Mode
The following application reads the temperature and pressure every second and displays the result on the debug console:
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Polling Example");
var mpl3115a2 = new MPL3115A2(updateInterval: 0);
while (true)
{
mpl3115a2.Update();
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2") + ", Pressure: " + mpl3115a2.Pressure.ToString("f2"));
Thread.Sleep(1000);
}
}
}
Wiring Example
MPL3115A2 configured for polling more data reads:
Methods
RaiseEventsAndNotify(IChangeResult<(Temperature? Temperature, Pressure? Pressure)>)
Inheritance-safe way to raise events and notify observers.
Declaration
protected override void RaiseEventsAndNotify(IChangeResult<(Temperature? Temperature, Pressure? Pressure)> changeResult)
Parameters
Type | Name | Description |
---|---|---|
IChangeResult<(Temperature? Temperature, Pressure? Pressure)> | changeResult |
Overrides
Remarks
Mpl3115a2 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The MPL3115A2 is a barometric pressure sensor capable of reading both temperature and temperature compensated pressure reading. This sensor includes the following features:
- I2C digital interface
- 24-bit ADC
- Altitude and pressure measurements
- Temperature sensor
Sample projects available on GitHub
Purchasing
The MPL3115A2 is available on breakout boards and a weather shield:
Code Example
Mpl3115a2? sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
sensor = new Mpl3115a2(Device.CreateI2cBus());
var consumer = Mpl3115a2.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
},
filter: result =>
{
if (result.Old?.Temperature is { } oldTemp &&
result.New.Temperature is { } newTemp)
{
return (newTemp - oldTemp).Abs().Celsius > 0.5; // returns true if > 0.5°C change.
}
return false;
}
);
sensor.Subscribe(consumer);
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Temperature: {result.New.Temperature?.Celsius:N2}C");
Resolver.Log.Info($" Pressure: {result.New.Pressure?.Bar:N2}bar");
};
return Task.CompletedTask;
}
public override async Task Run()
{
if (sensor == null) { return; }
var conditions = await sensor.Read();
Resolver.Log.Info($"Temperature: {conditions.Temperature?.Celsius}°C, Pressure: {conditions.Pressure?.Pascal}Pa");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Interrupt Mode
The application below connects the MPL3115A2 to two interrupt handlers. These interrupt handlers (events) will display the Temperature
and Pressure
properties when the handlers are triggered. The sensor is checked every 100 milliseconds (the default for the updatePeriod
).
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Interrupt Example");
var mpl3115a2 = new MPL3115A2(temperatureChangeNotificationThreshold: 0.1F);
mpl3115a2.TemperatureChanged += (s, e) =>
{
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2"));
};
mpl3115a2.PressureChanged += (s, e) =>
{
Console.WriteLine("Pressure: " + mpl3115a2.Pressure.ToString("f2"));
};
Thread.Sleep(Timeout.Infinite);
}
}
Polling Mode
The following application reads the temperature and pressure every second and displays the result on the debug console:
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Polling Example");
var mpl3115a2 = new MPL3115A2(updateInterval: 0);
while (true)
{
mpl3115a2.Update();
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2") + ", Pressure: " + mpl3115a2.Pressure.ToString("f2"));
Thread.Sleep(1000);
}
}
}
Wiring Example
MPL3115A2 configured for polling more data reads:
ReadSensor()
Update the temperature and pressure from the sensor and set the Pressure property.
Declaration
protected override Task<(Temperature? Temperature, Pressure? Pressure)> ReadSensor()
Returns
Type | Description |
---|---|
Task<(Temperature? Temperature, Pressure? Pressure)> |
Overrides
Remarks
Mpl3115a2 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The MPL3115A2 is a barometric pressure sensor capable of reading both temperature and temperature compensated pressure reading. This sensor includes the following features:
- I2C digital interface
- 24-bit ADC
- Altitude and pressure measurements
- Temperature sensor
Sample projects available on GitHub
Purchasing
The MPL3115A2 is available on breakout boards and a weather shield:
Code Example
Mpl3115a2? sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
sensor = new Mpl3115a2(Device.CreateI2cBus());
var consumer = Mpl3115a2.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
},
filter: result =>
{
if (result.Old?.Temperature is { } oldTemp &&
result.New.Temperature is { } newTemp)
{
return (newTemp - oldTemp).Abs().Celsius > 0.5; // returns true if > 0.5°C change.
}
return false;
}
);
sensor.Subscribe(consumer);
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Temperature: {result.New.Temperature?.Celsius:N2}C");
Resolver.Log.Info($" Pressure: {result.New.Pressure?.Bar:N2}bar");
};
return Task.CompletedTask;
}
public override async Task Run()
{
if (sensor == null) { return; }
var conditions = await sensor.Read();
Resolver.Log.Info($"Temperature: {conditions.Temperature?.Celsius}°C, Pressure: {conditions.Pressure?.Pascal}Pa");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Interrupt Mode
The application below connects the MPL3115A2 to two interrupt handlers. These interrupt handlers (events) will display the Temperature
and Pressure
properties when the handlers are triggered. The sensor is checked every 100 milliseconds (the default for the updatePeriod
).
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Interrupt Example");
var mpl3115a2 = new MPL3115A2(temperatureChangeNotificationThreshold: 0.1F);
mpl3115a2.TemperatureChanged += (s, e) =>
{
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2"));
};
mpl3115a2.PressureChanged += (s, e) =>
{
Console.WriteLine("Pressure: " + mpl3115a2.Pressure.ToString("f2"));
};
Thread.Sleep(Timeout.Infinite);
}
}
Polling Mode
The following application reads the temperature and pressure every second and displays the result on the debug console:
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Polling Example");
var mpl3115a2 = new MPL3115A2(updateInterval: 0);
while (true)
{
mpl3115a2.Update();
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2") + ", Pressure: " + mpl3115a2.Pressure.ToString("f2"));
Thread.Sleep(1000);
}
}
}
Wiring Example
MPL3115A2 configured for polling more data reads:
Reset()
Reset the sensor
Declaration
public void Reset()
Remarks
Mpl3115a2 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The MPL3115A2 is a barometric pressure sensor capable of reading both temperature and temperature compensated pressure reading. This sensor includes the following features:
- I2C digital interface
- 24-bit ADC
- Altitude and pressure measurements
- Temperature sensor
Sample projects available on GitHub
Purchasing
The MPL3115A2 is available on breakout boards and a weather shield:
Code Example
Mpl3115a2? sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
sensor = new Mpl3115a2(Device.CreateI2cBus());
var consumer = Mpl3115a2.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
},
filter: result =>
{
if (result.Old?.Temperature is { } oldTemp &&
result.New.Temperature is { } newTemp)
{
return (newTemp - oldTemp).Abs().Celsius > 0.5; // returns true if > 0.5°C change.
}
return false;
}
);
sensor.Subscribe(consumer);
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Temperature: {result.New.Temperature?.Celsius:N2}C");
Resolver.Log.Info($" Pressure: {result.New.Pressure?.Bar:N2}bar");
};
return Task.CompletedTask;
}
public override async Task Run()
{
if (sensor == null) { return; }
var conditions = await sensor.Read();
Resolver.Log.Info($"Temperature: {conditions.Temperature?.Celsius}°C, Pressure: {conditions.Pressure?.Pascal}Pa");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Interrupt Mode
The application below connects the MPL3115A2 to two interrupt handlers. These interrupt handlers (events) will display the Temperature
and Pressure
properties when the handlers are triggered. The sensor is checked every 100 milliseconds (the default for the updatePeriod
).
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Interrupt Example");
var mpl3115a2 = new MPL3115A2(temperatureChangeNotificationThreshold: 0.1F);
mpl3115a2.TemperatureChanged += (s, e) =>
{
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2"));
};
mpl3115a2.PressureChanged += (s, e) =>
{
Console.WriteLine("Pressure: " + mpl3115a2.Pressure.ToString("f2"));
};
Thread.Sleep(Timeout.Infinite);
}
}
Polling Mode
The following application reads the temperature and pressure every second and displays the result on the debug console:
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Polling Example");
var mpl3115a2 = new MPL3115A2(updateInterval: 0);
while (true)
{
mpl3115a2.Update();
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2") + ", Pressure: " + mpl3115a2.Pressure.ToString("f2"));
Thread.Sleep(1000);
}
}
}
Wiring Example
MPL3115A2 configured for polling more data reads:
Events
PressureUpdated
Event raised when pressure value changes
Declaration
public event EventHandler<IChangeResult<Pressure>> PressureUpdated
Event Type
Type | Description |
---|---|
EventHandler<IChangeResult<Pressure>> |
Remarks
Mpl3115a2 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The MPL3115A2 is a barometric pressure sensor capable of reading both temperature and temperature compensated pressure reading. This sensor includes the following features:
- I2C digital interface
- 24-bit ADC
- Altitude and pressure measurements
- Temperature sensor
Sample projects available on GitHub
Purchasing
The MPL3115A2 is available on breakout boards and a weather shield:
Code Example
Mpl3115a2? sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
sensor = new Mpl3115a2(Device.CreateI2cBus());
var consumer = Mpl3115a2.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
},
filter: result =>
{
if (result.Old?.Temperature is { } oldTemp &&
result.New.Temperature is { } newTemp)
{
return (newTemp - oldTemp).Abs().Celsius > 0.5; // returns true if > 0.5°C change.
}
return false;
}
);
sensor.Subscribe(consumer);
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Temperature: {result.New.Temperature?.Celsius:N2}C");
Resolver.Log.Info($" Pressure: {result.New.Pressure?.Bar:N2}bar");
};
return Task.CompletedTask;
}
public override async Task Run()
{
if (sensor == null) { return; }
var conditions = await sensor.Read();
Resolver.Log.Info($"Temperature: {conditions.Temperature?.Celsius}°C, Pressure: {conditions.Pressure?.Pascal}Pa");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Interrupt Mode
The application below connects the MPL3115A2 to two interrupt handlers. These interrupt handlers (events) will display the Temperature
and Pressure
properties when the handlers are triggered. The sensor is checked every 100 milliseconds (the default for the updatePeriod
).
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Interrupt Example");
var mpl3115a2 = new MPL3115A2(temperatureChangeNotificationThreshold: 0.1F);
mpl3115a2.TemperatureChanged += (s, e) =>
{
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2"));
};
mpl3115a2.PressureChanged += (s, e) =>
{
Console.WriteLine("Pressure: " + mpl3115a2.Pressure.ToString("f2"));
};
Thread.Sleep(Timeout.Infinite);
}
}
Polling Mode
The following application reads the temperature and pressure every second and displays the result on the debug console:
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Polling Example");
var mpl3115a2 = new MPL3115A2(updateInterval: 0);
while (true)
{
mpl3115a2.Update();
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2") + ", Pressure: " + mpl3115a2.Pressure.ToString("f2"));
Thread.Sleep(1000);
}
}
}
Wiring Example
MPL3115A2 configured for polling more data reads:
TemperatureUpdated
Event raised when temperature value changes
Declaration
public event EventHandler<IChangeResult<Temperature>> TemperatureUpdated
Event Type
Type | Description |
---|---|
EventHandler<IChangeResult<Temperature>> |
Remarks
Mpl3115a2 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The MPL3115A2 is a barometric pressure sensor capable of reading both temperature and temperature compensated pressure reading. This sensor includes the following features:
- I2C digital interface
- 24-bit ADC
- Altitude and pressure measurements
- Temperature sensor
Sample projects available on GitHub
Purchasing
The MPL3115A2 is available on breakout boards and a weather shield:
Code Example
Mpl3115a2? sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
sensor = new Mpl3115a2(Device.CreateI2cBus());
var consumer = Mpl3115a2.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Observer: Temp changed by threshold; new temp: {result.New.Temperature?.Celsius:N2}C, old: {result.Old?.Temperature?.Celsius:N2}C");
},
filter: result =>
{
if (result.Old?.Temperature is { } oldTemp &&
result.New.Temperature is { } newTemp)
{
return (newTemp - oldTemp).Abs().Celsius > 0.5; // returns true if > 0.5°C change.
}
return false;
}
);
sensor.Subscribe(consumer);
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Temperature: {result.New.Temperature?.Celsius:N2}C");
Resolver.Log.Info($" Pressure: {result.New.Pressure?.Bar:N2}bar");
};
return Task.CompletedTask;
}
public override async Task Run()
{
if (sensor == null) { return; }
var conditions = await sensor.Read();
Resolver.Log.Info($"Temperature: {conditions.Temperature?.Celsius}°C, Pressure: {conditions.Pressure?.Pascal}Pa");
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Interrupt Mode
The application below connects the MPL3115A2 to two interrupt handlers. These interrupt handlers (events) will display the Temperature
and Pressure
properties when the handlers are triggered. The sensor is checked every 100 milliseconds (the default for the updatePeriod
).
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Interrupt Example");
var mpl3115a2 = new MPL3115A2(temperatureChangeNotificationThreshold: 0.1F);
mpl3115a2.TemperatureChanged += (s, e) =>
{
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2"));
};
mpl3115a2.PressureChanged += (s, e) =>
{
Console.WriteLine("Pressure: " + mpl3115a2.Pressure.ToString("f2"));
};
Thread.Sleep(Timeout.Infinite);
}
}
Polling Mode
The following application reads the temperature and pressure every second and displays the result on the debug console:
public class MeadowApp : App<F7Micro, MeadowApp>
{
public MeadowApp()
{
Console.WriteLine("MPL3115A2 Polling Example");
var mpl3115a2 = new MPL3115A2(updateInterval: 0);
while (true)
{
mpl3115a2.Update();
Console.WriteLine("Temperature: " + mpl3115a2.Temperature.ToString("f2") + ", Pressure: " + mpl3115a2.Pressure.ToString("f2"));
Thread.Sleep(1000);
}
}
}
Wiring Example
MPL3115A2 configured for polling more data reads: