thermostat2 2.0.0.0
Main Page

Thermostat 2 click

‍Thermostat 2 click is a general-purpose thermostat Click board™ designed to be used with any temperature sensor based on the DS1820 sensor design: 3-pin package with 1-Wire® communication interface.

click Product page


Click library

  • Author : Aleksandra Cvjeticanin
  • Date : Mar 2022.
  • Type : One Wire type

Software Support

We provide a library for the Thermostat 2 Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

‍This library contains API for Thermostat 2 Click driver.

Standard key functions :

Example key functions :

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.

void application_init ( void )
{
log_cfg_t log_cfg;
thermostat2_cfg_t thermostat2_cfg;
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 " );
}
#define THERMOSTAT2_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition thermostat2.h:150
void application_init(void)
Definition main.c:33
@ THERMOSTAT2_ERROR
Definition thermostat2.h:192

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.

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 " );
relay_state = THERMOSTAT2_RELAY_ON;
}
}
else
{
if ( relay_state != THERMOSTAT2_RELAY_OFF )
{
log_info( &logger, " Relay is OFF.\r\n" );
relay_state = THERMOSTAT2_RELAY_OFF;
}
}
}
#define THERMOSTAT2_RELAY_ON
Thermostat 2 temperature values and relay states.
Definition thermostat2.h:130
#define THERMOSTAT2_TEMPERATURE_LIMIT
Definition thermostat2.h:132
#define THERMOSTAT2_RELAY_OFF
Definition thermostat2.h:131
void application_task(void)
Definition main.c:69
@ THERMOSTAT2_OK
Definition thermostat2.h:191

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.Thermostat2

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.