Remarks
Bmp085 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BMP085 is a high-precision, low-power barometric pressure sensor. The BMP085 offers a measuring range of 300 to 1100 hPa with an absolute accuracy of down to 0.03 hPa. It's based on piezo-resistive technology for EMC robustness, high accuracy and linearity as well as long term stability. This sensor supports a voltage supply between 1.8 and 3.6VDC. It is designed to be connected directly to a micro-controller via the I2C bus.
Code Example
Bmp085? sensor;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
sensor = new Bmp085(Device.CreateI2cBus());
var consumer = Bmp085.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 =>
{
//c# 8 pattern match syntax. checks for !null and assigns var.
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
Wiring Example
To wire a BMP085 to your Meadow board, connect the following:
BMP085 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
Syntax
public class Bmp085 : ByteCommsSensorBase<(Units.Temperature? Temperature, Pressure? Pressure)>, ISamplingSensor<(Units.Temperature? Temperature, Pressure? Pressure)>, ISamplingSensor<(Units.Temperature? Temperature, Pressure? Pressure)>, IDisposable, ITemperatureSensor, IBarometricPressureSensor
Constructors
Bmp085(II2cBus, Byte, Bmp085.DeviceMode)
Create a new BMP085 object
Declaration
public Bmp085(II2cBus i2cBus, byte address = null, Bmp085.DeviceMode deviceMode = default(Bmp085.DeviceMode))
Parameters
Type | Name | Description |
---|---|---|
II2cBus | i2cBus | The I2C bus |
System.Byte | address | The I2C address |
Bmp085.DeviceMode | deviceMode | The device mode |
Properties
Pressure
Last value read from the Pressure sensor.
Declaration
public Pressure? Pressure { get; }
Property Value
Type | Description |
---|---|
System.Nullable<Pressure> |
Temperature
Last value read from the Pressure sensor.
Declaration
public Units.Temperature? Temperature { get; }
Property Value
Type | Description |
---|---|
System.Nullable<Units.Temperature> |
Methods
RaiseEventsAndNotify(IChangeResult<(Nullable<Units.Temperature> Temperature, Nullable<Pressure> Pressure)>)
Raise events for subcribers and notify of value changes
Declaration
protected override void RaiseEventsAndNotify(IChangeResult<(Units.Temperature? Temperature, Pressure? Pressure)> changeResult)
Parameters
Type | Name | Description |
---|---|---|
IChangeResult<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<Pressure>>> | changeResult | The updated sensor data |
ReadSensor()
Calculates the compensated pressure and temperature.
Declaration
protected override Task<(Units.Temperature? Temperature, Pressure? Pressure)> ReadSensor()
Returns
Type | Description |
---|---|
Task<System.ValueTuple<System.Nullable<Units.Temperature>, System.Nullable<Pressure>>> |
Overrides
Events
PressureUpdated
Raised when the pressure value changes
Declaration
public event EventHandler<IChangeResult<Pressure>> PressureUpdated
Event Type
Type | Description |
---|---|
EventHandler<IChangeResult<Pressure>> |
TemperatureUpdated
Raised when the temperature value changes
Declaration
public event EventHandler<IChangeResult<Units.Temperature>> TemperatureUpdated
Event Type
Type | Description |
---|---|
EventHandler<IChangeResult<Units.Temperature>> |