Nol.A SDK Library 26.11.2
For IoT System Software Development
Loading...
Searching...
No Matches
SHTSensor Class Reference

#include <SHTSensor.hpp>

Public Types

enum  SHTSensorType {
  AUTO_DETECT , SHT3X , SHT85 , SHT3X_ALT ,
  SHTC1 , SHTC3 , SHTW1 , SHTW2 ,
  SHT4X
}
enum  SHTAccuracy { SHT_ACCURACY_HIGH , SHT_ACCURACY_MEDIUM , SHT_ACCURACY_LOW }

Public Member Functions

 SHTSensor (SHTSensorType sensorType=AUTO_DETECT)
virtual ~SHTSensor ()
 Release the owned digital sensor driver.
bool init (TwoWire &wire)
bool readSample ()
float getHumidity () const
float getTemperature () const
bool setAccuracy (SHTAccuracy newAccuracy)

Public Attributes

SHTSensorType mSensorType
 Sensor selection supplied to the constructor; configure before init().

Static Public Attributes

static const float HUMIDITY_INVALID
static const float TEMPERATURE_INVALID
static const SHTSensorType AUTO_DETECT_SENSORS []

Detailed Description

Official interface for Sensirion SHT Sensors

Examples
rak3172/I2C-SHTSensor/main.cpp.

Member Enumeration Documentation

◆ SHTAccuracy

Accuracy setting of measurement. Not all sensors support changing the sampling accuracy.

Enumerator
SHT_ACCURACY_HIGH 

Highest repeatability at the cost of slower measurement

SHT_ACCURACY_MEDIUM 

Balanced repeatability and speed of measurement

SHT_ACCURACY_LOW 

Fastest measurement but lowest repeatability

80 {
87 };
@ SHT_ACCURACY_LOW
Definition SHTSensor.hpp:86
@ SHT_ACCURACY_MEDIUM
Definition SHTSensor.hpp:84
@ SHT_ACCURACY_HIGH
Definition SHTSensor.hpp:82

◆ SHTSensorType

Enum of the supported Digital Sensirion SHT Sensors. For analog sensors, see SHT3xAnalogSensor. Using the special AUTO_DETECT sensor causes all i2c sensors to be probed. The first matching sensor will then be used.

Enumerator
AUTO_DETECT 

Automatically detect the sensor type (only i2c sensors listed above)

SHT3X 

SHT3x-DIS with ADDR (sensor pin 2) connected to VSS (default)

SHT3X_ALT 

SHT3x-DIS with ADDR (sensor pin 2) connected to VDD

60 {
63 // i2c Sensors:
65 SHT3X,
66 SHT85,
69 SHTC1,
70 SHTC3,
71 SHTW1,
72 SHTW2,
73 SHT4X
74 };
@ AUTO_DETECT
Definition SHTSensor.hpp:62
@ SHT3X
Definition SHTSensor.hpp:65
@ SHT3X_ALT
Definition SHTSensor.hpp:68

Constructor & Destructor Documentation

◆ SHTSensor()

SHTSensor::SHTSensor ( SHTSensorType sensorType = AUTO_DETECT)
inline

Instantiate a new SHTSensor By default, the i2c bus is queried for known SHT Sensors. To address a specific sensor, set the sensorType.

106 : mSensorType(sensorType),
107 mSensor(NULL),
108 mTemperature(SHTSensor::TEMPERATURE_INVALID),
110 {
111 }
static const float HUMIDITY_INVALID
Definition SHTSensor.hpp:90
static const float TEMPERATURE_INVALID
Definition SHTSensor.hpp:92
SHTSensorType mSensorType
Sensor selection supplied to the constructor; configure before init().
Definition SHTSensor.hpp:169

◆ ~SHTSensor()

virtual SHTSensor::~SHTSensor ( )
inlinevirtual

Release the owned digital sensor driver.

116 {
117 cleanup();
118 }

Member Function Documentation

◆ getHumidity()

float SHTSensor::getHumidity ( ) const
inline

Get the relative humidity in percent read from the last sample Use readSample() to trigger a new sensor reading

148 {
149 return mHumidity;
150 }

◆ getTemperature()

float SHTSensor::getTemperature ( ) const
inline

Get the temperature in Celsius read from the last sample Use readSample() to trigger a new sensor reading

156 {
157 return mTemperature;
158 }

◆ init()

bool SHTSensor::init ( TwoWire & wire)

Initialize the sensor driver, and probe for the sensor on the bus

If SHTSensor() was created with an empty constructor or with 'sensorType' AUTO_DETECT, init() will also try to automatically detect a sensor. Auto detection will stop as soon as the first sensor was found; if you have multiple sensor types on the bus, use the 'sensorType' argument of the constructor to control which sensor type will be instantiated.

To read out the sensor use readSample(), followed by getTemperature() and getHumidity() to retrieve the values from the sample

Returns true if communication with a sensor on the bus was successful, false otherwise

◆ readSample()

bool SHTSensor::readSample ( )

Read new values from the sensor After the call, use getTemperature() and getHumidity() to retrieve the values Returns true if the sample was read and the values are cached

◆ setAccuracy()

bool SHTSensor::setAccuracy ( SHTAccuracy newAccuracy)

Change the sensor accurancy, if supported by the sensor Returns true if the accuracy was changed

Member Data Documentation

◆ AUTO_DETECT_SENSORS

const SHTSensorType SHTSensor::AUTO_DETECT_SENSORS[]
static

Auto-detectable sensor types. Note that the SHTC3, SHTW1 and SHTW2 share exactly the same driver as the SHTC1 and are thus not listed individually.

◆ HUMIDITY_INVALID

const float SHTSensor::HUMIDITY_INVALID
static

Value reported by getHumidity() when the sensor is not initialized

◆ TEMPERATURE_INVALID

const float SHTSensor::TEMPERATURE_INVALID
static

Value reported by getTemperature() when the sensor is not initialized


The documentation for this class was generated from the following file: