Device::Chip::SCD4x - chip driver for SCD40 and SCD41
Device::Chip::SCD4x
use Device::Chip::SCD4x; use Future::AsyncAwait; my $chip = Device::Chip::SCD4x->new; await $chip->mount( Device::Chip::Adapter::...->new ); await $chip->start_periodic_measurement; while(1) { await Future::IO->sleep(1); my ( $co2, $temp, $humid ) = await $chip->maybe_read_measurement or next; printf "CO2 concentration=%dppm ", $co2; printf "Temperature=%.2fC ", $temp; printf "Humidity=%.2f%%\n", $hum; }
This Device::Chip subclass provides specific communication to a Sensirion SCD40 or SCD41 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 I²C address of the device. Can be specified in decimal, octal or hex with leading 0 or 0x prefixes.
0
0x
The following methods documented in an await expression return Future instances.
await
$config = await $chip->read_config;
Returns a HASH reference containing the compensation values from chip config.
HASH
temperature_offset # in degrees C sensor_altitude # in metres ambient_pressure # in hPa
await $chip->start_periodic_measurement;
Starts periodic measurement mode.
( $co2concentration, $temperature, $humidity ) = await $chip->read_measurement();
Returns the latest sensor reading values. Returns a 3-element list, containing the CO₂ concentration in PPM, temperature in degrees C, and humidity in %RH.
( $co2concentration, $temperature, $humidity ) = await $chip->maybe_read_measurement();
If the sensor has a new measurement ready, returns it. Otherwise, returns the last successful measurement reading. After initial startup, this will return an empty list before the first reading is available.
$bytes = await $chip->get_serial_number;
Returns a 6-byte encoding of the chip's internal serial number.
Paul Evans <leonerd@leonerd.org.uk>
To install Device::Chip::SCD4x, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::Chip::SCD4x
CPAN shell
perl -MCPAN -e shell install Device::Chip::SCD4x
For more information on module installation, please visit the detailed CPAN module installation guide.