T9602
Library for the IP67-rated T9602 I2C temperature and relative humidity sensor.
#include <T9602.h>
Inherits from NW_PlainSensor
Public Functions
| Name | |
|---|---|
| T9602() Instantiate the T9602 sensor class. |
|
| bool | begin(uint8t ADR =DEFAULT_ADDRESS) Begin communications with the T9602 sensor. |
| bool | updateMeasurements() Measure relative humidity [%] and temperature [degrees C]. |
| uint16_t | setReadings(uint16_t n) Set how many readings updateMeasurements() takes (statistics are computed over them). Clamped to T9602_CAPACITY. |
| void | setStats(bool enable) Enable or disable humidity and temperature std and sterr columns in printDataHeader()/printDataRow(). |
| uint16_t | getReadingCount() Number of valid readings stored by the last updateMeasurements(). |
| uint8_t | getStatus() Status bits from the last data fetch. |
| float | getHumidity() Return the stored relative humidity [%]: the mean of the last updateMeasurements(), NW_ERROR (-9999) when none was valid. |
| float | getHumidityMean() Humidity mean [%] over the stored readings. |
| float | getHumidityStd() Humidity standard deviation [%]. |
| float | getHumiditySterr() Humidity standard error [%]. |
| float | getHumidityMedian() Humidity median [%] (mean of the middle pair for even N). |
| float | getTemperatureMean() Temperature mean [C] over the stored readings. |
| float | getTemperatureStd() Temperature standard deviation [C]. |
| float | getTemperatureSterr() Temperature standard error [C]. |
| float | getTemperatureMedian() Temperature median [C]. |
| float | getTemperature() Return the stored temperature [degrees C]. |
| size_t | printDataHeader(Print & out) override Print the summary columns a logger writes: the means, with the statistics columns when they are enabled. |
| size_t | printDataRow(Print & out) override Print one summary row, in printDataHeader()’s column order. |
| const char * | name() const override The part’s name, for the status file and for a sketch’s own use. |
| uint8_t | defaultAddress() const override The address it answers at unless the logger says otherwise. |
| bool | wake(uint8_t address) override Come back on the bus after the logger cut the sensor rail to sleep. |
| bool | acquire() override Take this row’s readings, for printDataRow() to print. |
| bool | sleep() Dummy function to enable sleep mode. |
| size_t | printHeader(Print & out) Print the header matching printReading(): “Humidity [%],Temp Atmos [C],”. No statistics columns: one reading has none. |
| size_t | printReading(Print & out) Print the stored reading, each value followed by a comma. Does not acquire: call updateMeasurements() first, or use logReading(). |
| size_t | logReading(Print & out) Take ONE reading and print it: the one-reading primitive for collecting many readings to a file. |
| void | beginReadings(uint16_t n =0) Begin a run of readings. The T9602 is not a Schema 1 device, so n is only the number of logReading() calls to follow; nothing is declared to the sensor. |
| void | endReadings() End a run of readings. |
Public Attributes
| Name | |
|---|---|
| constexpr uint8_t | DEFAULT_ADDRESS Default I2C address. The part fixes it: there is no strapping pin and no register to change it. |
Public Functions Documentation
function T9602
T9602()
Instantiate the T9602 sensor class.
function begin
bool begin(
uint8_t ADR_ =DEFAULT_ADDRESS
)
Begin communications with the T9602 sensor.
Parameters:
- ADR_ I2C address. Defaults to 0x28. This library cannot change this, but this option exists in case you make this change elsewhere.
Return: true if the sensor acknowledges its address on the bus.
function updateMeasurements
bool updateMeasurements()
Measure relative humidity [%] and temperature [degrees C].
Return: true if every reading was valid. false if any timed out (stale or no data, sensor in command mode, or no sensor); the stored values are NW_ERROR (-9999) when none was valid.
Takes setReadings(n) readings (default one). Each sends a measurement request, then fetches data until the sensor’s status bits report a valid (not yet fetched) measurement, or until T9602_TIMEOUT_MS passes; readings are therefore independent measurement cycles. The getters return the mean of the readings taken.
function setReadings
uint16_t setReadings(
uint16_t n
)
Set how many readings updateMeasurements() takes (statistics are computed over them). Clamped to T9602_CAPACITY.
Return: The number actually set.
function setStats
void setStats(
bool enable
)
Enable or disable humidity and temperature std and sterr columns in printDataHeader()/printDataRow().
function getReadingCount
uint16_t getReadingCount()
Number of valid readings stored by the last updateMeasurements().
function getStatus
uint8_t getStatus()
Status bits from the last data fetch.
Return: 0: valid data; 1: stale data (already fetched since the last measurement cycle); 2: sensor in command mode (start-up); 3: no data (no sensor on the bus).
function getHumidity
float getHumidity()
Return the stored relative humidity [%]: the mean of the last updateMeasurements(), NW_ERROR (-9999) when none was valid.
function getHumidityMean
float getHumidityMean()
Humidity mean [%] over the stored readings.
function getHumidityStd
float getHumidityStd()
Humidity standard deviation [%].
function getHumiditySterr
float getHumiditySterr()
Humidity standard error [%].
function getHumidityMedian
float getHumidityMedian()
Humidity median [%] (mean of the middle pair for even N).
function getTemperatureMean
float getTemperatureMean()
Temperature mean [C] over the stored readings.
function getTemperatureStd
float getTemperatureStd()
Temperature standard deviation [C].
function getTemperatureSterr
float getTemperatureSterr()
Temperature standard error [C].
function getTemperatureMedian
float getTemperatureMedian()
Temperature median [C].
function getTemperature
float getTemperature()
Return the stored temperature [degrees C].
function printDataHeader
size_t printDataHeader(
Print & out
) override
Print the summary columns a logger writes: the means, with the statistics columns when they are enabled.
Parameters:
- out Where to print.
Return: Bytes printed.
“Humidity [%],Temp Atmos [C],” with std and sterr columns after each value when setStats(true) is on. Pass a File to write the card, Serial to write the monitor. Distinct from printHeader(), which is the burst interface and carries no statistics.
function printDataRow
size_t printDataRow(
Print & out
) override
Print one summary row, in printDataHeader()’s column order.
Parameters:
- out Where to print.
Return: Bytes printed.
Takes no reading: it prints what the last updateMeasurements() left, which is what lets a caller write the same row to two sinks without acquiring twice.
function name
inline const char * name() const override
The part’s name, for the status file and for a sketch’s own use.
function defaultAddress
inline uint8_t defaultAddress() const override
The address it answers at unless the logger says otherwise.
function wake
inline bool wake(
uint8_t address
) override
Come back on the bus after the logger cut the sensor rail to sleep.
function acquire
inline bool acquire() override
Take this row’s readings, for printDataRow() to print.
function sleep
bool sleep()
Dummy function to enable sleep mode.
Currently not used. Instead, we simply power the sensor down.
function printHeader
size_t printHeader(
Print & out
)
Print the header matching printReading(): “Humidity [%],Temp Atmos [C],”. No statistics columns: one reading has none.
Parameters:
- out Any Print destination (SdFat File, Serial, …).
Return: Bytes written.
function printReading
size_t printReading(
Print & out
)
Print the stored reading, each value followed by a comma. Does not acquire: call updateMeasurements() first, or use logReading().
Return: Bytes written.
function logReading
size_t logReading(
Print & out
)
Take ONE reading and print it: the one-reading primitive for collecting many readings to a file.
Return: Bytes written.
function beginReadings
void beginReadings(
uint16_t n =0
)
Begin a run of readings. The T9602 is not a Schema 1 device, so n is only the number of logReading() calls to follow; nothing is declared to the sensor.
function endReadings
void endReadings()
End a run of readings.
Public Attributes Documentation
variable DEFAULT_ADDRESS
static constexpr uint8_t DEFAULT_ADDRESS = 0x28;
Default I2C address. The part fixes it: there is no strapping pin and no register to change it.
Updated on 2026-10-04 at 04:51:47 +0000