SensirionSHT4x class

The Sensor sub-class for the Sensirion SHT4x.

Base classes

class Sensor
The "Sensor" class is used for all sensor-level operations - waking, sleeping, and taking measurements.

Constructors, destructors, conversion operators

SensirionSHT4x(TwoWire* theI2C, int8_t powerPin, bool useHeater = true, uint8_t measurementsToAverage = 1)
Construct a new SensirionSHT4x object using a secondary hardware I2C instance.
SensirionSHT4x(int8_t powerPin, bool useHeater = true, uint8_t measurementsToAverage = 1) explicit
Construct a new SensirionSHT4x object using the primary hardware I2C instance.
~SensirionSHT4x()
Destroy the SensirionSHT4x object - no action needed.

Public functions

String getSensorLocation(void) -> String override
Report the I2C address of the SHT4x - which is always 0x44.
bool setup(void) -> bool override
Do any one-time preparations needed before the sensor will be able to take readings.
bool addSingleMeasurementResult(void) -> bool override
Get the results from a single measurement.
bool sleep(void) -> bool override
Puts the sensor to sleep, if necessary.

Function documentation

SensirionSHT4x::SensirionSHT4x(TwoWire* theI2C, int8_t powerPin, bool useHeater = true, uint8_t measurementsToAverage = 1)

Construct a new SensirionSHT4x object using a secondary hardware I2C instance.

Parameters
theI2C A TwoWire instance for I2C communication. Due to the limitations of the Arduino core, only a hardware I2C instance can be used. For an AVR board, there is only one I2C instance possible and this form of the constructor should not be used. For a SAMD board, this can be used if a secondary I2C port is created on one of the extra SERCOMs.
powerPin

The pin on the mcu controlling power to the Sensirion SHT4x. Use -1 if it is continuously powered.

  • The SHT4x requires a 3.3V power source
useHeater Whether or not to run the internal heater of the SHT4x when shutting down the sensor; optional with a default value of true. The internal heater is designed to remove condensed water from the sensor - which will make the sensor stop responding to air humidity changes - and to allow creep-free operation in high humidity environments. The longest the internal heater can run at a time is 1s and the maximum duty load is 5%. Running only 1s per measurment cycle probably isn't enough to help with more than very minimal condensation, but it's probably the best we can easily do.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

This is only applicable to SAMD boards that are able to have multiple hardware I2C ports in use via SERCOMs.


SensirionSHT4x::SensirionSHT4x(int8_t powerPin, bool useHeater = true, uint8_t measurementsToAverage = 1) explicit

Construct a new SensirionSHT4x object using the primary hardware I2C instance.

Parameters
powerPin

The pin on the mcu controlling power to the Sensirion SHT4x. Use -1 if it is continuously powered.

  • The SHT4x requires a 3.3V power source
useHeater Whether or not to run the internal heater of the SHT4x when shutting down the sensor; optional with a default value of true. The internal heater is designed to remove condensed water from the sensor - which will make the sensor stop responding to air humidity changes - and to allow creep-free operation in high humidity environments. The longest the internal heater can run at a time is 1s and the maximum duty load is 5%. Running only 1s per measurment cycle probably isn't enough to help with more than very minimal condensation, but it's probably the best we can easily do.
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.

Because this is I2C and has only 1 possible address (0x44), we only need the power pin.


String SensirionSHT4x::getSensorLocation(void) override

Report the I2C address of the SHT4x - which is always 0x44.

Returns String Text describing how the sensor is attached to the mcu.

bool SensirionSHT4x::setup(void) override

Do any one-time preparations needed before the sensor will be able to take readings.

Returns bool True if the setup was successful.

This sets the _powerPin mode, begins the Wire library (sets pin levels and modes for I2C), and updates the _sensorStatus. No sensor power is required.


bool SensirionSHT4x::addSingleMeasurementResult(void) override

Get the results from a single measurement.

Returns bool True if the function completed successfully.

This asks the sensor for a new result, verifies that it passes sanity range checks, and then adds the value to the result array.

This also un-sets the _millisMeasurementRequested timestamp (sets _millisMeasurementRequested to 0) and updates the _sensorStatus.


bool SensirionSHT4x::sleep(void) override

Puts the sensor to sleep, if necessary.

Returns bool True if the sleep function completed successfully.

Does not take any action if not necessary.

If opted for, we run the SHT4x's internal heater for 1s before going to sleep.