Intermediate
30 min

Ensure healthy air quality by monitoring humidity and temperature with HDC3021 and PIC18F86K90

Your solution for accurate environmental data

Temp&Hum 24 Click with UNI-DS v8

Published Aug 25, 2023

Click board™

Temp&Hum 24 Click

Dev Board

UNI-DS v8

Compiler

NECTO Studio

MCU

PIC18F86K90

By seamlessly integrating temperature and humidity measurement, this solution enables real-time insights for efficient climate control and environmental management

A

A

Hardware Overview

How does it work?

Temp&Hum 24 Click is based on the HDC3021, an integrated interface digital sensor that incorporates both humidity and temperature sensing elements, an analog-to-digital converter, calibration memory, and an I2C compatible interface from Texas Instruments in one package. The sensor performs best when operated within the recommended average temperature and humidity range of 0-50°C and 10-50%RH, with each measurement in a 16-bit format. The HDC3021 also provides excellent measurement accuracy at low power (±0.5%RH and ±0.1°C over a wide operating temperature range). The HDC3021 measures relative humidity through variations in the capacitance of a polymer dielectric. This sensor has a polyimide tape to cover the opening of the humidity sensor element, which protects it from pollutants that can be produced as part of the manufacturing process. The tape must be removed after the final stages of assembly to measure the relative humidity in the ambient environment accurately. To remove the polyimide tape from the humidity sensor element, TI recommends using an ESD-safe tweezer to

grip the adhesive-free tab in the top right corner and slowly peel the adhesive from the top-right corner towards the bottom-left corner in an upward direction. This will help to reduce the risk of scratching the humidity sensor element. Due to contaminants, the natural aging of the sensor's polymer dielectric, and exposure to extreme operating conditions resulting in long-term drift, the HDC3021 accuracy can incur an offset. Thanks to the Offset Error Correction, the RH sensor offset reduces due to aging, exposure to extreme operating conditions, and contaminants to return the sensor to within accuracy specifications. This Click board™ communicates with an MCU using the standard I2C 2-Wire interface to read data and configure settings, supporting Fast Mode Plus up to 1MHz. The HDC3021 also has two measurement modes: Trigger-on-demand and Auto Measurement. Trigger-on Demand is a single temperature and relative humidity measurement reading triggered through an I2C command as needed. After the measurement is converted, the sensor remains in Sleep mode until another I2C command is

received. Auto Measurement mode is a recurring temperature and relative humidity measurement reading, eliminating the need to initiate a measurement request through an I2C command repeatedly. The HDC3021 wakes from Sleep to measurement mode in this mode based on the selected sampling rate. Besides, the HDC3021 allows choosing the least significant bit (LSB) of its I2C slave address using the SMD jumpers labeled ADDR SEL. It also possesses an additional interrupt alert signal, routed on the ALR pin of the mikroBUS™ socket, to provide a notification of ambient temperature and relative humidity measurements that violate programmed thresholds and general reset function routed on the RST pin of the mikroBUS™ socket. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. Also, this Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used for further development.

Temp&Hum 24 Click hardware overview image

Features overview

Development board

UNI-DS v8 is a development board specially designed for the needs of rapid development of embedded applications. It supports a wide range of microcontrollers, such as different STM32, Kinetis, TIVA, CEC, MSP, PIC, dsPIC, PIC32, and AVR MCUs regardless of their number of pins, and a broad set of unique functions, such as the first-ever embedded debugger/programmer over WiFi. The development board is well organized and designed so that the end-user has all the necessary elements, such as switches, buttons, indicators, connectors, and others, in one place. Thanks to innovative manufacturing technology, UNI-DS v8 provides a fluid and immersive working experience, allowing access anywhere and under any

circumstances at any time. Each part of the UNI-DS v8 development board contains the components necessary for the most efficient operation of the same board. An advanced integrated CODEGRIP programmer/debugger module offers many valuable programming/debugging options, including support for JTAG, SWD, and SWO Trace (Single Wire Output)), and seamless integration with the Mikroe software environment. Besides, it also includes a clean and regulated power supply module for the development board. It can use a wide range of external power sources, including a battery, an external 12V power supply, and a power source via the USB Type-C (USB-C) connector. Communication options such as USB-UART, USB

HOST/DEVICE, CAN (on the MCU card, if supported), and Ethernet is also included. In addition, it also has the well-established mikroBUS™ standard, a standardized socket for the MCU card (SiBRAIN standard), and two display options for the TFT board line of products and character-based LCD. UNI-DS v8 is an integral part of the Mikroe ecosystem for rapid development. Natively supported by Mikroe software tools, it covers many aspects of prototyping and development thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

UNI-DS v8 horizontal image

Microcontroller Overview

MCU Card / MCU

default

Type

8th Generation

Architecture

PIC

MCU Memory (KB)

64

Silicon Vendor

Microchip

Pin count

80

RAM (Bytes)

3828

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PJ4
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Alert Interrupt
PB0
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PC3
SCL
I2C Data
PC4
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

Temp&Hum 24 Click Schematic schematic

Step by step

Project assembly

Fusion for PIC v8 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the UNI-DS v8 as your development board.

Fusion for PIC v8 front image hardware assembly
Buck 22 Click front image hardware assembly
SiBRAIN for PIC32MZ1024EFK144 front image hardware assembly
v8 SiBRAIN MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
NECTO Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto image step 7 hardware assembly
Necto image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

Track your results in real time

Application Output

After pressing the "FLASH" button on the left-side panel, it is necessary to open the UART terminal to display the achieved results. By clicking on the Tools icon in the right-hand panel, multiple different functions are displayed, among which is the UART Terminal. Click on the offered "UART Terminal" icon.

UART Application Output Step 1

Once the UART terminal is opened, the window takes on a new form. At the top of the tab are two buttons, one for adjusting the parameters of the UART terminal and the other for connecting the UART terminal. The tab's lower part is reserved for displaying the achieved results. Before connecting, the terminal has a Disconnected status, indicating that the terminal is not yet active. Before connecting, it is necessary to check the set parameters of the UART terminal. Click on the "OPTIONS" button.

UART Application Output Step 2

In the newly opened UART Terminal Options field, we check if the terminal settings are correct, such as the set port and the Baud rate of UART communication. If the data is not displayed properly, it is possible that the Baud rate value is not set correctly and needs to be adjusted to 115200. If all the parameters are set correctly, click on "CONFIGURE".

UART Application Output Step 3

The next step is to click on the "CONNECT" button, after which the terminal status changes from Disconnected to Connected in green, and the data is displayed in the Received data field.

UART Application Output Step 4

Software Support

Library Description

This library contains API for Temp&Hum 24 Click driver.

Key functions:

  • temphum24_read_temp_and_rh - This function reads the temperature in celsius and the relative humidity level in percents

  • temphum24_read_temp_history - This function reads the temperature minimum and maximum values since the beginning of the measurements

  • temphum24_read_rh_history - This function reads the relative humidity minimum and maximum values since the beginning of measurements

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief TempHum 24 Click example
 *
 * # Description
 * This example demonstrates the use of Temp & Hum 24 click board by reading
 * the temperature and humidity data.
 * 
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration which
 * resets the device and starts the auto measurement mode with data rate of 1 Hz.
 *
 * ## Application Task
 * Reads the temperature (degrees C) and the relative humidity (%RH) data and 
 * displays the results on the USB UART approximately once per second. It also
 * reads and displays the minimum and maximum values measured since the beginning
 * of measurements.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "temphum24.h"

static temphum24_t temphum24;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    temphum24_cfg_t temphum24_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    temphum24_cfg_setup( &temphum24_cfg );
    TEMPHUM24_MAP_MIKROBUS( temphum24_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == temphum24_init( &temphum24, &temphum24_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( TEMPHUM24_ERROR == temphum24_default_cfg ( &temphum24 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    float temp = 0, hum = 0;
    if ( TEMPHUM24_OK == temphum24_read_temp_and_rh ( &temphum24, &temp, &hum ) )
    {
        float min_temp = 0, max_temp = 0;
        float min_rh = 0, max_rh = 0;
        log_printf ( &logger, " Temperature: %.2f C\r\n", temp );
        if ( TEMPHUM24_OK == temphum24_read_temp_history ( &temphum24, &min_temp, &max_temp ) )
        {
            log_printf ( &logger, " MIN: %.2f C\r\n MAX: %.2f C\r\n", min_temp, max_temp );
        }
        log_printf ( &logger, "\r\n Humidity: %.1f %%RH\r\n", hum );
        if ( TEMPHUM24_OK == temphum24_read_rh_history ( &temphum24, &min_rh, &max_rh ) )
        {
            log_printf ( &logger, " MIN: %.1f %%RH\r\n MAX: %.1f %%RH\r\n", min_rh, max_rh );
        }
        log_printf ( &logger, "----------------------\r\n" );
        Delay_ms ( 1000 );
    }
}

void main ( void ) 
{
    application_init( );

    for ( ; ; ) 
    {
        application_task( );
    }
}

// ------------------------------------------------------------------------ END

Additional Support

Resources