Intermediate
20 min

Reimagine the way you connect to the world using DA16200MOD-AA and ATmega328P

Connect anywhere, anytime with ultra-low-power Wi-Fi innovation!

LP WiFi Click with Arduino UNO Rev3

Published Feb 14, 2024

Click board™

LP WiFi Click

Dev. board

Arduino UNO Rev3

Compiler

NECTO Studio

MCU

ATmega328P

Experience a new era of seamless connectivity as we introduce our innovative ultra-low-power Wi-Fi solution, redefining the way you stay connected on the go.

A

A

Hardware Overview

How does it work?

LP WiFi Click is based on the DA16200MOD-AA, a highly integrated ultra-low power WiFi module with the best RF performance and a comfortable development environment from Renesas. It consists of the DA16200 SoC, 4MB flash memory, RF components, crystal oscillator, RF lumped filter, and an onboard 2.4GHz chip antenna. Such low-power operation can extend the battery life for a year or more, depending on the application, even when the board is continuously connected to the WiFi network. This module also features strong IoT security, including WPA3 and TLS for authentication and encryption at WiFi and higher stack layers. The DA16200MOD has an integrated RTC block (36-bit real-time counter) with a 32.768kHz clock source necessary for the free-running counter in the RTC block of the SoC, which provides power management and function control for low-power operation. The RTC block

is always powered ON when an onboard switch labeled POWER is set to the appropriate ON position during normal operation. This optimizes power consumption and is used for power ON/OFF purposes. Also, the upper left header of the board, labeled as RTC Block Pads, is connected to the internal RTC block to connect and receive external event signals from an external device like a sensor. LP WiFi Click communicates with MCU using the UART interface as its default communication protocol. Users can use other interfaces, such as SPI and I2C, to improve and communicate with peripherals. It should be noted that the DA16200 module comes with firmware that only supports UART communication with the host microcontroller and I2C with peripherals such as sensors (SPI interface is not supported by default and can be enabled by firmware update). Additional options that this board has are certain

buttons and headers. The onboard pushbuttons are labeled RESET, and WPS represents a Factory reset button and WiFi Protected Setup (WPS) button. As for the headers, the first one marked with TX and RX signals is suitable for debugging purposes using the UART interface, while the second lets you add a small but bright and crisp OLED display to your design by connecting it to the upper-right header with I2C signals suitable for controlling the OLED. This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, it comes equipped with a library containing functions and an example code that can be used as a reference for further development.

LP WiFi Click hardware overview image

Features overview

Development board

Arduino UNO is a versatile microcontroller board built around the ATmega328P chip. It offers extensive connectivity options for various projects, featuring 14 digital input/output pins, six of which are PWM-capable, along with six analog inputs. Its core components include a 16MHz ceramic resonator, a USB connection, a power jack, an

ICSP header, and a reset button, providing everything necessary to power and program the board. The Uno is ready to go, whether connected to a computer via USB or powered by an AC-to-DC adapter or battery. As the first USB Arduino board, it serves as the benchmark for the Arduino platform, with "Uno" symbolizing its status as the

first in a series. This name choice, meaning "one" in Italian, commemorates the launch of Arduino Software (IDE) 1.0. Initially introduced alongside version 1.0 of the Arduino Software (IDE), the Uno has since become the foundational model for subsequent Arduino releases, embodying the platform's evolution.

Arduino UNO Rev3 double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

AVR

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

28

RAM (Bytes)

2048

You complete me!

Accessories

Click Shield for Arduino UNO has two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the Arduino UNO board without effort. The Arduino Uno, a microcontroller board based on the ATmega328P, provides an affordable and flexible way for users to try out new concepts and build prototypes with the ATmega328P microcontroller from various combinations of performance, power consumption, and features. The Arduino Uno has 14 digital input/output pins (of which six can be used as PWM outputs), six analog inputs, a 16 MHz ceramic resonator (CSTCE16M0V53-R0), a USB connection, a power jack, an ICSP header, and reset button. Most of the ATmega328P microcontroller pins are brought to the IO pins on the left and right edge of the board, which are then connected to two existing mikroBUS™ sockets. This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the Arduino UNO board with our Click Shield for Arduino UNO, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Arduino UNO accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Wake-Up
PD2
RST
SPI Chip Select
PB2
CS
SPI Clock
PB5
SCK
SPI Data OUT
PB4
MISO
SPI Data IN
PB3
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
PWM Signal
PD6
PWM
Interrupt
PC3
INT
UART TX
PD0
TX
UART RX
PD1
RX
I2C Clock
PC5
SCL
I2C Data
PC4
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

LP WiFi Click Schematic schematic

Step by step

Project assembly

Click Shield for Arduino UNO front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Arduino UNO Rev3 as your development board.

Click Shield for Arduino UNO front image hardware assembly
Arduino UNO Rev3 front image hardware assembly
Barometer 13 Click front image hardware assembly
Prog-cut hardware assembly
Arduino UNO Rev3 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
Arduino UNO 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

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 LP WiFi Click driver.

Key functions:

  • lpwifi_send_cmd - Send command function.

  • lpwifi_connect_to_ap - Connect to AP function.

  • lpwifi_factory_reset_device - Device factory reset 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 main.c
 * @brief LP WiFi Click Example.
 *
 * # Description
 * This example reads and processes data from LP WiFi Clicks.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and powers up the module, then connects to the desired AP
 * and creates TCP and UDP servers on the desired local port.
 *
 * ## Application Task
 * Logs all the data received from TCP/UDP clients on the USB UART.
 *
 * ## Additional Function
 * - static void lpwifi_clear_app_buf ( void )
 * - static err_t lpwifi_process ( void )
 * - static void lpwifi_error_check( err_t error_flag )
 * - static void lpwifi_log_app_buf ( void )
 * - static err_t lpwifi_rsp_check ( void )
 * - static void lpwifi_check_connection( void )
 *
 * @note
 * In order for the example to work, user needs to set the AP SSID, password, and Local port
 * on which the TCP server and UDP socket will be created.
 * Enter valid data for the following macros: AP_SSID, AP_PASSWORD and LOCAL_PORT.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "lpwifi.h"
#include "string.h"
#include "generic_pointer.h"

// Set AP SSID
#define AP_SSID                     ""

// Set AP password - if the AP is OPEN remain this NULL
#define AP_PASSWORD                 ""

// Set Local port on which the TCP server and UDP socket will be created.
#define LOCAL_PORT                  1

#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 PROCESS_BUFFER_SIZE         400

#define WAIT_FOR_CONNECTION         0
#define CONNECTED_TO_AP             1
#define NOT_CONNECTED_TO_AP         2

static lpwifi_t lpwifi;
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 char assigned_ip_address[ 25 ]      = { 0 };
static uint8_t app_connection_status       = WAIT_FOR_CONNECTION;

static err_t app_error_flag;

/**
 * @brief LP WiFi clearing application buffer.
 * @details This function clears memory of application buffer and reset it's length and counter.
 * @note None.
 */
static void lpwifi_clear_app_buf ( void );

/**
 * @brief LP WiFi data reading function.
 * @details This function reads data from device and concatenates 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 lpwifi_process ( void );

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

/**
 * @brief LP WiFi logs application buffer.
 * @details This function logs data from application buffer.
 * @note None.
 */
static void lpwifi_log_app_buf ( void );

/**
 * @brief LP WiFi 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 lpwifi_rsp_check ( void );

/**
 * @brief LP WiFi check connection.
 * @details This function checks connection to the AP, and fills the assigned_ip_address buffer and
 *          logs the response on the USB UART if it is connected successfully.
 *
 * @note None.
 */
static void lpwifi_check_connection( void );

/**
 * @brief LP WiFi str cut chr function.
 * @details This function removes all selected characters from string str,
 * and returns it to the same str without those characters.
 * @param str Address of string.
 * @param chr Character to cut.
 */
static void lpwifi_str_cut_chr ( uint8_t *str, uint8_t chr );

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    lpwifi_cfg_t lpwifi_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 ( 100 );

    // Click initialization.

    lpwifi_cfg_setup( &lpwifi_cfg );
    LPWIFI_MAP_MIKROBUS( lpwifi_cfg, MIKROBUS_1 );
    err_t init_flag = lpwifi_init( &lpwifi, &lpwifi_cfg );
    if ( UART_ERROR == init_flag )
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }

    lpwifi_default_cfg( &lpwifi );
    Delay_ms ( 500 );

    // Initiate the communication
    lpwifi_send_cmd( &lpwifi, LPWIFI_CMD_AT );
    Delay_ms ( 1000 );

    // Dummy read
    lpwifi_process( );
    lpwifi_clear_app_buf( );

    log_printf( &logger, "\r\n --- Factory reset --- \r\n" );
    lpwifi_factory_reset_device ( &lpwifi );
    Delay_ms ( 500 );
    // Enable Echo
    lpwifi_send_cmd( &lpwifi, LPWIFI_CMD_ATE );
    app_error_flag = lpwifi_rsp_check( );
    lpwifi_error_check( app_error_flag );
    Delay_ms ( 500 );
    log_printf( &logger, " ----------------------------------------------- \r\n" );

    log_printf( &logger, "\r\n --- Connecting to the access point --- \r\n" );
    // Connect to AP
    lpwifi_connect_to_ap( &lpwifi, AP_SSID, AP_PASSWORD );
    app_error_flag = lpwifi_rsp_check( );
    lpwifi_error_check( app_error_flag );
    lpwifi_check_connection();
    while ( CONNECTED_TO_AP != app_connection_status )
    {
        lpwifi_check_connection();
        if ( NOT_CONNECTED_TO_AP == app_connection_status )
        {
            Delay_ms ( 500 );
            app_connection_status = WAIT_FOR_CONNECTION;

            // Connect to AP
            lpwifi_connect_to_ap( &lpwifi, AP_SSID, AP_PASSWORD );
            app_error_flag = lpwifi_rsp_check( );
            lpwifi_error_check( app_error_flag );
        }
    }
    log_printf( &logger, " ----------------------------------------------- \r\n" );
    log_printf( &logger, "\r\n --- Creating a TCP server --- \r\n" );
    // Create TCP Server
    lpwifi_create_tcp_server( &lpwifi, LOCAL_PORT );
    app_error_flag = lpwifi_rsp_check( );
    lpwifi_error_check( app_error_flag );
    Delay_ms ( 500 );

    log_printf( &logger, " ----------------------------------------------- \r\n" );
    log_printf( &logger, "\r\n --- Creating a UDP socket --- \r\n" );
    // Create UDP socket
    lpwifi_create_udp_socket( &lpwifi, LOCAL_PORT );
    app_error_flag = lpwifi_rsp_check( );
    lpwifi_error_check( app_error_flag );
    Delay_ms ( 500 );

    log_printf( &logger, " ----------------------------------------------- \r\n" );
    log_printf( &logger, " TCP server and UDP socket are available at: \r\n" );
    log_printf( &logger, "    SSID: \"%s\"\r\n    IP: %s\r\n    Port: %u", ( char * ) AP_SSID,
                                                                           ( char * ) assigned_ip_address,
                                                                         ( uint16_t ) LOCAL_PORT );
    log_printf( &logger, "\r\n ----------------------------------------------- \r\n" );
    log_printf( &logger, " You can connect to it via a TCP/UDP client." );
    log_printf( &logger, "\r\n ----------------------------------------------- \r\n" );
}

void application_task ( void )
{
    lpwifi_process( );
    lpwifi_log_app_buf( );
}

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;
}

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

static err_t lpwifi_process ( void )
{
    int32_t rx_size;
    char rx_buff[ PROCESS_BUFFER_SIZE ] = { 0 };

    rx_size = lpwifi_generic_read( &lpwifi, rx_buff, PROCESS_BUFFER_SIZE );

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

        if ( app_buf_len + rx_size >= PROCESS_BUFFER_SIZE )
        {
            lpwifi_clear_app_buf(  );
            return LPWIFI_ERROR;
        }
        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 LPWIFI_OK;
    }
    return LPWIFI_ERROR;
}

static err_t lpwifi_rsp_check ( void )
{
    uint16_t timeout_cnt = 0;
    uint16_t timeout = 10000;

    err_t error_flag = lpwifi_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 = lpwifi_process(  );
        if ( ( error_flag != 0 ) && ( error_flag != -1 ) )
        {
            return error_flag;
        }

        timeout_cnt++;
        if ( timeout_cnt > timeout )
        {
            // Initialize AT command
            while ( ( 0 == strstr( app_buf, RSP_OK ) ) && ( 0 == strstr( app_buf, RSP_ERROR ) ) )
            {
                lpwifi_send_cmd( &lpwifi, LPWIFI_CMD_ATZ );
                lpwifi_process(  );
                Delay_ms ( 100 );
            }
            lpwifi_clear_app_buf(  );
            // Enable Echo
            while ( ( 0 == strstr( app_buf, RSP_OK ) ) && ( 0 == strstr( app_buf, RSP_ERROR ) ) )
            {
                lpwifi_send_cmd( &lpwifi, LPWIFI_CMD_ATE );
                lpwifi_process(  );
                Delay_ms ( 100 );
            }
            lpwifi_clear_app_buf(  );
            return APP_ERROR_TIMEOUT;
        }

        Delay_ms ( 1 );
    }

    lpwifi_log_app_buf();

    return APP_OK;
}

static void lpwifi_error_check( err_t error_flag )
{
    if ( ( error_flag != APP_OK ) && ( error_flag != APP_ERROR_DRIVER ) )
    {
        switch ( error_flag )
        {
            case APP_ERROR_OVERFLOW:
                log_error( &logger, " Overflow!" );
                break;
            case APP_ERROR_TIMEOUT:
                log_error( &logger, " Timeout!" );
                break;
            default:
                break;
        }
    }
}

static void lpwifi_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 ] );
    }

    lpwifi_clear_app_buf(  );
}

static void lpwifi_check_connection( void )
{
    #define CONNECTED     "+WFJAP:1"
    #define NOT_CONNECTED "+WFJAP:0"

    lpwifi_process( );
    if ( 0 != strstr( app_buf, CONNECTED ) )
    {
        #define IP_DELIMITER "',"
        char * __generic_ptr app_buf_ptr;
        Delay_ms ( 200 );
        lpwifi_process( );
        app_buf_ptr = strstr( app_buf, IP_DELIMITER );
        strcpy( assigned_ip_address, app_buf_ptr );
        lpwifi_str_cut_chr( assigned_ip_address, '\'' );
        lpwifi_str_cut_chr( assigned_ip_address, ',' );
        lpwifi_str_cut_chr( assigned_ip_address, '\r' );
        lpwifi_str_cut_chr( assigned_ip_address, '\n' );
        lpwifi_log_app_buf( );
        app_connection_status = CONNECTED_TO_AP;
    }
    else if ( 0 != strstr( app_buf, NOT_CONNECTED ) )
    {
        app_connection_status = NOT_CONNECTED_TO_AP;
    }
}

static void lpwifi_str_cut_chr ( uint8_t *str, uint8_t chr )
{
    uint16_t cnt_0, cnt_1;
    for ( cnt_0 = 0; cnt_0 < strlen( str ); cnt_0++ )
    {
        if ( str[ cnt_0 ] == chr )
        {
            for ( cnt_1 = cnt_0; cnt_1 < strlen( str ); cnt_1++ )
            {
                str[ cnt_1 ] = str[ cnt_1 + 1 ];
            }
        }
    }
}

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