Table of Contents

Class Bmp280

Namespace
Pamoja.Sensors
Assembly
Pamoja.Sensors.dll

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

bus I2cBus

The bus the part is on.

address byte

AddressPrimary with SDO low, AddressSecondary with SDO high.

temperature Bmp280.Oversampling

The temperature oversampling.

pressure Bmp280.Oversampling

The pressure oversampling.

filter byte

The 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

byte

AddressSecondary

The address it answers on with SDO high.

public const byte AddressSecondary = 119

Field Value

byte

CalibrationLength

How many trimming bytes the part holds from 0x88.

public const int CalibrationLength = 24

Field Value

int

ChipId

The value its chip-ID register reads, which tells it from a BME280.

public const byte ChipId = 88

Field Value

byte

DataLength

How many bytes one measurement burst holds.

public const int DataLength = 6

Field Value

int

Properties

Coefficients

The trimming coefficients read at initialization, or null before it.

public PamojaBmp280Coefficients? Coefficients { get; }

Property Value

PamojaBmp280Coefficients?

Methods

ConfigBits(PamojaBmp280Config)

Assembles a BMP280 config register value.

public static byte ConfigBits(PamojaBmp280Config config)

Parameters

config PamojaBmp280Config

The config.

Returns

byte

The value the C ABI computes.

ConfigFromBits(byte)

Parses a BMP280 config register value.

public static PamojaBmp280Config ConfigFromBits(byte bits)

Parameters

bits byte

The 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

config PamojaBmp280CtrlMeas

The 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

bits byte

The 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

status byte

The 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

pressure uint

The pressure.

temperature uint

The temperature.

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

status byte

The 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

code byte

The 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

data ReadOnlySpan<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

code byte

The code.

Returns

uint

The value the C ABI computes.