Device::Chip::BME280 - chip driver for BME280
Device::Chip::BME280
use Device::Chip::BME280; use Future::AsyncAwait; my $chip = Device::Chip::BME280->new; await $chip->mount( Device::Chip::Adapter::...->new ); await $chip->change_config( OSRS_H => 4, OSRS_P => 4, OSRS_T => 4, MODE => "NORMAL", ); my ( $pressure, $temperature, $humidity ) = await $chip->read_sensor; printf "Temperature=%.2fC ", $temperature; printf "Pressure=%dPa ", $pressure; printf "Humidity=%.2f%%\n", $humidity;
This Device::Chip subclass provides specific communication to a Bosch BME280 attached to a computer via an I²C adapter.
The reader is presumed to be familiar with the general operation of this chip; the documentation here will not attempt to explain or define chip-specific concepts or features, only the use of this module to access them.
The following methods documented in an await expression return Future instances.
await
$id = await $chip->read_id
Returns the chip ID.
$config = await $chip->read_config
Returns a HASH reference containing the chip config, using fields named from the data sheet.
HASH
FILTER => OFF | 2 | 4 | 8 | 16 MODE => SLEEP | FORCED | NORMAL OSRS_H => SKIP | 1 | 2 | 4 | 8 | 16 OSRS_P => SKIP | 1 | 2 | 4 | 8 | 16 OSRS_T => SKIP | 1 | 2 | 4 | 8 | 16 SPI3W_EN => 0 | 1 T_SB => 0.5 | 10 | 20 | 62.5 | 125 | 250 | 500 | 1000
await $chip->change_config( %changes )
Writes updates to the configuration registers.
Note that these two methods use a cache of configuration bytes to make subsequent modifications more efficient.
$status = await $chip->read_status;
( $adc_P, $adc_T, $adc_H ) = await $chip->read_raw
Returns three integers containing the raw ADC reading values from the sensor.
This method is mostly for testing or internal purposes only. For converted sensor readings in real-world units you want to use "read_sensor".
( $pressure, $temperature, $humidity ) = await $chip->read_sensor
Returns the sensor readings appropriately converted into units of Pascals for pressure, degrees Celcius for temperature, and percentage relative for humidity.
Paul Evans <leonerd@leonerd.org.uk>
To install Device::Chip::BME280, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::Chip::BME280
CPAN shell
perl -MCPAN -e shell install Device::Chip::BME280
For more information on module installation, please visit the detailed CPAN module installation guide.