There is a lot of different sensors for this kind of job. In this post we are going to present the new version of one of the most popular sensors for this kind of measurement. SHT click caries the new SHT3x-DIS by Sensirion. If you are not new to the embedded world, you probably know of the SHT1x click board that is one of the most popular sensors. Especially if we are talking about sensors for humidity and temperature measurement.
SHT Click
SHT3x-DIS is new generation of sensors with increased intelligence, reliability and improved accuracy. Sensor is already calibrated, linearized and temperature compensated. SHT click board supports 3.3 and 5V power supply and communication with the host MCU is performed through the I2C bus with speed up to 1 MHz.
Recommended operation temperature is 5 C - 60 C and 20% - 80% for humidity. Long-term exposure to conditions outside normal range, especially at high humidity, may temporarily offset the RH signal. After returning into the normal temperature and humidity range the sensor will slowly come back to calibration state by itself.
The sensor have two working modes :
- Single shot measurement
- Periodic mode measurement
Both working modes returning 16 bit values for temperature and humidity and both modes can be adjusted with repeatability. This setting influences the measurement duration and thus the overall energy consumption. For single shot mode there is an option to setup clock stretching, and in case periodic measurement mode there is acquisition frequency setting which allow us to set how many measurement per second we want to perform.
Sensor also have heater functionality which can be useful to prevent the sensor overheating that can occurs on highest repeatability and acquisition frequency.
SHT click average current consumption is 2 μA ( operation with one measurement per second at lowest repeatability ) which means that it can be good solution for battery powered applications.
Library
The library for SHT click is quite easy to use. You can use library packed for our compilers from Libstock or use the source code if some changes are needed for your application.
The first thing is proper I2C bus and pin initialization. After that we can initialize the library with the I2C address which depends on ADDR jumper on the click board.
#include "SHT_hw.h" sbit SHT_RST_PIN at RC1_bit; sbit SHT_RST_PIN_DIR at TRISC1_bit; /* Prototypes ****************************/ void system_init( void ); /* Functions ****************************/ void system_init() { SHT_RST_PIN_DIR = 0; I2C2_Init( 100000 ); Delay_ms ( 200 ); } void main() { system_init(); sht_init( 0x44 ); while( 1 ) { } }
Now we can implement functions for temperature and humidity measurement which will be placed inside the infinite loop.
void display_temp() { temperature = sht_temp_ss(); Delay_ms( 200 ); } void display_hum() { humidity = sht_hum_ss(); Delay_ms( 200 ); }
The final step will be implementation the of the TFT functions which will initialize the TFT and display the measurements.
#include "SHT_hw.h" #include "resources.h" /* TFT pins *****************************/ char TFT_DataPort at LATE; sbit TFT_RST at LATD7_bit; sbit TFT_BLED at LATD2_bit; sbit TFT_RS at LATD9_bit; sbit TFT_CS at LATD10_bit; sbit TFT_RD at LATD5_bit; sbit TFT_WR at LATD4_bit; char TFT_DataPort_Direction at TRISE; sbit TFT_RST_Direction at TRISD7_bit; sbit TFT_BLED_Direction at TRISD2_bit; sbit TFT_RS_Direction at TRISD9_bit; sbit TFT_CS_Direction at TRISD10_bit; sbit TFT_RD_Direction at TRISD5_bit; sbit TFT_WR_Direction at TRISD4_bit; /* Variables ****************************/ sbit SHT_RST_PIN at RC1_bit; sbit SHT_RST_PIN_DIR at TRISC1_bit; float temperature, humidity; char tmp_txt[10]; /* Prototypes ****************************/ void system_init( void ); void display_init( void ); void display_temp( void ); void display_hum( void ); /* Functions ****************************/ void system_init() { SHT_RST_PIN_DIR = 0; I2C2_Init( 100000 ); Delay_ms ( 200 ); } void display_init() { TFT_Init_ILI9341_8bit( 320, 240 ); TFT_BLED = 1; TFT_Set_Pen( CL_WHITE, 1 ); TFT_Set_Brush( 1, CL_WHITE, 0, 0, 0, 0 ); TFT_Set_Font( TFT_defaultFont, CL_BLACK, FO_HORIZONTAL ); TFT_Fill_Screen( CL_WHITE ); TFT_Set_Pen( CL_BLACK, 1 ); TFT_Line( 20, 46, 300, 46 ); TFT_Line( 20, 70, 300, 70 ); TFT_Line( 20, 220, 300, 220 ); TFT_Set_Pen( CL_WHITE, 1 ); TFT_Set_Font( &HandelGothic_BT21x22_Regular, CL_RED, FO_HORIZONTAL ); TFT_Write_Text( "SHT click", 115, 14 ); TFT_Set_Font( &Tahoma15x16_Bold, CL_BLUE, FO_HORIZONTAL ); TFT_Write_Text( "SHT3x-DIS", 125, 50 ); TFT_Set_Font( &Verdana12x13_Regular, CL_BLACK, FO_HORIZONTAL ); TFT_Write_Text( "EasyMx PRO v7 for STM32", 19, 223 ); TFT_Set_Font( &Verdana12x13_Regular, CL_RED, FO_HORIZONTAL ); TFT_Write_Text( "www.mikroe.com", 200, 223 ); TFT_Set_Font( &Tahoma15x16_Bold, CL_BLACK, FO_HORIZONTAL ); TFT_Write_Text( "Temperature : ", 60, 100 ); TFT_Write_Text( "Humidity : ", 60, 135 ); TFT_Set_Font( &Tahoma15x16_Bold, CL_RED, FO_HORIZONTAL ); } void display_temp() { temperature = sht_temp_ss(); Delay_ms( 200 ); sprintf( tmp_txt, "%3.1f C", temperature ); TFT_Rectangle( 195, 95, 250, 120 ); TFT_Write_Text( tmp_txt, 200, 100 ); } void display_hum() { humidity = sht_hum_ss(); Delay_ms( 200 ); sprintf( tmp_txt, "%3.1f", humidity ); strcat( tmp_txt, " %" ); TFT_Rectangle( 195, 130, 250, 155 ); TFT_Write_Text( tmp_txt, 200, 135 ); } void main() { system_init(); display_init(); sht_init( 0x44 ); while( 1 ) { display_temp(); display_hum(); } }
Summary
As a very precise and durable sensor, SHT3x-DIS is the first choice from the point of view of lot embedded developers. 3X version is really improved to the earlier version with few additions which can help you to configure and adjust the measurement the way you want.
References
Sensirion manufacturer 2016
SHT3x-DIS datasheet 2016
Manual - SHT click
Library - Libstock 2016
Source Code - GitHub 2016