@johntalton/boschieu
v8.0.1
Published
Common Unified Sensor API for supported IEU chips.
Maintainers
Readme
Bosch Integrated Environmental Unit
Common Unified Sensor API for supported IEU chips.
Provides full feature access to all supported chips (bmp280 bme280 bme680 bme688 bmp388 bmp390) while still providing rich chip specific features (multiple heater profiles and fifo access).
Products:
(note: Adafruit no-longer sells the bmp085 or bmp180, donation of legacy chips are welcome to aid in greater product support)
:gear: API
The API is organized around simple sensor class BoschSensor which provides an object interface for manipulating the sensor.
Example using detect method to discover chip type.
import { BoschIEU } from '@johntalton/boschieu'
import { I2CAddressedBus } from '@johntalton/and-other-delights'
const DEFAULT_BOSCH_ADDRESS = 0x77
const i2cBus = /* from I2CBus interface */
const addressedBus = new I2CAddressedBus(i2cBus, DEFAULT_BOSCH_ADDRESS)
// use `detect` method to identify sensor type
const sensor = await BoschIEU.detect(addressedBus)
// load the calibration data in sensor cache
// only needed once on chip initialization
await sensor.calibration()
// setting profile values
// different chips have addition profile properties and modes
await sensor.setProfile({ /* ... */ })
// perform a reading of the chips data values
await sensor.measurement()
Alternatively, if you wish to set the chip during initialization that is also possible (replacing the above detect with a call to sensor with the specified chip)
// ...
import { bmp390 } from '@johntalton/boschieu/chip'
// ...
const sensor = BoschIEU.sensor(addressedBus, { chip: bmp390 })
// use bmp390 specific interaction (etc)
:wrench: sensor.chip
The chips identification can be inspected via the sensor.chip property.
// ...
const features = sensor.chip.features
const hasFifo = features.fifo
const name = sensor.chip.name
const kind = sensor.chip.kind
console.log('chip:', kind, name, hasFifo)
// chip: 3xx bmp390 true
:wrench: calibration()
Calibration method fetches required parameters from the chip and caches them in the sensor class. It also returns a copy for inspection.
This is required prior to any measurement call to properly calculate results.
:wrench: profile()
Returns the chips full profile object.
:wrench: setProfile(profile)
Sets the profile for the chip in full.
Using the bmp390 profile as an example, a full profile set would look similar to the following.
// ...
await sensor.setProfile({
mode: 'NORMAL',
standby_prescaler: 1,
oversampling_p: 1,
oversampling_t: 1,
filter_coefficient: false,
watchdog: 'LONG',
spi: {
mode: '4-wire',
page: 0 // no paging for 3xx
},
fifo: {
active: true,
stopOnFull: false,
temp: true,
press: true,
time: true,
data: 'unfiltered',
subSampling: 0,
highWatermark: 1
},
interrupt: {
mode: 'open-drain',
level: 'active-low',
driveStrength: 'low',
latched: true,
onFifoWatermark: false,
onFifoFull: false,
onReady: true
}
})
:wrench: setMode(profile)
Setting the Mode is a short form of setting the profile. It allows for updating part of the profile that controls the mode. This is useful for chips that can be used in single-shot measurement modes.
Note, the mode register contains the temperature and pressure oversampling values, thus the must be specified as part of this limited profile setting.
