Intermediate
30 min

Experience a leap forward in IoT connectivity with SARA-R410M-02B and ATmega644

The future of IoT connectivity

LTE IoT Click with EasyAVR v7

Published Sep 13, 2023

Click board™

LTE IoT Click

Dev. board

EasyAVR v7

Compiler

NECTO Studio

MCU

ATmega644

Empower your IoT ventures with LTE IoT, where the seamless integration of CAT M1 and NB1 technologies unlocks a world of connectivity possibilities

A

A

Hardware Overview

How does it work?

LTE IoT Click is based on the SARA-R410M-02B, a configurable LTE Cat M1/NB1 multi-mode module with global support for IoT and M2M applications from u-Blox. This module consists of several internal blocks or sections, such as the RF and memory section, the power management section, and the cellular baseband processor with the peripheral interfaces. It supports UART and USB interfaces alongside an external SIM card/chip interface, ultra-low power consumption, and cost-optimized solutions, making it ideal for developing LPWA IoT applications. It also provides an Extended Discontinuous Reception (e-DRX), extending battery life to 10 years. Another benefit of SARA-R410M-02B is the hardware readiness for future support of voice functionality via VoLTE over Cat M1, which can be used for applications requiring a level of human interaction, as is the case for security applications such as alarm panels. The power supply of the SARA-R410M-02B module is regulated to 3.8V by the MCP1826, a 1A low-drop output (LDO) regulator from Microchip. The module's digital interface supply output pin provides a needed reference voltage for one side of the TXB0106, a 6-bit bidirectional level shifting and voltage translator from Texas Instruments. The main UART bus of the module is connected to one side of the TXB0106 level shifter, while the other is connected to the respective mikroBUS™ UART pins. The reference voltage for the other side of the level shifter is taken from the onboard SMD

jumper, labeled as PWR SEL, used to select between 3.3V and 5V from the mikroBUS™, depending on the used MCU type and its logic voltage level requirements. The SARA-R410M-02B module communicates with MCU using the UART interface with commonly used UART RX and TX pins, including the hardware flow control pins UART CTS, RTS, RI (Clear to Send, Ready to Send, and Ring Indicator). It supports automatic baud rate detection, operates at 115200 bps by default configuration, and is used for data transmission and exchanging AT communication commands with the host MCU. In addition to the default baud rates, the UART interface supports 9600, 19200, 38400, and 57600 baud rates. This interface can also act as a device and be connected to a USB host, such as the personal computer (PC), allowing the proprietary application from u-Blox called m-center to be used, offering a clean and comprehensive interface for accessing the main functionality of the module, setting up the configuration parameters, managing SMS messages, tracing the module activity, and more. LTE IoT Click possesses the SMA antenna connector with an impedance of 50Ω, and it can be used for connecting the appropriate antenna that MikroE offers, such as Rubber Antenna GSM/GPRS Right Angle. This antenna is an excellent choice for all GSM/GPRS applications and supports a range of frequencies and bands. It has a Micro SIM card holder on the back of the Click

board™ used to install a micro SIM card, which allows connection to the cellular network with both 1.8V and 3V SIM card types supported. The onboard active-low pushbutton labeled PWR routed to the AN pin on the mikroBUS™ represents the Ignition (Power-On) button, whose successful action will be indicated by the STAT LED. If the device is powered up, a LOW pulse with a duration of 1.5s on this pin will power the module down. It is also possible to power down the module by issuing the AT+CPWROFF command or with a Reset function routed to the RST pin on the mikroBUS™, which will cause an abrupt power down (forced power-down) by sending an active low input on this pin with the duration of 10s. This Click board™ has two LED indicators: the yellow LED labeled as STAT is used to visually indicate the device's Operational Status, and a red LED labeled as TX is used to indicate the Network Status. This Click Board™ is designed to operate with 3.3V and 5V logic voltage levels that can be selected via the PWR SEL jumper. Appropriate voltage level shifters perform a proper logic voltage level conversion, while the LDOs ensure that recommended values power the module. 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.

LTE IoT Click hardware overview image

Features overview

Development board

EasyAVR v7 is the seventh generation of AVR development boards specially designed for the needs of rapid development of embedded applications. It supports a wide range of 16-bit AVR microcontrollers from Microchip and has a broad set of unique functions, such as a powerful onboard mikroProg programmer and In-Circuit debugger over USB. The development board is well organized and designed so that the end-user has all the necessary elements in one place, such as switches, buttons, indicators, connectors, and others. With four different connectors for each port, EasyAVR v7 allows you to connect accessory boards, sensors, and custom electronics more

efficiently than ever. Each part of the EasyAVR v7 development board contains the components necessary for the most efficient operation of the same board. An integrated mikroProg, a fast USB 2.0 programmer with mikroICD hardware In-Circuit Debugger, offers many valuable programming/debugging options and seamless integration with the Mikroe software environment. Besides it also includes a clean and regulated power supply block for the development board. It can use a wide range of external power sources, including an external 12V power supply, 7-12V AC or 9-15V DC via DC connector/screw terminals, and a power source via the USB Type-B (USB-B)

connector. Communication options such as USB-UART and RS-232 are also included, alongside the well-established mikroBUS™ standard, three display options (7-segment, graphical, and character-based LCD), and several different DIP sockets which cover a wide range of 16-bit AVR MCUs. EasyAVR v7 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.

EasyAVR v7 horizontal image

Microcontroller Overview

MCU Card / MCU

ATmega644

Architecture

AVR

MCU Memory (KB)

64

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

4096

You complete me!

Accessories

LTE Flat Rotation Antenna is a versatile choice for boosting the performance of 3G/4G LTE devices. With a wide frequency range of 700-2700MHz, it ensures optimal connectivity on major cellular bands worldwide. This flat antenna features an SMA male connector, making it easy to attach directly to your device or SMA module connector. One of its standout features is its adjustable angle, which can be set in 45⁰ increments (0⁰/45⁰/90⁰), allowing you to fine-tune the antenna's orientation for maximum signal reception. With an impedance of 50Ω and a VSW Ratio of <2.0:1, this antenna ensures a reliable and efficient connection. Its 5dB gain, vertical polarization, and omnidirectional radiation pattern enhance signal strength, making it suitable for various applications. Measuring 196mm in length and 38mm in width, this antenna offers a compact yet effective solution for improving your connectivity. With a maximum input power of 50W, it can handle the demands of various devices.

LTE IoT Click accessories image

Used MCU Pins

mikroBUS™ mapper

Power ON
PA7
AN
HW Reset / Power OFF
PA6
RST
UART CTS
PA5
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
UART RI
PD4
PWM
UART RTS
PD2
INT
UART TX
PD1
TX
UART RX
PD0
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

LTE IoT Click Schematic schematic

Step by step

Project assembly

EasyAVR v7 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyAVR v7 as your development board.

EasyAVR v7 front image hardware assembly
GNSS2 Click front image hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
EasyAVR v7 Access DIP 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 DIP image step 7 hardware assembly
EasyPIC PRO v7a Display Selection Necto Step 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

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

This library contains API for LTE IoT Click driver.

Key functions:

  • lteiot_power_on - LTE IoT module power on

  • lteiot_send_cmd - Send command function

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * \file 
 * \brief LteIot Click example
 * 
 * # Description
 * This example reads and processes data from LTE IoT click.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes driver and wake-up module and sets default configuration for connecting device to network.
 * 
 * ## Application Task  
 * Waits for device to connect to network and then sends SMS to selected phone number.
 * 
 * ## Additional Function
 * - static void lteiot_clear_app_buf ( void )
 * - static void lteiot_error_check( err_t error_flag )
 * - static void lteiot_log_app_buf ( void )
 * - static void lteiot_check_connection( void )
 * - static err_t lteiot_rsp_check ( void )
 * - static err_t lteiot_process ( void )
 * 
 * @note 
 * In order for the example to work, 
 * user needs to set the phone number and sim apn to which he wants to send an SMS
 * Enter valid data for the following macros: SIM_APN and PHONE_NUMBER_TO_MESSAGE.
 * E.g. 
    SIM_APN "vipmobile"
    PHONE_NUMBER_TO_MESSAGE "999999999"
 * 
 * @author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "lteiot.h"

#define APP_OK                              0
#define APP_ERROR_DRIVER                    -1
#define APP_ERROR_OVERFLOW                  -2
#define APP_ERROR_TIMEOUT                   -3

#define RSP_OK                              "OK"
#define RSP_ERROR                           "ERROR"

#define SIM_APN                             ""  // Set valid SIM APN
#define PHONE_NUMBER_TO_MESSAGE             ""  // Set Phone number to message
#define MESSAGE_CONTENT                     "LTE IoT Click"   // Messege content 

#define PROCESS_BUFFER_SIZE                 500

#define WAIT_FOR_CONNECTION                 0
#define CONNECTED_TO_NETWORK                1

static lteiot_t lteiot;
static log_t logger;

static char app_buf[ PROCESS_BUFFER_SIZE ]  = { 0 };
static int32_t app_buf_len                  = 0;
static int32_t app_buf_cnt                  = 0;

static uint8_t app_connection_status        = WAIT_FOR_CONNECTION;

static err_t app_error_flag;

/**
 * @brief LTE IoT clearing application buffer.
 * @details This function clears memory of application buffer and reset its length and counter.
 * @note None.
 */
static void lteiot_clear_app_buf ( void );

/**
 * @brief LTE IoT data reading function.
 * @details This function reads data from device and concats data to application buffer.
 * 
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - Nothing is read.
 *         @li @c -2 - Application buffer overflow.
 *
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t lteiot_process ( void );

/**
 * @brief LTE IoT check for errors.
 * @details This function checks for different types of errors and logs them on UART.
 * @note None.
 */
static void lteiot_error_check( err_t error_flag );

/**
 * @brief LTE IoT logs application buffer.
 * @details This function logs data from application buffer.
 * @note None.
 */
static void lteiot_log_app_buf ( void );

/**
 * @brief LTE IoT response check.
 * @details This function checks for response and returns the status of response.
 * 
 * @return application status.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t lteiot_rsp_check ( void );

/**
 * @brief LTE IoT chek connection.
 * @details This function checks connection to the network and 
 *          logs that status to UART.
 * 
 * @note None.
 */
static void lteiot_check_connection( void );

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    lteiot_cfg_t lteiot_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 " );
    Delay_ms( 1000 );
    
    // Click initialization.
    lteiot_cfg_setup( &lteiot_cfg );
    LTEIOT_MAP_MIKROBUS( lteiot_cfg, MIKROBUS_1 );
    err_t init_flag  = lteiot_init( &lteiot, &lteiot_cfg );
    if ( init_flag == UART_ERROR )
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }
    
    log_info( &logger, " Power on device... " );
    lteiot_power_on( &lteiot );
    
    // dummy read
    lteiot_process( );
    lteiot_clear_app_buf( );
    
    // AT
    lteiot_send_cmd( &lteiot, LTEIOT_CMD_AT );
    app_error_flag = lteiot_rsp_check( );
    lteiot_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // ATI - product information
    lteiot_send_cmd( &lteiot, LTEIOT_CMD_ATI );
    app_error_flag = lteiot_rsp_check(  );
    lteiot_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // CGMR - firmware version
    lteiot_send_cmd( &lteiot, LTEIOT_CMD_CGMR );
    app_error_flag = lteiot_rsp_check(  );
    lteiot_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // COPS - deregister from network
    lteiot_send_cmd_with_parameter( &lteiot, LTEIOT_CMD_COPS, "2" );
    app_error_flag = lteiot_rsp_check(  );
    lteiot_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // CGDCONT - set sim apn
    lteiot_set_sim_apn( &lteiot, SIM_APN );
    app_error_flag = lteiot_rsp_check(  );
    lteiot_error_check( app_error_flag );
    Delay_ms( 500 );
     
    // CFUN - full funtionality
    lteiot_send_cmd_with_parameter( &lteiot, LTEIOT_CMD_CFUN, "1" );
    app_error_flag = lteiot_rsp_check(  );
    lteiot_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // COPS - automatic mode
    lteiot_send_cmd_with_parameter( &lteiot, LTEIOT_CMD_COPS, "0" );
    app_error_flag = lteiot_rsp_check(  );
    lteiot_error_check( app_error_flag );
    Delay_ms( 2000 );
    
    // CEREG - network registration status
    lteiot_send_cmd_with_parameter( &lteiot, LTEIOT_CMD_CEREG, "2" );
    app_error_flag = lteiot_rsp_check(  );
    lteiot_error_check( app_error_flag );
    Delay_ms( 500 );
    
    // CIMI - request IMSI
    lteiot_send_cmd( &lteiot, LTEIOT_CMD_CIMI );
    app_error_flag = lteiot_rsp_check(  );
    lteiot_error_check( app_error_flag );
    Delay_ms( 500 );
    
    app_buf_len = 0;
    app_buf_cnt = 0;
    app_connection_status = WAIT_FOR_CONNECTION;
    log_info( &logger, " Application Task " );
    Delay_ms( 5000 );
}

void application_task ( void )
{  
    if ( app_connection_status == WAIT_FOR_CONNECTION )
    {
        // CGATT - request IMSI
        lteiot_send_cmd_check( &lteiot, LTEIOT_CMD_CGATT );
        app_error_flag = lteiot_rsp_check(  );
        lteiot_error_check( app_error_flag );
        Delay_ms( 500 );
        
        // CEREG - network registration status
        lteiot_send_cmd_check( &lteiot, LTEIOT_CMD_CEREG );
        app_error_flag = lteiot_rsp_check(  );
        lteiot_error_check( app_error_flag );
        Delay_ms( 500 );
        
        // CSQ - signal quality
        lteiot_send_cmd( &lteiot, LTEIOT_CMD_CSQ );
        app_error_flag = lteiot_rsp_check(  );
        lteiot_error_check( app_error_flag );
        Delay_ms( 5000 );
    }
    else
    {
        log_info( &logger, "CONNECTED TO NETWORK" );
        
        // SMS message format - text mode
        lteiot_send_cmd_with_parameter( &lteiot, "AT+CMGF", "1" );
        app_error_flag = lteiot_rsp_check(  );
        lteiot_error_check( app_error_flag );
        Delay_ms( 3000 );
        
        for( ; ; )
        {   
            log_printf( &logger, "> Sending message to phone number...\r\n" );
            lteiot_send_text_message( &lteiot, PHONE_NUMBER_TO_MESSAGE, MESSAGE_CONTENT );
            app_error_flag = lteiot_rsp_check(  );
            lteiot_error_check( app_error_flag );
            Delay_ms( 10000 );
            Delay_ms( 10000 );
            Delay_ms( 10000 );
        }
    }
}

void main ( void )
{
    application_init( );

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

static void lteiot_clear_app_buf ( void )
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
    app_buf_cnt = 0;
}

static err_t lteiot_process ( void )
{
    err_t return_flag = APP_ERROR_DRIVER;
    int32_t rx_size;
    char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };
    
    rx_size = lteiot_generic_read( &lteiot, rx_buff, PROCESS_BUFFER_SIZE );

    if ( rx_size > 0 )
    { 
        int32_t buf_cnt = 0;
        return_flag = APP_OK;

        if ( app_buf_len + rx_size >= PROCESS_BUFFER_SIZE )
        {
            lteiot_clear_app_buf(  );
            return_flag = APP_ERROR_OVERFLOW;
        }
        else
        {
            buf_cnt = app_buf_len;
            app_buf_len += rx_size;
        }

        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ )
        {
            if ( rx_buff[ rx_cnt ] != 0 ) 
            {
                app_buf[ ( buf_cnt + rx_cnt ) ] = rx_buff[ rx_cnt ];
            }
            else
            {
                app_buf_len--;
                buf_cnt--;
            }
        }
    } 

    return return_flag;
}

static err_t lteiot_rsp_check ( void )
{
    uint16_t timeout_cnt = 0;
    uint16_t timeout = 10000;
    
    err_t error_flag = lteiot_process(  );
    
    if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
    {
        return error_flag;
    }
    
    while ( ( strstr( app_buf, RSP_OK ) == 0 ) && ( strstr( app_buf, RSP_ERROR ) == 0 ) )
    {
        error_flag = lteiot_process(  );
        if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
        {
            return error_flag;
        }
        
        timeout_cnt++;
        if ( timeout_cnt > timeout )
        {
            while ( ( strstr( app_buf, RSP_OK ) == 0 ) && ( strstr( app_buf, RSP_ERROR ) == 0 ) )
            {
                lteiot_send_cmd( &lteiot, LTEIOT_CMD_AT );
                lteiot_process(  );
                Delay_ms( 100 );
            }
            lteiot_clear_app_buf(  );
            return APP_ERROR_TIMEOUT;
        }
        
        Delay_ms( 1 );
    }
    
    lteiot_check_connection();
    
    lteiot_log_app_buf();
    
    log_printf( &logger, "-----------------------------------\r\n" );
    
    return APP_OK;
}

static void lteiot_error_check( err_t error_flag )
{
    if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
    {
        switch ( error_flag )
        {
            case -2:
                log_error( &logger, " Overflow!" );
                break;
            case -3:
                log_error( &logger, " Timeout!" );
                break;
            default:
                break;
        }
    }
}

static void lteiot_log_app_buf ( void )
{
    for ( int32_t buf_cnt = 0; buf_cnt < app_buf_len; buf_cnt++ )
    {
        log_printf( &logger, "%c", app_buf[ buf_cnt ] );
    }
    log_printf( &logger, "\r\n" );
    lteiot_clear_app_buf(  );
}

static void lteiot_check_connection( void )
{
    #define CONNECTED "+CGATT: 1"
    
    if ( strstr( app_buf, CONNECTED ) != 0 )
    {
        app_connection_status = CONNECTED_TO_NETWORK;
    }
}

// ------------------------------------------------------------------------ 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.