Beginner
10 min

Maintain the ideal conditions for research and experimentation with G6D-1A-ASI and PIC18F57Q43

Your trusted thermometer for every environment

Thermostat 2 Click with Curiosity Nano with PIC18F57Q43

Published Feb 13, 2024

Click board™

Thermostat 2 Click

Dev Board

Curiosity Nano with PIC18F57Q43

Compiler

NECTO Studio

MCU

PIC18F57Q43

Stay ahead of potential health risks with our temperature measurement technology, designed to provide early warnings of temperature fluctuations in critical environments.

A

A

Hardware Overview

How does it work?

Thermostat 2 Click is designed without the main IC; it allows an externally connected thermal sensor to be used, instead. It can be interfaced with the DS1820 compatible sensor which uses 1-Wire® communication. The Click board™ is equipped with a 3-pin female socket, which can be used to install the DS1820 compatible sensor in TO-92 casing, onboard. There is also a 3-pole screw terminal, that can be used if the sensor needs to be installed on a remote location, i.e. onto a heating component. The screw-terminal shares its lines with the socket. The 1-Wire® communication with the host MCU is performed over the PWM pin of the mikroBUS™. Depending on the temperature information obtained over the 1-Wire® interface, the host MCU can take the necessary action: it can either open or close contacts of the relay. The Click board™ uses the G6D series PCB power relay, from Omron. This quality relay can withstand an amazingly large number of mechanical cycles, with no load connected. However, when there is a significant load connected at its output, micro-electric arcs cause the contacts to wear over time. With the maximum load current of 5A, it can sustain up to 70,000

cycles. Its contacts are made of silver alloy, yielding exceptional ON resistance of only 100mΩ (max). The relay is activated by a magnetic field, generated in a built-in coil on the low-voltage side. The coil is activated by the host MCU. The voltage for the coil activation is 5V, while the current through the coil is 40mA. The MCU is not able to drive the coil directly, therefore an NPN transistor had to be added. Its base is controlled by the host MCU, allowing the coil to drain enough current from the 5V mikroBUS™ power rail. The base of the transistor is routed to the CS pin of the Click board™. The transistor packs two biasing resistors in the same casing, so it can be directly used on the MCU pin, without external biasing resistors. A red color LED, labeled as ACTIVE is used to indicate that the transistor is in an open state and that the current is running through the relay coil. When the current through a coil (or any other inductor) is suddenly changed, the backEMF will be generated, opposing the changes of the current. This can sometimes lead to damage to the control circuit: in this case, the transistor will become inversely polarized. To prevent this from happening, a flyback diode is added

across the coil. During the normal operation, this diode does not conduct any current. However, when the coil is switched OFF, the inverse polarization will cause the current to pass through this diode with minimum resistance. This prevents inverse (flyback) voltage from building up, so the transistor remains safe. Contacts at the output may be connected to a higher voltage and larger current may run through. To prevent high voltage transients in this case, a flyback diode is not a viable option. Therefore, Thermostat 2 click uses a varistor (VDR). This component rapidly drops its resistance as the voltage rises above its rated clamping voltage. The excessive voltage transient will pass through the VDR since it will become a current path with the least resistance. During the normal operation, while the voltage stays below the rated clamping voltage, VDR has a very high resistance, so the current runs through the electrical circuit, instead. The operating voltage of the Click board™ can be selected by the VCC SEL jumper. This jumper allows selecting either 3.3V or 5V from the mikroBUS™. The selected voltage will be applied to the VCC pin of the connected DS1820 sensor.

Thermostat 2 Click hardware overview image

Features overview

Development board

PIC18F57Q43 Curiosity Nano evaluation kit is a cutting-edge hardware platform designed to evaluate microcontrollers within the PIC18-Q43 family. Central to its design is the inclusion of the powerful PIC18F57Q43 microcontroller (MCU), offering advanced functionalities and robust performance. Key features of this evaluation kit include a yellow user LED and a responsive

mechanical user switch, providing seamless interaction and testing. The provision for a 32.768kHz crystal footprint ensures precision timing capabilities. With an onboard debugger boasting a green power and status LED, programming and debugging become intuitive and efficient. Further enhancing its utility is the Virtual serial port (CDC) and a debug GPIO channel (DGI

GPIO), offering extensive connectivity options. Powered via USB, this kit boasts an adjustable target voltage feature facilitated by the MIC5353 LDO regulator, ensuring stable operation with an output voltage ranging from 1.8V to 5.1V, with a maximum output current of 500mA, subject to ambient temperature and voltage constraints.

PIC18F57Q43 Curiosity Nano double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC

MCU Memory (KB)

128

Silicon Vendor

Microchip

Pin count

48

RAM (Bytes)

8196

You complete me!

Accessories

Curiosity Nano Base for Click boards is a versatile hardware extension platform created to streamline the integration between Curiosity Nano kits and extension boards, tailored explicitly for the mikroBUS™-standardized Click boards and Xplained Pro extension boards. This innovative base board (shield) offers seamless connectivity and expansion possibilities, simplifying experimentation and development. Key features include USB power compatibility from the Curiosity Nano kit, alongside an alternative external power input option for enhanced flexibility. The onboard Li-Ion/LiPo charger and management circuit ensure smooth operation for battery-powered applications, simplifying usage and management. Moreover, the base incorporates a fixed 3.3V PSU dedicated to target and mikroBUS™ power rails, alongside a fixed 5.0V boost converter catering to 5V power rails of mikroBUS™ sockets, providing stable power delivery for various connected devices.

Curiosity Nano Base for Click boards accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
Relay Control
PD4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
1-Wire Data
PB0
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

Thermostat 2 Click Schematic schematic

Step by step

Project assembly

Curiosity Nano Base for Click boards front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity Nano with PIC18F57Q43 as your development board.

Curiosity Nano Base for Click boards front image hardware assembly
Charger 27 Click front image hardware assembly
PIC18F47Q10 Curiosity Nano front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Curiosity Nano with PICXXX Access 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 image step 5 hardware assembly
Necto image step 6 hardware assembly
PIC18F57Q43 Curiosity MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output via Debug Mode

1. Once the code example is loaded, pressing the "DEBUG" button initiates the build process, programs it on the created setup, and enters Debug mode.

2. After the programming is completed, a header with buttons for various actions within the IDE becomes visible. Clicking the green "PLAY" button starts reading the results achieved with the Click board™. The achieved results are displayed in the Application Output tab.

DEBUG_Application_Output

Software Support

Library Description

This library contains API for Thermostat 2 Click driver.

Key functions:

  • thermostat2_read_temperature - This function reads the temperature value in Celsius.

  • thermostat2_relay_state - This function turns the relay on/off.

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 Thermostat 2 Click Example.
 *
 * # Description
 * This example demonstrates the use of Thermostat 2 click board by reading
 * and displaying the temperature in Celsius and turning the relay on/off 
 * depending on the temperature value.
 * DS1820, DS18S20 and DS18B20 chips can be used in this example. 
 * 
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration.
 *
 * ## Application Task
 * Reads and displays the temperature measured by the click board on the UART Terminal.
 * If the temperature goes beneath the THERMOSTAT2_TEMPERATURE_LIMIT, 
 * the relay will be turned off while otherwise it will be turned on. 
 * In both cases an appropriate message will be displayed on the terminal. 
 *
 * @author Aleksandra Cvjetićanin 
 *
 */

#include "board.h"
#include "log.h"
#include "thermostat2.h"

static thermostat2_t thermostat2;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    thermostat2_cfg_t thermostat2_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.
    thermostat2_cfg_setup( &thermostat2_cfg );
    THERMOSTAT2_MAP_MIKROBUS( thermostat2_cfg, MIKROBUS_1 );
    if ( ONE_WIRE_ERROR == thermostat2_init( &thermostat2, &thermostat2_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( THERMOSTAT2_ERROR == thermostat2_default_cfg ( &thermostat2 ) )
    {
        log_error( &logger, " Default config." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    static uint8_t relay_state = 0xFF;
    float temperature;
    
    if ( THERMOSTAT2_OK == thermostat2_read_temperature ( &thermostat2, &temperature ) )
    {
        log_printf( &logger, " Temperature: %.2f C\r\n\n ", temperature );
    }
    
    if ( temperature < THERMOSTAT2_TEMPERATURE_LIMIT )
    {
        if ( relay_state != THERMOSTAT2_RELAY_ON )
        {
            log_info( &logger, " Relay is ON.\r\n " );
            thermostat2_relay_state ( &thermostat2, THERMOSTAT2_RELAY_ON );
            relay_state = THERMOSTAT2_RELAY_ON;
        }
    }
    else 
    {
        if ( relay_state != THERMOSTAT2_RELAY_OFF )
        {
            log_info( &logger, " Relay is OFF.\r\n" );
            thermostat2_relay_state ( &thermostat2, THERMOSTAT2_RELAY_OFF );
            relay_state = THERMOSTAT2_RELAY_OFF;
        }
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

// ------------------------------------------------------------------------ END
/*!
 * @file main.c
 * @brief Thermostat 2 Click Example.
 *
 * # Description
 * This example demonstrates the use of Thermostat 2 click board by reading
 * and displaying the temperature in Celsius and turning the relay on/off 
 * depending on the temperature value.
 * DS1820, DS18S20 and DS18B20 chips can be used in this example. 
 * 
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration.
 *
 * ## Application Task
 * Reads and displays the temperature measured by the click board on the UART Terminal.
 * If the temperature goes beneath the THERMOSTAT2_TEMPERATURE_LIMIT, 
 * the relay will be turned off while otherwise it will be turned on. 
 * In both cases an appropriate message will be displayed on the terminal. 
 *
 * @author Aleksandra Cvjetićanin 
 *
 */

#include "board.h"
#include "log.h"
#include "thermostat2.h"

static thermostat2_t thermostat2;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    thermostat2_cfg_t thermostat2_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.
    thermostat2_cfg_setup( &thermostat2_cfg );
    THERMOSTAT2_MAP_MIKROBUS( thermostat2_cfg, MIKROBUS_1 );
    if ( ONE_WIRE_ERROR == thermostat2_init( &thermostat2, &thermostat2_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( THERMOSTAT2_ERROR == thermostat2_default_cfg ( &thermostat2 ) )
    {
        log_error( &logger, " Default config." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    static uint8_t relay_state = 0xFF;
    float temperature;
    
    if ( THERMOSTAT2_OK == thermostat2_read_temperature ( &thermostat2, &temperature ) )
    {
        log_printf( &logger, " Temperature: %.2f C\r\n\n ", temperature );
    }
    
    if ( temperature < THERMOSTAT2_TEMPERATURE_LIMIT )
    {
        if ( relay_state != THERMOSTAT2_RELAY_ON )
        {
            log_info( &logger, " Relay is ON.\r\n " );
            thermostat2_relay_state ( &thermostat2, THERMOSTAT2_RELAY_ON );
            relay_state = THERMOSTAT2_RELAY_ON;
        }
    }
    else 
    {
        if ( relay_state != THERMOSTAT2_RELAY_OFF )
        {
            log_info( &logger, " Relay is OFF.\r\n" );
            thermostat2_relay_state ( &thermostat2, THERMOSTAT2_RELAY_OFF );
            relay_state = THERMOSTAT2_RELAY_OFF;
        }
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

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

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.