Introduction

Smablo Relay Shield is equipped with two relays that you can utilize to turn something on or off. It has two outside connectors to connect to the outside devices. Smablo Relay Shield can work with switching current 2/5A, switching power 60W/62.5VA and switching voltage 220VDC/250VAC and low coil power consumption 140mW which make it very power efficient.

Applications

Smablo Relay Shield can be used for situation when you need to turn smoothing on or off. It can be use for example for :

  • HVAC devices
  • Controlling electromagnetic locks
  • Controlling electric motors

Getting started

To get started with Smablo Relay Shield you will need :

Take Smablo development board from your smablo development kit and place CPU and Smablo Relay Shield on the described connectors like in the pictures and video below:

[plugin:youtube]()

{.force-inline} {.force-inline} {.force-inline}

When you’ve done connecting Shields you can connect Smablo Development board to your computer with USB cable.

Example programs

To show you how to interact with Smablo Relay Shield open Visual Studio Code and open relay example just like it was shown in the video below:

[plugin:youtube]()

To run the demo relay project press F5 button to compile and flash the code and then press run button just like it was shown in video below:

[plugin:youtube]()

As the result of this example you can hear that every 2 second there is switch state change.

Minimal code

#include "app_relay.h"

void example_code(void)
{
    //initialize relay board
    app_relay_init();

    //set relay to needed state
    app_relay_configure_state(APP_RELAY_ID_1, APP_RELAY_STATE_OPEN);

    //send the configuration to the shield 
    app_relay_commit_blocking();
}

Minimal code snippet shown above minimal code snippet is illustrating how you should program with Smablo app_relay library.

Firstly we need to include the library with #include "app_relay.h" and then we can use all of the library functions.

Then we need to initialize the shield with app_relay_init(); function.

Now we can start configuration the function, in app_relay_configure_state function we are setting the first relay to open state. To make actual changes to the shield we need to send those configurations to the shield and we can do that with app_relay_commit_blocking();function.

How do I?

Change the relay state to open

#include "app_relay.h"

void example_code(void)
{
    //initialize relay board
    app_relay_init();

    //set relay to needed state
    app_relay_configure_state(APP_RELAY_ID_1, APP_RELAY_STATE_OPEN);

    //send the configuration to the shield 
    app_relay_commit_blocking();
}

The code above sets the state of the relay number one to open. We can configure the relay state with app_relay_configure_state() function. First parameter of the function determines the ID of the relay the state we want to change and the second one determines the state we want to configure.

Change relay state to close

void example_code(void)
{
    //initialize relay board
    app_relay_init();

    //set relay to needed state
    app_relay_configure_state(APP_RELAY_ID_1, APP_RELAY_STATE_CLOSE);

    //send the configuration to the shield 
    app_relay_commit_blocking();
}

The code above sets the state of the relay number one to close. First parameter of the function determines the ID of the relay the state we want to change and the second one determines the state we want to configure.

app_relay library reference

To make your work with Smablo products easier and faster we prepared app_relay library for use with Relay Shield. All of available functions and their descriptions can be found in app_relay.h

app_relay_init

Prototype:

void app_relay_init(void)

Function is used for initialize the shield. Use it once at the beginning of our program like in code snippet above.

app_relay_configure_state

Prototype:

void app_relay_configure_state(app_relay_id_t relay_id, app_relay_state_t relay_state)

Function is used for configuring the state of the relays. Function takes 2 parameters:

  • relay_id type app_relay_id_t parameter that determines ID of the relay you want to configure. You can choose the relay one APP_RELAY_ID_1 with and second relay with APP_RELAY_ID_2.
  • relay_state type app_relay_state_t parameter that determines the state of the relay. You can configure the relay to open APP_RELAY_STATE_OPEN with and close with APP_RELAY_STATE_CLOSED.

app_relay_commit_blocking

Prototype:

void app_relay_commit_blocking(void);

Function is used for sending all of the configurations made to shield. Only after executing this function you will see the change of behaviour of the Relay Shield.

app_relay_state_t app_relay_get_state

Prototype:

app_relay_state_t app_relay_get_state(app_relay_id_t relay_id);

Function is used for getting the relay state of the shield. Function takes one parameter the relay_id type app_relay_id_t parameter that determines ID of the relay the state you want to check. Function return the state of the relay.