NAME

Device::Chip::SHT4x - chip driver for SHT40 and SHT41

SYNOPSIS

use Device::Chip::SHT4x;
use Future::AsyncAwait;

my $chip = Device::Chip::SHT4x->new;
await $chip->mount( Device::Chip::Adapter::...->new );

while(1) {
   await Future::IO->sleep(1);

   my ( $temp, $humid ) = await $chip->read_measurement;

   printf "Temperature=%.2fC  ", $temp;
   printf "Humidity=%.2f%%\n", $hum;
}

DESCRIPTION

This Device::Chip subclass provides specific communication to a Sensirion SHT40 or SHT41 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.

Heater Operation

By default, the heater ability of the chip is not used by the "read_measurement" method.

If enabled by the heater_power and heater_duration settings, then the method might enable the heater at each measurement.

If heater_interval is not defined, then the heater will be used for every call to "read_measurement", and thus the returned readings will have been performed with that in effect. This will cause the sensor to report the temperature higher than, and humidity lower than, the actual ambient environment.

If heater_interval is defined, then the heater will only be activated each call if it hasn't been activated within that time before. Any measurement made within heater_cooldown seconds of the most recent heater operation will not report the actual sensor values, but instead will report the (cached) readings from the most recent non-heater measurement cycle.

When using the periodic heater, the heater will only activate each cycle if the previous reading was within both limits set by heater_max_temperature and heater_min_humidity. If either limit is exceeded then the heater will not be activated.

MOUNT PARAMETERS

addr

The I²C address of the device. Can be specified in decimal, octal or hex with leading 0 or 0x prefixes.

METHODS

The following methods documented in an await expression return Future instances.

read_config

$config = await $chip->read_config;

Returns a HASH reference containing the configuration.

While the chip itself does not have any configuration registers, this driver module stores the following fields directly to influence which measurement commands it uses to request readings from the chip.

precision       => low | medium | high
heater_power    => off | 20mW | 110mW | 200mW
heater_duration => off | 0.1s | 1s
heater_interval => undef | NUM
heater_cooldown => undef | NUM
heater_max_temperature => NUM
heater_min_humidity    => NUM

The module defaults to high precision, heater off.

Due to the way the SHT4x works, the precision field is ignored if the heater is enabled; measurements are always high-precision.

The various heater_* settings are described above, under "Heater Operation". The heater_cooldown setting defaults to 5 seconds, heater_max_temperature to 65 C, and heater_min_humidity to 80 %RH.

change_config

await $chip->change_config( %changes );

Writes updates to the stored configuration settings, which will take effect in the next call to the measurement method.

read_measurement

( $temperature, $humidity ) = await $chip->read_measurement();

Performs a measurement and returns the sensor reading values. Returns a 2-element list, containing temperature in degrees C, and humidity in %RH.

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>