### Monitor Timing for AM2315C Sensor Reads Source: https://context7.com/robtillaart/am2315c/llms.txt This example shows how to use `lastRead()` and `lastRequest()` to monitor the time elapsed since the last sensor read or data request. This is crucial for adhering to the minimum 1000 ms inter-read constraint and scheduling asynchronous reads without blocking the main loop. ```cpp #include "AM2315C.h" AM2315C DHT; void setup() { Serial.begin(115200); Wire.begin(); DHT.begin(); delay(1000); } void loop() { uint32_t now = millis(); Serial.print("Time since last read: "); Serial.print(now - DHT.lastRead()); Serial.print(" ms | Time since last request: "); Serial.print(now - DHT.lastRequest()); Serial.println(" ms"); // Only read when 1 second has elapsed since last read if (now - DHT.lastRead() >= 1000) { int status = DHT.read(); if (status == AM2315C_OK) { Serial.print("Read OK at "); Serial.print(DHT.lastRead()); Serial.println(" ms"); } } delay(250); } // Example output: // Time since last read: 1004 ms | Time since last request: 1004 ms // Read OK at 5012 ms ``` -------------------------------- ### Get Last Read Time Source: https://github.com/robtillaart/am2315c/blob/master/README.md Returns the time in milliseconds since the start of the program when the sensor was last read. ```cpp uint32_t lastRead() ``` -------------------------------- ### Get Last Request Time Source: https://github.com/robtillaart/am2315c/blob/master/README.md Returns the time in milliseconds since the start of the program when the last measurement request was made. ```cpp uint32_t lastRequest() ``` -------------------------------- ### Get Temperature Offset from AM2315C Source: https://github.com/robtillaart/am2315c/blob/master/README.md Retrieve the current temperature calibration offset. ```cpp float getTempOffset() { // Return current temperature offset, default 0. } ``` -------------------------------- ### Offset Calibration Source: https://github.com/robtillaart/am2315c/blob/master/README.md Allows setting and getting custom offsets for humidity and temperature readings to calibrate the sensor. ```APIDOC ## Offset Calibration - **void setHumOffset(float offset = 0)**: Sets an offset for humidity to calibrate the sensor. The default offset is 0. - **float getHumOffset()**: Returns the current humidity offset. Defaults to 0. - **void setTempOffset(float offset = 0)**: Sets an offset for temperature to calibrate the sensor. The default offset is 0. - **float getTempOffset()**: Returns the current temperature offset. Defaults to 0. ``` -------------------------------- ### Get Humidity Offset from AM2315C Source: https://github.com/robtillaart/am2315c/blob/master/README.md Retrieve the current humidity calibration offset. ```cpp float getHumOffset() { // Return current humidity offset, default 0. } ``` -------------------------------- ### Get Address Source: https://github.com/robtillaart/am2315c/blob/master/README.md Returns the fixed I2C address of the AM2315C sensor. ```APIDOC ## Get Address - **uint8_t getAddress()**: Returns the (fixed) address of the sensor. ``` -------------------------------- ### Get Temperature from AM2315C Source: https://github.com/robtillaart/am2315c/blob/master/README.md Get the last read temperature value. Multiple calls return the same value until a new read() is performed. ```cpp float getTemperature() { // Returns last read temperature + optional offset. // Multiple calls will return same value until a new read() is made. } ``` -------------------------------- ### Get Humidity from AM2315C Source: https://github.com/robtillaart/am2315c/blob/master/README.md Get the last read humidity value. Multiple calls return the same value until a new read() is performed. ```cpp float getHumidity() { // Returns last read humidity + optional offset. // Multiple calls will return same value until a new read() is made. } ``` -------------------------------- ### Get Temperature and Humidity Source: https://github.com/robtillaart/am2315c/blob/master/README.md Retrieves the last measured temperature and humidity values. These values remain the same until a new read operation is performed. ```APIDOC ## Get Temperature and Humidity - **float getHumidity()**: Returns the last read humidity, optionally adjusted by an offset. Multiple calls return the same value until a new **read()** is made. - **float getTemperature()**: Returns the last read temperature, optionally adjusted by an offset. Multiple calls return the same value until a new **read()** is made. ``` -------------------------------- ### Get AM2315C Address Source: https://github.com/robtillaart/am2315c/blob/master/README.md Retrieve the fixed I2C address of the AM2315C sensor. ```cpp uint8_t getAddress() ``` -------------------------------- ### Get Internal Sensor Status Source: https://github.com/robtillaart/am2315c/blob/master/README.md Returns the internal status of the sensor, primarily for debugging purposes. ```cpp int internalStatus() ``` -------------------------------- ### Initialize: bool begin() Source: https://context7.com/robtillaart/am2315c/llms.txt Initializes the sensor and verifies its presence on the I2C bus at the default address 0x38. ```APIDOC ## Initialize: bool begin() ### Description Verifies that the sensor is reachable on the I2C bus. Must be called after `Wire.begin()`. Returns `true` if the sensor acknowledges at address 0x38, `false` otherwise. ### Usage ```cpp #include "AM2315C.h" AM2315C DHT; void setup() { Serial.begin(115200); Wire.begin(); if (!DHT.begin()) { Serial.println("AM2315C not found — check wiring!"); while (1); // halt } Serial.print("Sensor at address 0x"); Serial.println(DHT.getAddress(), HEX); // prints: 0x38 } ``` ``` -------------------------------- ### Constructor and Initialization Source: https://github.com/robtillaart/am2315c/blob/master/README.md Initializes the AM2315C sensor. The user must call Wire.begin() before this function. It returns true if the sensor is successfully connected. ```APIDOC ## Constructor - **AM2315C(TwoWire *wire = &Wire)**: Constructor, using a specific Wire (I2C bus). ## Initialization - **bool begin()**: Initializer. Returns true if connected. The user must call **Wire.begin()** before calling this function. ``` -------------------------------- ### Initialize AM2315C Sensor with Default or Custom I2C Bus Source: https://context7.com/robtillaart/am2315c/llms.txt Demonstrates how to instantiate and initialize the AM2315C sensor using the default I2C bus (Wire) or a custom one (e.g., Wire1 on ESP32). Ensure Wire.begin() is called before DHT.begin(). ```cpp #include "AM2315C.h" // Default: use Wire AM2315C DHT; // Alternative: use Wire1 with custom pins (ESP32 example) AM2315C DHT_alt(&Wire1); void setup() { Serial.begin(115200); // Default Wire Wire.begin(); DHT.begin(); // Wire1 on custom pins Wire1.begin(12, 13); Wire1.setClock(400000); DHT_alt.begin(); } ``` -------------------------------- ### Initialize AM2315C Sensor Source: https://github.com/robtillaart/am2315c/blob/master/README.md Initialize the AM2315C sensor. Ensure Wire.begin() is called before this. Returns true if the sensor is connected. ```cpp bool begin() { // User must call Wire.begin() before this function. // Returns true if connected. } ``` -------------------------------- ### Include AM2315C Library Source: https://github.com/robtillaart/am2315c/blob/master/README.md Include the necessary header file for the AM2315C library. ```cpp #include "AM2315C.h" ``` -------------------------------- ### Constructor: AM2315C(TwoWire *wire) Source: https://context7.com/robtillaart/am2315c/llms.txt Initializes the AM2315C sensor object, optionally binding it to a specific I2C bus instance. ```APIDOC ## Constructor: AM2315C(TwoWire *wire) ### Description Creates an AM2315C instance bound to the specified I2C bus. Pass a pointer to `Wire` (default) or any other `TwoWire` instance (e.g., `Wire1` on ESP32) to control which hardware I2C peripheral is used. ### Usage ```cpp #include "AM2315C.h" // Default: use Wire AM2315C DHT; // Alternative: use Wire1 with custom pins (ESP32 example) AM2315C DHT_alt(&Wire1); void setup() { Serial.begin(115200); // Default Wire Wire.begin(); DHT.begin(); // Wire1 on custom pins Wire1.begin(12, 13); Wire1.setClock(400000); DHT_alt.begin(); } ``` ``` -------------------------------- ### Asynchronous Interface Source: https://github.com/robtillaart/am2315c/blob/master/README.md Provides methods for initiating measurements, reading data, and converting raw sensor readings. Note the timing constraints between requests. ```APIDOC ## Asynchronous Interface ### Description Allows for non-blocking sensor operations. Initiate a measurement, and check for data readiness later. ### Methods - **bool isMeasuring()**: Checks if a new measurement is ready. - **int requestData()**: Signals the sensor to start a new measurement. Requires at least 1000ms delay before the next request. - **int readData()**: Reads the raw measurement data from the sensor. - **int convert()**: Converts the raw data into temperature, humidity, and status. ### Timing Constraints - Time between requests: 1000 ms - Time between request and data ready: 80 ms ``` -------------------------------- ### Apply Calibration Offsets to Humidity and Temperature Source: https://context7.com/robtillaart/am2315c/llms.txt Use setHumOffset() and setTempOffset() to apply a first-order correction to sensor readings. Call with no argument or 0 to reset. Offsets are applied automatically on every getHumidity() and getTemperature() call. ```cpp #include "AM2315C.h" AM2315C DHT; void setup() { Serial.begin(115200); Wire.begin(); Wire.setClock(400000); DHT.begin(); delay(1000); } void loop() { // Apply calibration offsets after 10 seconds of warmup if (millis() > 10000) { DHT.setTempOffset(1.7); // sensor reads 1.7 °C low DHT.setHumOffset(-2.3); // sensor reads 2.3 %RH high } if (millis() - DHT.lastRead() >= 2000) { DHT.read(); Serial.print("Humidity: "); Serial.print(DHT.getHumidity(), 1); // offset already applied Serial.print(" %RH (offset: "); Serial.print(DHT.getHumOffset()); Serial.print(") Temp: "); Serial.print(DHT.getTemperature(), 1); // offset already applied Serial.print(" °C (offset: "); Serial.print(DHT.getTempOffset()); Serial.println(")"); } } // Example output after 10 s: // Humidity: 52.1 %RH (offset: -2.3) Temp: 23.8 °C (offset: 1.7) ``` -------------------------------- ### Request Sensor Data Asynchronously Source: https://github.com/robtillaart/am2315c/blob/master/README.md Initiates a new measurement on the sensor. Ensure at least 1000 milliseconds pass between consecutive calls to requestData(). ```cpp int requestData() ``` -------------------------------- ### Set Temperature Offset for AM2315C Source: https://github.com/robtillaart/am2315c/blob/master/README.md Set a calibration offset for the temperature readings. Default is 0. ```cpp void setTempOffset(float offset = 0) { // Set an offset for temperature to calibrate (1st order) the sensor. // Default offset == 0, so no parameter will reset the offset. } ``` -------------------------------- ### Status and Calibration Checks Source: https://github.com/robtillaart/am2315c/blob/master/README.md Methods to query the sensor's operational status, calibration state, and measurement progress. ```APIDOC ## Status ### Description Provides functions to check the current status and calibration of the AM2315C sensor. ### Methods - **uint8_t readStatus()**: Forces a read of the sensor's status register. - **bool isCalibrated()**: Returns true if the sensor is calibrated. - **bool isMeasuring()**: Returns true if the sensor is currently measuring. - **bool isIdle()**: Returns true if the sensor is idle. - **int internalStatus()**: Returns the internal status code of the sensor for debugging purposes. ### Status Bit Meanings | Status Bit | Meaning | |:----------:|:----------------| | 7 | 1 = measuring, 0 = idle | | 6 - 4 | Unknown | | 3 | 1 = calibrated, 0 = not | | 2 - 0 | Unknown | ``` -------------------------------- ### Check if Measurement is Ready Source: https://github.com/robtillaart/am2315c/blob/master/README.md Checks if a new measurement is ready to be read from the sensor. This is useful for asynchronous operation to avoid blocking. ```cpp bool isMeasuring() ``` -------------------------------- ### Verify AM2315C Sensor Connection Source: https://context7.com/robtillaart/am2315c/llms.txt Initializes the AM2315C sensor and checks if it is connected to the I2C bus at address 0x38. Halts execution if the sensor is not found. ```cpp #include "AM2315C.h" AM2315C DHT; void setup() { Serial.begin(115200); Wire.begin(); if (!DHT.begin()) { Serial.println("AM2315C not found — check wiring!"); while (1); // halt } Serial.print("Sensor at address 0x"); Serial.println(DHT.getAddress(), HEX); // prints: 0x38 } ``` -------------------------------- ### Asynchronous Data Interface Source: https://context7.com/robtillaart/am2315c/llms.txt A three-step non-blocking read pipeline for sensor data. `requestData()` initiates a measurement, `readData()` retrieves raw bytes when ready, and `convert()` decodes the data. Ensure at least 1000 ms between `requestData()` calls. ```APIDOC ## requestData() ### Description Sends the measurement trigger command to the sensor and records the request timestamp. This is the first step in the asynchronous read process. ### Method int ``` ```APIDOC ## readData() ### Description Retrieves the 7 raw bytes of sensor data once it is ready. This should be called after `requestData()` and approximately 80 ms later, or after `isMeasuring()` returns false. ### Method int ``` ```APIDOC ## convert() ### Description Decodes the raw sensor data bits into humidity and temperature values, including CRC validation. This is the final step in the asynchronous read process. ### Method int ``` -------------------------------- ### Asynchronous Data Reading Pipeline Source: https://context7.com/robtillaart/am2315c/llms.txt Utilize requestData(), readData(), and convert() for a non-blocking sensor reading process. Ensure at least 1000 ms between requestData() calls. readData() retrieves raw bytes, and convert() decodes them with CRC validation. ```cpp #include "AM2315C.h" AM2315C DHT; uint32_t counter = 0; void setup() { Serial.begin(115200); Wire.begin(); DHT.begin(); delay(2000); DHT.requestData(); // kick off first measurement } void loop() { // Once per second: collect result, print, issue next request if (millis() - DHT.lastRead() > 1000) { int r = DHT.readData(); if (r > 0) { int c = DHT.convert(); if (c == AM2315C_OK) { Serial.print(DHT.getHumidity(), 1); Serial.print(" %RH\t"); Serial.print(DHT.getTemperature(), 1); Serial.print(" °C\tloop iterations since last read: "); Serial.println(counter); } } counter = 0; DHT.requestData(); // request next measurement } // Non-blocking work continues here unimpeded counter++; } // Expected output: // 55.2 %RH 22.4 °C loop iterations since last read: 18342 ``` -------------------------------- ### Synchronous Read: int8_t read() Source: https://context7.com/robtillaart/am2315c/llms.txt Triggers a measurement, waits for data, and reads/converts humidity and temperature. Returns status code. ```APIDOC ## Synchronous Blocking Read: int8_t read() ### Description Triggers a measurement, waits for data ready (~80 ms), reads and converts the raw bytes, then stores humidity and temperature internally. Returns `AM2315C_OK` (0) on success or a negative error code. Must not be called more than once per second. ### Return Value - `AM2315C_OK` (0) on success. - Negative error codes for various failure conditions (e.g., `AM2315C_ERROR_CHECKSUM`, `AM2315C_ERROR_CONNECT`). ### Usage ```cpp #include "AM2315C.h" AM2315C DHT; void setup() { Serial.begin(115200); Wire.begin(); DHT.begin(); delay(1000); } void loop() { // guard: read at most once per second if (millis() - DHT.lastRead() >= 1000) { int status = DHT.read(); if (status == AM2315C_OK) { Serial.print("Humidity: "); Serial.print(DHT.getHumidity(), 1); Serial.println(" %RH"); Serial.print("Temperature: "); Serial.print(DHT.getTemperature(), 1); Serial.println(" °C"); } else { switch (status) { case AM2315C_ERROR_CHECKSUM: Serial.println("Error: checksum mismatch"); break; case AM2315C_ERROR_CONNECT: Serial.println("Error: sensor not connected"); break; case AM2315C_MISSING_BYTES: Serial.println("Error: missing bytes"); break; case AM2315C_ERROR_BYTES_ALL_ZERO: Serial.println("Error: all bytes zero"); break; case AM2315C_ERROR_READ_TIMEOUT: Serial.println("Error: read timeout"); break; case AM2315C_ERROR_LASTREAD: Serial.println("Error: read too fast"); break; default: Serial.println("Error: unknown"); break; } } } } // Expected output: // Humidity: 54.3 %RH // Temperature: 22.1 °C ``` ``` -------------------------------- ### Set Humidity Offset for AM2315C Source: https://github.com/robtillaart/am2315c/blob/master/README.md Set a calibration offset for the humidity readings. Default is 0. ```cpp void setHumOffset(float offset = 0) { // Set an offset for humidity to calibrate (1st order) the sensor. // Default offset == 0, so no parameter will reset the offset. } ``` -------------------------------- ### Calibration Offsets Source: https://context7.com/robtillaart/am2315c/llms.txt Apply and retrieve calibration offsets for humidity and temperature readings. These offsets are applied to raw sensor values on every read operation. Call with no argument or 0 to reset the offsets. ```APIDOC ## setHumOffset(float offset) / setTempOffset(float offset) ### Description Applies a first-order correction offset to humidity and/or temperature. The offset is added to the raw sensor value on every `getHumidity()` / `getTemperature()` call. Call with no argument (or `0`) to reset. ### Parameters #### Path Parameters - **offset** (float) - Required - The offset value to apply. ### Method void ``` ```APIDOC ## getHumOffset() / getTempOffset() ### Description Reads back the current humidity and temperature calibration offsets. ### Method float ``` -------------------------------- ### Convert Sensor Readings Source: https://github.com/robtillaart/am2315c/blob/master/README.md Converts the raw bits read from the sensor into temperature and humidity values. This should be called as the final step after readData(). ```cpp int convert() ``` -------------------------------- ### Access Cached Humidity and Temperature Values Source: https://context7.com/robtillaart/am2315c/llms.txt Retrieves the last successfully read humidity and temperature values from the sensor's internal cache. These values are updated by `read()` or `convert()` and include any applied calibration offsets. ```cpp #include "AM2315C.h" AM2315C DHT; void setup() { Serial.begin(115200); Wire.begin(); DHT.begin(); delay(1000); DHT.read(); } void loop() { // Multiple accesses without re-reading — same values returned float hum = DHT.getHumidity(); // e.g. 55.4 float temp = DHT.getTemperature(); // e.g. 21.8 Serial.print(hum); Serial.print(" %RH | "); Serial.print(temp); Serial.println(" °C"); delay(2000); DHT.read(); // update cached values } ``` -------------------------------- ### Perform Synchronous Blocking Read from AM2315C Source: https://context7.com/robtillaart/am2315c/llms.txt Triggers a measurement, waits for data, and reads humidity and temperature. Includes error handling for various sensor states and a guard to prevent reading more than once per second. ```cpp #include "AM2315C.h" AM2315C DHT; void setup() { Serial.begin(115200); Wire.begin(); DHT.begin(); delay(1000); } void loop() { // guard: read at most once per second if (millis() - DHT.lastRead() >= 1000) { int status = DHT.read(); if (status == AM2315C_OK) { Serial.print("Humidity: "); Serial.print(DHT.getHumidity(), 1); Serial.println(" %RH"); Serial.print("Temperature: "); Serial.print(DHT.getTemperature(), 1); Serial.println(" °C"); } else { switch (status) { case AM2315C_ERROR_CHECKSUM: Serial.println("Error: checksum mismatch"); break; case AM2315C_ERROR_CONNECT: Serial.println("Error: sensor not connected"); break; case AM2315C_MISSING_BYTES: Serial.println("Error: missing bytes"); break; case AM2315C_ERROR_BYTES_ALL_ZERO: Serial.println("Error: all bytes zero"); break; case AM2315C_ERROR_READ_TIMEOUT: Serial.println("Error: read timeout"); break; case AM2315C_ERROR_LASTREAD: Serial.println("Error: read too fast"); break; default: Serial.println("Error: unknown"); break; } } } } // Expected output: // Humidity: 54.3 %RH // Temperature: 22.1 °C ``` -------------------------------- ### lastRead() / lastRequest() Source: https://context7.com/robtillaart/am2315c/llms.txt Timing utilities that return the `millis()` timestamp of the most recent successful `readData()` call (`lastRead()`) or `requestData()` call (`lastRequest()`). These are used to enforce the minimum inter-read constraint (≥1000 ms) and to schedule asynchronous reads without blocking delays. ```APIDOC ## lastRead() / lastRequest() ### Description `lastRead()` returns the `millis()` timestamp of the most recent successful `readData()` call. `lastRequest()` returns the timestamp of the most recent `requestData()` call. Both are used to enforce the ≥1000 ms inter-read constraint and to schedule asynchronous reads without blocking delays. ### Returns - `uint32_t`: The `millis()` timestamp of the last relevant call. ### Example Usage ```cpp #include "AM2315C.h" AM2315C DHT; void setup() { Serial.begin(115200); Wire.begin(); DHT.begin(); delay(1000); } void loop() { uint32_t now = millis(); Serial.print("Time since last read: "); Serial.print(now - DHT.lastRead()); Serial.print(" ms | Time since last request: "); Serial.print(now - DHT.lastRequest()); Serial.println(" ms"); // Only read when 1 second has elapsed since last read if (now - DHT.lastRead() >= 1000) { int status = DHT.read(); if (status == AM2315C_OK) { Serial.print("Read OK at "); Serial.print(DHT.lastRead()); Serial.println(" ms"); } } delay(250); } ``` ``` -------------------------------- ### Timing Information Source: https://github.com/robtillaart/am2315c/blob/master/README.md Retrieves timestamps related to the last sensor read and measurement request. ```APIDOC ## Timing ### Description Provides access to timing information for sensor operations. ### Methods - **uint32_t lastRead()**: Returns the timestamp of the last successful sensor read in milliseconds. - **uint32_t lastRequest()**: Returns the timestamp of the last measurement request in milliseconds. ``` -------------------------------- ### Read AM2315C Sensor Data Source: https://github.com/robtillaart/am2315c/blob/master/README.md Read the latest temperature and humidity data from the sensor. This is a blocking call. Returns AM2315C_OK (0) on success. ```cpp int8_t read() { // Read the sensor and store the values internally. // Returns the status of the read which should be 0 == AM2315C_OK. } ``` -------------------------------- ### Read Sensor Data Source: https://github.com/robtillaart/am2315c/blob/master/README.md Reads the data from the sensor after a measurement is ready. This function should be called after confirming data is ready using isMeasuring() or after a sufficient delay. ```cpp int readData() ``` -------------------------------- ### Error Codes Source: https://github.com/robtillaart/am2315c/blob/master/README.md Lists and explains the possible error codes returned by the library functions. ```APIDOC ## Error Codes ### Description Defines the error codes that can be returned by the library functions, along with their meanings and notes. | Name | Value | Notes | |:----------------------------|:-----:|:----------------------------------------------------------------------| | AM2315C_OK | 00 | OK | | AM2315C_ERROR_CHECKSUM | -10 | Values might be OK if they are like recent previous ones. | | AM2315C_ERROR_CONNECT | -11 | Check connection. | | AM2315C_MISSING_BYTES | -12 | Check connection. | | AM2315C_ERROR_BYTES_ALL_ZERO| -13 | Check connection. | | AM2315C_ERROR_READ_TIMEOUT | -14 | | | AM2315C_ERROR_LASTREAD | -15 | Wait 1 second between reads. | ``` -------------------------------- ### Sensor Reading Source: https://github.com/robtillaart/am2315c/blob/master/README.md Reads the temperature and humidity from the sensor. The read operation is blocking and takes over 80 milliseconds. The status of the read operation is returned. ```APIDOC ## Sensor Reading - **int8_t read()**: Reads the sensor and stores the values internally. Returns the status of the read, which should be 0 for AM2315C_OK. ``` -------------------------------- ### Experimental Reset Sensor Source: https://github.com/robtillaart/am2315c/blob/master/README.md An experimental function to reset specific sensor registers, potentially resolving communication issues. Use with caution. ```APIDOC ## Experimental Reset Sensor ### Description Resets registers 0x1B, 0x1C, and 0x1E. This is an experimental feature based on AHT20 examples and may be necessary if the sensor does not return a status of 0x18 at startup. ### Method - **uint8_t resetSensor()**: Resets specific internal registers. This function is embedded within read calls in version 0.2.0 and later. ``` -------------------------------- ### Access Cached Values: float getHumidity(), float getTemperature() Source: https://context7.com/robtillaart/am2315c/llms.txt Retrieves the last cached humidity and temperature values from the sensor. ```APIDOC ## Access Cached Values: float getHumidity() / float getTemperature() ### Description Return the humidity (% RH) and temperature (°C) stored from the last successful `read()` or `convert()` call. Applying offsets is automatic — raw values plus any configured offset are returned. Repeated calls return the same value until a new read is performed. ### Return Value - `getHumidity()`: Returns the cached relative humidity in %RH as a float. - `getTemperature()`: Returns the cached temperature in °C as a float. ### Usage ```cpp #include "AM2315C.h" AM2315C DHT; void setup() { Serial.begin(115200); Wire.begin(); DHT.begin(); delay(1000); DHT.read(); } void loop() { // Multiple accesses without re-reading — same values returned float hum = DHT.getHumidity(); // e.g. 55.4 float temp = DHT.getTemperature(); // e.g. 21.8 Serial.print(hum); Serial.print(" %RH | "); Serial.print(temp); Serial.println(" °C"); delay(2000); DHT.read(); // update cached values } ``` ``` -------------------------------- ### resetSensor() Source: https://context7.com/robtillaart/am2315c/llms.txt Resets internal sensor registers if the status byte does not equal 0x18 at startup. This function can be called manually or is invoked automatically within `requestData()`. It returns 255 if no reset was needed, 3 if all registers were successfully reset, or 0-2 on partial failure. ```APIDOC ## resetSensor() ### Description Resets three internal sensor registers (0x1B, 0x1C, 0x1E) if the status byte does not equal 0x18 at startup (per datasheet section 7.4). This is called automatically within `requestData()` but can also be invoked manually. ### Returns - `uint8_t`: 255 if no reset was needed, 3 if all registers were successfully reset, or 0–2 on partial failure. ### Example Usage ```cpp #include "AM2315C.h" AM2315C DHT; void setup() { Serial.begin(115200); Wire.begin(); DHT.begin(); delay(1000); // Manually trigger a sensor reset check uint8_t result = DHT.resetSensor(); if (result == 255) { Serial.println("Reset not needed (status already 0x18)."); } else if (result == 3) { Serial.println("Sensor successfully reset (3/3 registers written)."); } else { Serial.print("Partial reset: "); Serial.print(result); Serial.println("/3 registers written — check I2C connection."); } } void loop() { // ... your loop code ... } ``` ``` -------------------------------- ### Check Bus Presence: bool isConnected() Source: https://context7.com/robtillaart/am2315c/llms.txt Checks if the sensor is currently connected to the I2C bus without re-initializing. ```APIDOC ## Check Bus Presence: bool isConnected() ### Description Probes the I2C bus for the sensor's fixed address (0x38). Useful for runtime connection monitoring without re-initialising. ### Usage ```cpp #include "AM2315C.h" AM2315C DHT; void loop() { if (!DHT.isConnected()) { Serial.println("Sensor disconnected!"); delay(1000); return; } // proceed with read } ``` ``` -------------------------------- ### Check if Sensor is Calibrated Source: https://github.com/robtillaart/am2315c/blob/master/README.md Checks if the sensor is calibrated. This is a wrapper function around readStatus(). ```cpp bool isCalibrated() ``` -------------------------------- ### Manually Reset AM2315C Sensor Source: https://context7.com/robtillaart/am2315c/llms.txt This snippet demonstrates how to manually trigger a sensor reset check. The reset is performed if the status byte is not 0x18 at startup. The function returns different values indicating the success or failure of the reset operation. ```cpp #include "AM2315C.h" AM2315C DHT; void setup() { Serial.begin(115200); Wire.begin(); DHT.begin(); delay(1000); // Manually trigger a sensor reset check uint8_t result = DHT.resetSensor(); if (result == 255) { Serial.println("Reset not needed (status already 0x18)."); } else if (result == 3) { Serial.println("Sensor successfully reset (3/3 registers written)."); } else { Serial.print("Partial reset: "); Serial.print(result); Serial.println("/3 registers written — check I2C connection."); } } void loop() { if (millis() - DHT.lastRead() >= 1000) { int status = DHT.read(); if (status == AM2315C_OK) { Serial.print(DHT.getHumidity(), 1); Serial.print(" %RH "); Serial.print(DHT.getTemperature(), 1); Serial.println(" °C"); } } } ``` -------------------------------- ### Reset Sensor Registers Source: https://github.com/robtillaart/am2315c/blob/master/README.md Resets specific sensor registers (0x1B, 0x1C, 0x1E) if the sensor does not return a status of 0x18 at startup. Use with caution as the meaning of these registers is not documented. ```cpp uint8_t resetSensor() ``` -------------------------------- ### Connection Check Source: https://github.com/robtillaart/am2315c/blob/master/README.md Checks if the AM2315C sensor is connected to the I2C bus. ```APIDOC ## Connection Check - **bool isConnected()**: Returns true if the address of the AM2315C can be seen on the I2C bus. ``` -------------------------------- ### Sensor Status Source: https://context7.com/robtillaart/am2315c/llms.txt Provides functions to read the sensor's status register and check its current state. `readStatus()` performs a direct I2C read, while helper functions provide boolean checks for calibration, measurement, and idle states. ```APIDOC ## readStatus() ### Description Performs a direct I2C read of the sensor's 1-byte status register. ### Method uint8_t ``` ```APIDOC ## isCalibrated() ### Description Checks if the sensor is calibrated. This is a convenience wrapper that calls `readStatus()` internally. ### Method bool ``` ```APIDOC ## isMeasuring() ### Description Checks if the sensor is currently performing a measurement. This is a convenience wrapper that calls `readStatus()` internally. ### Method bool ``` ```APIDOC ## isIdle() ### Description Checks if the sensor is idle and ready for a new command. This is a convenience wrapper that calls `readStatus()` internally. ### Method bool ``` ```APIDOC ## internalStatus() ### Description Returns the status byte cached during the last `read()` call without performing new I2C traffic. ### Method uint8_t ``` -------------------------------- ### Check if Sensor is Idle Source: https://github.com/robtillaart/am2315c/blob/master/README.md Checks if the sensor is in an idle state. This is a wrapper function around readStatus(). ```cpp bool isIdle() ``` -------------------------------- ### Read Sensor Status Register Source: https://context7.com/robtillaart/am2315c/llms.txt Use readStatus() for a direct I2C read of the sensor's status byte. Convenience functions isCalibrated(), isMeasuring(), and isIdle() wrap this call. internalStatus() returns the cached status from the last read without new I2C traffic. ```cpp #include "AM2315C.h" AM2315C DHT; void setup() { Serial.begin(115200); Wire.begin(); Wire.setClock(400000); DHT.begin(); delay(2000); // Check calibration at startup if (!DHT.isCalibrated()) { Serial.println("WARNING: sensor not calibrated!"); } // Poll until idle before first read while (DHT.isMeasuring()) { Serial.println("Sensor busy, waiting..."); delay(10); } Serial.println("Sensor idle, ready to read."); uint8_t rawStatus = DHT.readStatus(); Serial.print("Raw status register: 0x"); Serial.println(rawStatus, HEX); // e.g. 0x18 (calibrated + idle) } void loop() { if (millis() - DHT.lastRead() >= 1000) { DHT.read(); Serial.print("Internal status after read: 0x"); Serial.println(DHT.internalStatus(), HEX); } } ``` -------------------------------- ### Check AM2315C Connection Source: https://github.com/robtillaart/am2315c/blob/master/README.md Check if the AM2315C sensor is connected and visible on the I2C bus. ```cpp bool isConnected() ``` -------------------------------- ### Monitor AM2315C Sensor Bus Presence Source: https://context7.com/robtillaart/am2315c/llms.txt Continuously checks if the AM2315C sensor is present on the I2C bus. This is useful for detecting disconnections during runtime without re-initializing the sensor. ```cpp #include "AM2315C.h" AM2315C DHT; void loop() { if (!DHT.isConnected()) { Serial.println("Sensor disconnected!"); delay(1000); return; } // proceed with read } ``` -------------------------------- ### Read Sensor Status Source: https://github.com/robtillaart/am2315c/blob/master/README.md Forcibly reads only the status of the sensor. This function may block for a few milliseconds to optimize communication. ```cpp uint8_t readStatus() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.