Skip to content

Your Click boards™ application

In this section you will learn:

  • Creating a mikroSDK application project
  • Downloading and installing package for a specific Click board™
  • Usage of mikroBUS API
  • Making an application with mikroSDK and Click driver work on selected hardware

After you successfully installed mikroSDK package following these steps, you can start developing a portable mikroSDK application.

Creating mikroSDK application project

To see how to create a new mikroSDK application project, refer to the Your first application section.

Downloading and installing package for a specific Click board™

Prior to using the functions provided by a Click board driver, you have to install its package. This is done through the built-in Library Manager in NECTO Studio. Please refer to this link to see how to use the Library Manager.

Creating a Click board application with mikroSDK

In this guide we will use Relay Click to help us showcase the usage.

In order to use the functions provided by the Relay Click driver, you have to select its library and include its header file.

Right click on your project in the Project Manager and select Manage Project Libraries. Expand the Click section and tick the checkbox next to Relay.

Next step is to include the driver header:

#include "relay.h"

Create a relay driver instance by writing:

static relay_t relay;

In the application_init() we will perform the initialization of the Relay Click board:

void application_init ()
    relay_cfg_t cfg;

    relay_init(&relay, &cfg);



Take a look at the official example in order to see how to properly initialize a Click board. From the NECTO Studio's Welcome page, click on the Examples button, search for your Click board and click on it to open the example project. Expand the project tree and double click the main.c file in which the initialization code is located.

Main application logic is placed inside the application_task() function. Relay Click board has two relays on it, by writing the following code we will toggle both relays each second:

void application_task ()
    relay_set_state( &relay, RELAY_NUM_1, RELAY_STATE_ON );
    relay_set_state( &relay, RELAY_NUM_2, RELAY_STATE_ON );
    relay_set_state( &relay, RELAY_NUM_1, RELAY_STATE_OFF );
    relay_set_state( &relay, RELAY_NUM_2, RELAY_STATE_OFF );

Usage of mikroBUS API

As seen in the above example, RELAY_MAP_MIKROBUS() function uses macros from the mikrobus.h header file (located in board.h) to map the Click board's pins to mikroBUS pins. Users too can use these macros in their code to map the pins themselves (see this), however there is a faster way:
You can also use macro pin name MIKROBUS_1_CS to identify the CS pin on mikroBUS1 slot, MIKROBUS_2_AN to identify the AN pin on mikroBUS2 slot, etc... without needing to know the exact pin name on the target MCU.
These macros are defined in the board.h header file. This header comes with mikroSDK package and it defines your development board. It helps by mapping board pins to the target MCU.