Saturday, June 16, 2018

Interfacing to SHT30 Humidity & Temperature Sensor with PIC24F

In the previous post, I’ve designed a board with PIC24F, now I’m going to use it to make some project. The project will be interfacing PIC24F to SHT30 temperature & humidity sensor. SHT30 is manufactured by Sensirion Company which is the world’s leading manufacturer of digital relative humidity sensor. This sensor is said to be excellent, the best in class product, it has been used in many commercial industry product, and the company too has been pioneering digital humidity sensor over the past 15 years.

There’s a module/mini board with SHT30 already assembled on it available in the market, we just need to solder some jumper header on it then put it on a protoboard.
Communication with SHT30 sensor is performed through I2C interface. Basically PIC24F send measurement command to SHT30, then wait while measurement ongoing. After the measurement is complete, PIC24F will read the result from SHT30. PIC24F will check if the CRC is correct, if so then calculate the actual temperature and humidity, then send it through USB CDC to a PC running terminal program for displaying.

The connection diagram below show what’re we gonna do:
Measurement result from SHT30 is consist of 6 bytes, in sequence: 2 bytes of temperature data, 1 byte temperature CRC-checksum, 2 byte of relative humidity data, 1 byte humidity CRC-checksum. Table 8 from SHT3x datasheet show these along with how I2C communication performed:
The CRC used by SHT30 is CRC-8 Dallas/Maxim (DOW-CRC) with polynom 0x31 ( x^8 + x^5 + x^4 + 1 ) and initial CRC value 0xff. The CRC checksum is calculated for each 16-bit temperature and humidity data. PIC24F should check if the checksum is correct after retrieving measurement result, before sending it to USB CDC.

USB CDC library used in this project is based on CDC basic example found in MLA (Microchip Library for Application). I just modified what function “APP_DeviceCDCBasicDemoTasks” do in “app_device_cdc_basic.c”. Then added my own I2C and SHT30 library to the project.


To calculate the actual relative humidity and temperature from the measurement result, the formula below is used: (where SRH and ST is the 16 bit measurement value of relative humidity and temperature read from the sensor)
Terminal in PC will show the 6 bytes measurement result and the calculated temperature (Celcius) and relative humidity (%), for example: 71 22 AA A5 DC 70, T = 32.3 oC RH = 64.8%.

PIC24F is controlling SHT30 to do measurement every 1 second. Below is the terminal output:


No comments:

Post a Comment