Class Bmp280
A Bosch BMP280 pressure and temperature sensor, and a driver for one on an I2C bus.
public sealed class Bmp280 : IDisposable
- Inheritance
-
Bmp280
- Implements
- Inherited Members
Remarks
The static members are the part's datasheet, decoded exactly as the manufacturer specifies, and Bmp280.Sim, a part that is not there.
An instance drives one part over an I2cBus, measuring on demand in forced mode. Nothing is sent until Init() or the first Measure(). The driver holds its own share of the bus, so the bus may be disposed once the driver is built.
Constructors
Bmp280(I2cBus, byte, Oversampling, Oversampling, byte)
Creates a driver for the part at address on bus.
public Bmp280(I2cBus bus, byte address, Bmp280.Oversampling temperature = Oversampling.X1, Bmp280.Oversampling pressure = Oversampling.X1, byte filter = 0)
Parameters
busI2cBusThe bus the part is on.
addressbyteAddressPrimary with SDO low, AddressSecondary with SDO high.
temperatureBmp280.OversamplingThe temperature oversampling.
pressureBmp280.OversamplingThe pressure oversampling.
filterbyteThe IIR filter's three-bit code, 0 for the filter off, written as given.
Exceptions
- PamojaException
The native driver could not be created.
Fields
AddressPrimary
The address a BMP280 answers on with its SDO pin low.
public const byte AddressPrimary = 118
Field Value
AddressSecondary
The address it answers on with SDO high.
public const byte AddressSecondary = 119
Field Value
CalibrationLength
How many trimming bytes the part holds from 0x88.
public const int CalibrationLength = 24
Field Value
ChipId
The value its chip-ID register reads, which tells it from a BME280.
public const byte ChipId = 88
Field Value
DataLength
How many bytes one measurement burst holds.
public const int DataLength = 6
Field Value
Properties
Coefficients
The trimming coefficients read at initialization, or null before it.
public PamojaBmp280Coefficients? Coefficients { get; }
Property Value
Methods
ConfigBits(PamojaBmp280Config)
Assembles a BMP280 config register value.
public static byte ConfigBits(PamojaBmp280Config config)
Parameters
configPamojaBmp280ConfigThe config.
Returns
- byte
The value the C ABI computes.
ConfigFromBits(byte)
Parses a BMP280 config register value.
public static PamojaBmp280Config ConfigFromBits(byte bits)
Parameters
bitsbyteThe bits.
Returns
- PamojaBmp280Config
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
CtrlMeasBits(PamojaBmp280CtrlMeas)
Assembles a BMP280 ctrl_meas register value.
public static byte CtrlMeasBits(PamojaBmp280CtrlMeas config)
Parameters
configPamojaBmp280CtrlMeasThe config.
Returns
- byte
The value the C ABI computes.
CtrlMeasFromBits(byte)
Parses a BMP280 ctrl_meas register value.
public static PamojaBmp280CtrlMeas CtrlMeasFromBits(byte bits)
Parameters
bitsbyteThe bits.
Returns
- PamojaBmp280CtrlMeas
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
Dispose()
Releases the driver and its share of the bus.
public void Dispose()
ImageUpdating(byte)
Reports whether a BMP280 status byte says the calibration image is loading.
public static bool ImageUpdating(byte status)
Parameters
statusbyteThe status.
Returns
- bool
The value the C ABI computes.
Init()
Resets the part, checks it is a BMP280, reads its trimming, and writes the settings.
public void Init()
Exceptions
- PamojaException
Nothing answered at the address, another part did, or the trimming never finished loading.
Measure()
Runs one forced measurement and compensates it, initializing the part first if needed.
public Bmp280Reading Measure()
Returns
- Bmp280Reading
The reading.
Exceptions
- PamojaException
As Init(), and when the part is still measuring after the datasheet's time.
MeasurementBytes(uint, uint)
Builds the six data bytes a BMP280 holding these codes would return.
public static byte[] MeasurementBytes(uint pressure, uint temperature)
Parameters
Returns
- byte[]
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
Measuring(byte)
Reports whether a BMP280 status byte says a conversion is running.
public static bool Measuring(byte status)
Parameters
statusbyteThe status.
Returns
- bool
The value the C ABI computes.
OversamplingFactor(byte)
Returns how many samples a BMP280 oversampling code averages.
public static byte OversamplingFactor(byte code)
Parameters
codebyteThe code.
Returns
- byte
The value the C ABI computes.
ParseMeasurement(ReadOnlySpan<byte>)
Unpacks the six data bytes a BMP280 burst read returns.
public static PamojaBmp280Measurement ParseMeasurement(ReadOnlySpan<byte> data)
Parameters
dataReadOnlySpan<byte>The data.
Returns
- PamojaBmp280Measurement
The decoded value.
Exceptions
- PamojaException
The device data is not valid.
StandbyMicros(byte)
Returns the normal-mode standby period a BMP280 code selects.
public static uint StandbyMicros(byte code)
Parameters
codebyteThe code.
Returns
- uint
The value the C ABI computes.