Table of Contents

Class Bme280

Namespace
Pamoja.Sensors
Assembly
Pamoja.Sensors.dll

A Bosch BME280 temperature, pressure, and humidity sensor, and a driver for one on an I2C bus.

public sealed class Bme280 : IDisposable
Inheritance
Bme280
Implements
Inherited Members

Remarks

The static members are the part's datasheet: its addresses, registers, setting codes, and timing, and Bme280.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, and it waits as the datasheet asks, sleeping only when a real part is on the other end.

Constructors

Bme280(I2cBus, byte, Oversampling, Oversampling, Oversampling, Filter)

Creates a driver for the part at address on bus.

public Bme280(I2cBus bus, byte address, Bme280.Oversampling temperature = Oversampling.X1, Bme280.Oversampling pressure = Oversampling.X1, Bme280.Oversampling humidity = Oversampling.X1, Bme280.Filter filter = Filter.Off)

Parameters

bus I2cBus

The bus the part is on.

address byte

AddressPrimary with SDO low, AddressSecondary with SDO high.

temperature Bme280.Oversampling

The temperature oversampling.

pressure Bme280.Oversampling

The pressure oversampling.

humidity Bme280.Oversampling

The humidity oversampling.

filter Bme280.Filter

The IIR filter.

Exceptions

PamojaException

The native driver could not be created.

Fields

AddressPrimary

The address a BME280 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

CalibrationHumidityLength

How many bytes the humidity calibration block holds.

public const int CalibrationHumidityLength = 7

Field Value

int

CalibrationTempPressLength

How many bytes the temperature and pressure calibration block holds.

public const int CalibrationTempPressLength = 26

Field Value

int

ChipId

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

public const byte ChipId = 96

Field Value

byte

DataLength

How many bytes one measurement burst holds.

public const int DataLength = 8

Field Value

int

ResetWord

The word written to the reset register to restart the part.

public const byte ResetWord = 182

Field Value

byte

StartupMicros

How long the part takes to start after a reset, in microseconds.

public const uint StartupMicros = 2000

Field Value

uint

Methods

ConfigBits(Bme280Config)

Assembles a config register value.

public static byte ConfigBits(Bme280Config config)

Parameters

config Bme280Config

The standby period, filter, and interface settings.

Returns

byte

The register value to write.

ConfigFromBits(byte)

Parses a config register value.

public static Bme280Config ConfigFromBits(byte bits)

Parameters

bits byte

The register value, as read from the part.

Returns

Bme280Config

The standby period, filter, and interface settings.

CtrlHumBits(Oversampling)

Assembles a ctrl_hum register value, which takes effect only after the next ctrl_meas write.

public static byte CtrlHumBits(Bme280.Oversampling humidity)

Parameters

humidity Bme280.Oversampling

The humidity oversampling.

Returns

byte

The register value to write.

CtrlHumFromBits(byte)

Parses a ctrl_hum register value.

public static Bme280.Oversampling CtrlHumFromBits(byte bits)

Parameters

bits byte

The register value, as read from the part.

Returns

Bme280.Oversampling

The humidity oversampling.

CtrlMeasBits(Bme280CtrlMeas)

Assembles a ctrl_meas register value.

public static byte CtrlMeasBits(Bme280CtrlMeas ctrl)

Parameters

ctrl Bme280CtrlMeas

The oversampling and the power mode.

Returns

byte

The register value to write.

CtrlMeasFromBits(byte)

Parses a ctrl_meas register value.

public static Bme280CtrlMeas CtrlMeasFromBits(byte bits)

Parameters

bits byte

The register value, as read from the part.

Returns

Bme280CtrlMeas

The oversampling and the power mode.

Dispose()

Releases the driver and its share of the bus.

public void Dispose()

FilterCoefficient(Filter)

Returns the IIR coefficient a filter setting selects.

public static byte FilterCoefficient(Bme280.Filter filter)

Parameters

filter Bme280.Filter

The setting.

Returns

byte

The coefficient, or 0 when the filter is off.

ImageUpdating(byte)

Reports whether a status register says the calibration image is loading.

public static bool ImageUpdating(byte status)

Parameters

status byte

The status register.

Returns

bool

Whether the calibration is still being copied.

Init()

Resets the part, checks it is a BME280, reads its calibration, and writes the settings.

public void Init()

Remarks

The order is the datasheet's: the reset word, the start-up time, a wait for the calibration image to load, the chip id, the two calibration blocks, then config, ctrl_hum, and ctrl_meas, leaving the part asleep.

Exceptions

PamojaException

Nothing answered at the address, another part did, or the calibration never finished loading.

MaxMeasurementMicros(Oversampling, Oversampling, Oversampling)

Returns the longest one measurement can take, which is how long a driver waits after forcing one.

public static uint MaxMeasurementMicros(Bme280.Oversampling temperature, Bme280.Oversampling pressure, Bme280.Oversampling humidity)

Parameters

temperature Bme280.Oversampling

The temperature oversampling.

pressure Bme280.Oversampling

The pressure oversampling.

humidity Bme280.Oversampling

The humidity oversampling.

Returns

uint

The datasheet's maximum in microseconds.

Measure()

Runs one forced measurement and compensates it, initializing the part first if needed.

public Bme280Measurement Measure()

Returns

Bme280Measurement

The reading.

Exceptions

PamojaException

As Init(), and when the part is still measuring after the datasheet's time.

Measuring(byte)

Reports whether a status register says a conversion is running.

public static bool Measuring(byte status)

Parameters

status byte

The status register.

Returns

bool

Whether a measurement is in progress.

OversamplingFactor(Oversampling)

Returns how many samples an oversampling setting averages.

public static byte OversamplingFactor(Bme280.Oversampling oversampling)

Parameters

oversampling Bme280.Oversampling

The setting.

Returns

byte

The factor, or 0 when the measurement is skipped.

StandbyMicros(Standby)

Returns the period a standby setting rests for in normal mode.

public static uint StandbyMicros(Bme280.Standby standby)

Parameters

standby Bme280.Standby

The setting.

Returns

uint

The period in microseconds.

TypicalMeasurementMicros(Oversampling, Oversampling, Oversampling)

Returns the typical time one measurement takes.

public static uint TypicalMeasurementMicros(Bme280.Oversampling temperature, Bme280.Oversampling pressure, Bme280.Oversampling humidity)

Parameters

temperature Bme280.Oversampling

The temperature oversampling.

pressure Bme280.Oversampling

The pressure oversampling.

humidity Bme280.Oversampling

The humidity oversampling.

Returns

uint

The datasheet's typical time in microseconds.