src/T9602.h
Classes
| Name | |
|---|---|
| class | T9602 Library for the IP67-rated T9602 I2C temperature and relative humidity sensor. |
Defines
| Name | |
|---|---|
| T9602_LIBRARY_VERSION | |
| T9602_LIBRARY_COMMIT | |
| T9602_CAPACITY | |
| T9602_TIMEOUT_MS |
Macros Documentation
define T9602_LIBRARY_VERSION
#define T9602_LIBRARY_VERSION "0.0.0"
define T9602_LIBRARY_COMMIT
#define T9602_LIBRARY_COMMIT ""
define T9602_CAPACITY
#define T9602_CAPACITY 16
Readings per updateMeasurements() are kept in static arrays of this capacity (no heap); setReadings(n) clamps to it. Override before the include to trade RAM for a longer batch.
define T9602_TIMEOUT_MS
#define T9602_TIMEOUT_MS 250
Longest wait for valid data in updateMeasurements() [ms]. The ChipCap 2 core takes up to 165 ms per measurement cycle in Update mode and up to 55 ms to start up (Amphenol AAS-916-127, Table 5). Override before the include if needed.
Source code
#ifndef T9602_h
#define T9602_h
#include "Arduino.h"
#include "Wire.h"
#include <NW_Core.h> //NW_Core: NW_PlainSensor, NW_Readings (statistics), NW_ReadingsConfig, NW_ERROR
//Build identity: this library's version (held equal to library.properties by
//NW-Tests/version_check.py) and its build commit, which the NW-Build wrapper
//sets from git and an Arduino IDE build leaves blank. Both reach a logger's
//status file.
#define T9602_LIBRARY_VERSION "0.0.0"
#ifndef T9602_LIBRARY_COMMIT
#define T9602_LIBRARY_COMMIT ""
#endif
#ifndef T9602_CAPACITY
#define T9602_CAPACITY 16
#endif
#ifndef T9602_TIMEOUT_MS
#define T9602_TIMEOUT_MS 250
#endif
class T9602 : public NW_PlainSensor {
public:
static constexpr uint8_t DEFAULT_ADDRESS = 0x28;
T9602();
bool begin(uint8_t ADR_ = DEFAULT_ADDRESS); //use default address
bool updateMeasurements();
uint16_t setReadings(uint16_t n);
void setStats(bool enable);
uint16_t getReadingCount();
uint8_t getStatus();
float getHumidity();
//--- Statistics getters ---
//Computed two-pass in 32-bit float over the readings stored by the last
//updateMeasurements() (NW_Readings). NW_ERROR when there are none.
float getHumidityMean();
float getHumidityStd();
float getHumiditySterr();
float getHumidityMedian();
float getTemperatureMean();
float getTemperatureStd();
float getTemperatureSterr();
float getTemperatureMedian();
float getTemperature();
size_t printDataHeader(Print& out) override;
size_t printDataRow(Print& out) override;
//--- NW_Sensor, through NW_PlainSensor: what a logger asks of a sensor ---
//The T9602 has no Page 0 and no Report register, so it names itself here
//rather than on the bus and NW_Logger::discover() cannot find it. A sketch
//names it and watch() logs its columns like any other sensor's.
const char* name() const override {
return "T9602";
}
uint8_t defaultAddress() const override {
return DEFAULT_ADDRESS;
}
bool wake(uint8_t address) override {
return begin(address);
}
bool acquire() override {
return updateMeasurements();
}
bool sleep();
//--- Reading interface (NW standard) ---
size_t printHeader(Print& out);
size_t printReading(Print& out);
size_t logReading(Print& out);
void beginReadings(uint16_t n = 0);
void endReadings();
private:
uint8_t ADR = 0x28; //Default global sensor address
uint8_t status = 3; //Status bits from the last data fetch
float RH = NW_ERROR; //Mean of the last updateMeasurements()
float Temp = NW_ERROR;
bool readOnce(); //One measurement cycle, appended to the readings
NW_Readings<float, T9602_CAPACITY> _rh; //[%]
NW_Readings<float, T9602_CAPACITY> _temp; //[C]
NW_ReadingsConfig _cfg; //Readings per updateMeasurements() and the stats columns
};
#endif
Updated on 2026-10-04 at 04:51:47 +0000