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