### DHTNEW Constructor and Type Management Source: https://github.com/robtillaart/dhtnew/blob/master/README.md Initializes the DHT sensor library with the specified data pin and provides methods to manage the sensor type. ```APIDOC ## Constructor and Type Management ### DHTNEW(uint8_t pin) - **Description**: Defines the data pin of the sensor. ### void reset() - **Description**: Resets the library's internal settings to default. Does not perform a hardware reset of the sensor. ### uint8_t getType() - **Description**: Returns the detected sensor type (0 = unknown, 11, 22, 70 for experimental Si7021). Attempts to determine the type if unknown. ### void setType(uint8_t type = 0) - **Description**: Allows forcing the sensor type. Supported types include: - 0: Not defined - 11: DHT11, DHT12, KY015 - 22: DHT22, DHT33, DHT44, etc. - 23: DHT23 (mapped to 22) - 70: Sonoff Si7021 (experimental) - Other values set the type to 0. ``` -------------------------------- ### Include DHTNEW Library Source: https://github.com/robtillaart/dhtnew/blob/master/README.md Include the dhtnew library header file to use its functionalities. ```cpp #include "dhtnew.h" ``` -------------------------------- ### Conditional Compilation for MKR1010 Source: https://github.com/robtillaart/dhtnew/blob/master/README.md This snippet demonstrates conditional compilation for the Arduino MKR1010 board, intended to identify the correct preprocessor define. It is marked with a TODO for further investigation. ```cpp #if defined(MKR1010) // TODO find out real define https://github.com/RobTillaart/DHTNew/issues/67 #ifdef ARDUINO_SAMD_MKRWIFI1010 #error found #endif ``` -------------------------------- ### Temperature Constraining Logic Source: https://github.com/robtillaart/dhtnew/blob/master/README.md Illustrates how temperature values are constrained based on the sensor type. This logic is type-dependent and may require further investigation for different sensor models. ```cpp if (type == 11) temp = constrain(temp, 0, 100); if (type == 22) temp = constrain(temp, -40, 80); etc. ``` -------------------------------- ### DHT Sensor Offset Configuration Source: https://github.com/robtillaart/dhtnew/blob/master/README.md Allows setting and retrieving offset values for humidity and temperature readings. ```APIDOC ## Offset ### void setHumidityOffset(float offset) - **Description**: Sets the humidity offset in %RH. The value is constrained between 0.0 and 100.0. ### void setTemperatureOffset(float offset) - **Description**: Sets the temperature offset in degrees Celsius. No automatic constraint is applied, allowing for scales like Kelvin (e.g., -273.15). ### float getHumidityOffset() - **Description**: Returns the currently set humidity offset. ### float getTemperatureOffset() - **Description**: Returns the currently set temperature offset. ### void setHumOffset(float offset) - **Description**: Short alias for `setHumidityOffset()` (deprecated in future versions). ### void setTempOffset(float offset) - **Description**: Short alias for `setTemperatureOffset()` (deprecated in future versions). ### float getHumOffset() - **Description**: Short alias for `getHumidityOffset()` (deprecated in future versions). ### float getTempOffset() - **Description**: Short alias for `getTemperatureOffset()` (deprecated in future versions). ``` -------------------------------- ### DHT Sensor Base Interface Source: https://github.com/robtillaart/dhtnew/blob/master/README.md Provides the core interface for reading temperature and humidity data from the DHT sensor. ```APIDOC ## Base Interface ### int read() - **Description**: Reads new temperature (Celsius) and humidity (%RH) from the sensor. Returns 1 on success, 0 on failure. ### uint32_t lastRead() - **Description**: Returns the number of milliseconds since the last successful `read()` operation. ### float getHumidity() - **Description**: Returns the last read humidity value (0.0 - 100.0 %RH). Returns `DHTLIB_INVALID_VALUE` (-999) in case of an error. Error reporting can be suppressed using `setSuppressError()`. ### float getTemperature() - **Description**: Returns the last read temperature in Celsius. The range depends on the sensor. Returns `DHTLIB_INVALID_VALUE` (-999) in case of an error. Error reporting can be suppressed using `setSuppressError()`. ``` -------------------------------- ### Power Management Source: https://github.com/robtillaart/dhtnew/blob/master/README.md Functions to manage the sensor's power state. `powerDown` pulls the data pin low to reduce power consumption, and `powerUp` restarts the sensor, requiring a potential wait time. ```APIDOC ## Power Management ### `void powerDown()` Pulls the data pin down to reduce power consumption. ### `void powerUp()` Restarts the sensor. Note that a wait of up to two seconds may be required after this operation. ``` -------------------------------- ### Reading Wait Control Source: https://github.com/robtillaart/dhtnew/blob/master/README.md Flags to manage the waiting behavior during sensor readings. `setWaitForReading` enforces a blocking wait, while `setReadDelay` tunes the delay before the actual read to reduce blocking time. ```APIDOC ## Reading Wait Control ### `void setWaitForReading(bool b)` Enforces a blocking wait for sensor readings. ### `bool getWaitForReading()` Returns the current setting for blocking wait behavior. ### `void setReadDelay(uint16_t rd = 0)` Tunes the time the sensor waits before the actual read, reducing blocking time. Default values are 1000 ms for DHT11 and 2000 ms for DHT22. Setting `readDelay` to 0 resets to datasheet values after a `read()` call. ### `uint16_t getReadDelay()` Returns the current read delay setting. ``` -------------------------------- ### Interrupt Control Source: https://github.com/robtillaart/dhtnew/blob/master/README.md Functions to enable or disable interrupts during core read operations. Disabling interrupts can help maintain timing accuracy, especially on specific boards like AVR, MKR1010, and Arduino R4. ```APIDOC ## Interrupt Control ### `void setDisableIRQ(bool b)` Allows or suppresses interrupts during core read functions to maintain timing accuracy. ### `bool getDisableIRQ()` Returns the current setting for interrupt suppression. Defaults to `true`. ``` -------------------------------- ### Error Suppression Source: https://github.com/robtillaart/dhtnew/blob/master/README.md Control the suppression of error values (-999). When enabled, error values are suppressed, and users must check the return value of `read()` directly to detect errors. ```APIDOC ## Error Suppression ### `void setSuppressError(bool b)` Suppresses error values (e.g., -999). When this is enabled, users must check the return value of `read()` to identify errors. This is useful for preventing spikes in plots or logs. ### `bool getSuppressError()` Returns the current setting for error suppression. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.