Class Bme280
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
busI2cBusThe bus the part is on.
addressbyteAddressPrimary with SDO low, AddressSecondary with SDO high.
temperatureBme280.OversamplingThe temperature oversampling.
pressureBme280.OversamplingThe pressure oversampling.
humidityBme280.OversamplingThe humidity oversampling.
filterBme280.FilterThe 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
AddressSecondary
The address it answers on with SDO high.
public const byte AddressSecondary = 119
Field Value
CalibrationHumidityLength
How many bytes the humidity calibration block holds.
public const int CalibrationHumidityLength = 7
Field Value
CalibrationTempPressLength
How many bytes the temperature and pressure calibration block holds.
public const int CalibrationTempPressLength = 26
Field Value
ChipId
The value its chip-ID register reads, which tells it from a BMP280.
public const byte ChipId = 96
Field Value
DataLength
How many bytes one measurement burst holds.
public const int DataLength = 8
Field Value
ResetWord
The word written to the reset register to restart the part.
public const byte ResetWord = 182
Field Value
StartupMicros
How long the part takes to start after a reset, in microseconds.
public const uint StartupMicros = 2000
Field Value
Methods
ConfigBits(Bme280Config)
Assembles a config register value.
public static byte ConfigBits(Bme280Config config)
Parameters
configBme280ConfigThe 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
bitsbyteThe 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
humidityBme280.OversamplingThe 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
bitsbyteThe 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
ctrlBme280CtrlMeasThe 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
bitsbyteThe 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
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
statusbyteThe 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
temperatureBme280.OversamplingThe temperature oversampling.
pressureBme280.OversamplingThe pressure oversampling.
humidityBme280.OversamplingThe 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
statusbyteThe 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
oversamplingBme280.OversamplingThe 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
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
temperatureBme280.OversamplingThe temperature oversampling.
pressureBme280.OversamplingThe pressure oversampling.
humidityBme280.OversamplingThe humidity oversampling.
Returns
- uint
The datasheet's typical time in microseconds.