Beginner
10 min

Capture and decode barcodes from various media using the LV30 barcode scanner and PIC18F57Q43

OEM scan engine for outstanding screen code scanning performance

Barcode 3 Click with Curiosity Nano with PIC18F57Q43

Published Aug 12, 2024

Click board™

Barcode 3 Click

Dev. board

Curiosity Nano with PIC18F57Q43

Compiler

NECTO Studio

MCU

PIC18F57Q43

Read a wide range of 1D and 2D barcode types, including QR codes, data matrices, and linear barcodes

A

A

Hardware Overview

How does it work?

Barcode 3 Click is based on the LV30, an area image engine from Rakinda designed for efficient barcode scanning. This component features a laser aiming system and an LED illumination system, meeting the safety standards of IEC 62471:2006 for LEDs and IEC 60825:2014 for lasers. The LV30 incorporates a CMOS image sensor and a sophisticated image recognition system-on-chip, enabling quick and accurate decoding of barcodes on various media, including paper and magnetic cards. This versatile engine can be easily integrated into OEM equipment such as handheld, portable, or stationary barcode scanners, making it an excellent choice for upgrading from 1D to 2D barcode scanning solutions. The LV30 is equipped with a red LED (wavelength: 625±10nm) for additional lighting, allowing for barcode scanning even in complete darkness, with the option to turn the illumination ON or OFF. It also includes a laser aimer to help users accurately position the barcode within the scanning area, enhancing efficiency. The aiming pattern can be toggled ON or OFF, with the recommendation to keep it on during scanning for

better accuracy. When using the Barcode 3 Click for scanning through a specific surface, it is crucial to ensure proper protection against dust and other contaminants that could degrade the performance of the LV30 module. The surface through which scanning occurs must be made of clear material; it is recommended to use cell-cast plastics or optical glass such as PMMA, ADC, or chemically tempered glass. While the LV30 performs well under ambient light, exposure to high-frequency pulsed light can negatively impact its performance. The illumination LED in the LV30 is bright but designed to be safe under normal usage conditions. Nevertheless, users should avoid direct eye exposure to the beam. The LV30's physical interface includes a 12-pin FPC connector, which allows the Barcode 3 Click to connect to the host MCU using a 12-wire 0.5mm pitch FPC cable. This setup supports communication via the UART interface (the TX and RX pins of the mikroBUS™ socket) or the USB interface. Since the LV30 operates at 3.3V, while using the USB interface, the necessary power supply is provided through an additional

low-dropout (LDO) regulator, the TLV700, which converts the USB voltage level to the required 3.3V for the LV30. The Barcode 3 Click also features several additional components to enhance its functionality. An onboard buzzer provides audible feedback to the user, indicating power-on and successful read statuses. A blue READ OK LED indicator signals a successful barcode read. The READ button, when pressed and released, activates scanning until a barcode is decoded or the decode session timeout expires. This function can also be achieved through the TRG pin on the mikroBUS™ socket. Additionally, the board includes a RESET button for resetting the LV30, which can also be operated via the RST pin on the mikroBUS™ socket. 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.

Barcode 3 Click hardware overview image

Features overview

Development board

PIC18F57Q43 Curiosity Nano evaluation kit is a cutting-edge hardware platform designed to evaluate microcontrollers within the PIC18-Q43 family. Central to its design is the inclusion of the powerful PIC18F57Q43 microcontroller (MCU), offering advanced functionalities and robust performance. Key features of this evaluation kit include a yellow user LED and a responsive

mechanical user switch, providing seamless interaction and testing. The provision for a 32.768kHz crystal footprint ensures precision timing capabilities. With an onboard debugger boasting a green power and status LED, programming and debugging become intuitive and efficient. Further enhancing its utility is the Virtual serial port (CDC) and a debug GPIO channel (DGI

GPIO), offering extensive connectivity options. Powered via USB, this kit boasts an adjustable target voltage feature facilitated by the MIC5353 LDO regulator, ensuring stable operation with an output voltage ranging from 1.8V to 5.1V, with a maximum output current of 500mA, subject to ambient temperature and voltage constraints.

PIC18F57Q43 Curiosity Nano double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC

MCU Memory (KB)

128

Silicon Vendor

Microchip

Pin count

48

RAM (Bytes)

8196

You complete me!

Accessories

Curiosity Nano Base for Click boards is a versatile hardware extension platform created to streamline the integration between Curiosity Nano kits and extension boards, tailored explicitly for the mikroBUS™-standardized Click boards and Xplained Pro extension boards. This innovative base board (shield) offers seamless connectivity and expansion possibilities, simplifying experimentation and development. Key features include USB power compatibility from the Curiosity Nano kit, alongside an alternative external power input option for enhanced flexibility. The onboard Li-Ion/LiPo charger and management circuit ensure smooth operation for battery-powered applications, simplifying usage and management. Moreover, the base incorporates a fixed 3.3V PSU dedicated to target and mikroBUS™ power rails, alongside a fixed 5.0V boost converter catering to 5V power rails of mikroBUS™ sockets, providing stable power delivery for various connected devices.

Curiosity Nano Base for Click boards accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset
PA7
RST
ID COMM
PD4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Scan Trigger
PB0
PWM
NC
NC
INT
UART TX
PC3
TX
UART RX
PC2
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Barcode 3 Click Schematic schematic

Step by step

Project assembly

Curiosity Nano Base for Click boards front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity Nano with PIC18F57Q43 as your development board.

Curiosity Nano Base for Click boards front image hardware assembly
Charger 27 Click front image hardware assembly
PIC18F47Q10 Curiosity Nano front image hardware assembly
Prog-cut hardware assembly
Curiosity Nano with PICXXX Access 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
PIC18F57Q43 Curiosity 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 Barcode 3 Click driver.

Key functions:

  • barcode3_generic_read - This function reads a desired number of data bytes by using UART serial interface.

  • barcode3_start_scanning - This function starts the barcode scanning by setting the TRG pin to low logic state.

  • barcode3_stop_scanning - This function stops the barcode scanning by setting the TRG pin to high logic state.

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 Barcode 3 Click Example.
 *
 * # Description
 * This example demonstrates the use of the Barcode 3 click board by scanning
 * and displaying the content of a barcode or QR Code.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver, stops scanning and resets the barcode device.
 *
 * ## Application Task
 * Triggers scanning and waits up to 3 seconds for the barcode to be detected.
 * If a barcode or QR Code is detected, it displays its content on the USB UART.
 *
 * ## Additional Function
 * - static void barcode3_clear_app_buf ( void )
 * - static void barcode3_log_app_buf ( void )
 * - static err_t barcode3_process ( barcode3_t *ctx )
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "barcode3.h"

// Application buffer size
#define APP_BUFFER_SIZE             500
#define PROCESS_BUFFER_SIZE         200

static barcode3_t barcode3;
static log_t logger;

static uint8_t app_buf[ APP_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;

/**
 * @brief Barcode 3 clearing application buffer.
 * @details This function clears memory of application buffer and reset its length.
 * @note None.
 */
static void barcode3_clear_app_buf ( void );

/**
 * @brief Barcode 3 log application buffer.
 * @details This function logs data from application buffer to USB UART.
 * @note None.
 */
static void barcode3_log_app_buf ( void );

/**
 * @brief Barcode 3 data reading function.
 * @details This function reads data from device and concatenates data to application buffer. 
 * @param[in] ctx : Click context object.
 * See #barcode3_t object definition for detailed explanation.
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - Nothing is read.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t barcode3_process ( barcode3_t *ctx );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    barcode3_cfg_t barcode3_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 " );

    // Click initialization.
    barcode3_cfg_setup( &barcode3_cfg );
    BARCODE3_MAP_MIKROBUS( barcode3_cfg, MIKROBUS_1 );
    if ( UART_ERROR == barcode3_init( &barcode3, &barcode3_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    barcode3_stop_scanning ( &barcode3 );
    barcode3_reset_device ( &barcode3 );
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    uint16_t timeout = 0;
    log_printf( &logger, "\r\n------- SCAN START ------\r\n" );
    barcode3_start_scanning ( &barcode3 );
    while ( ++timeout < 3000 )
    {
        if ( BARCODE3_OK == barcode3_process( &barcode3 ) )
        {
            barcode3_log_app_buf( );
            barcode3_clear_app_buf( );
            Delay_10ms ( );
            while ( BARCODE3_OK == barcode3_process( &barcode3 ) )
            {
                barcode3_log_app_buf( );
                barcode3_clear_app_buf( );
                Delay_10ms ( );
            }
            break;
        }
        Delay_1ms ( );
    }
    log_printf( &logger, "------- SCAN STOP -------\r\n" );
    barcode3_stop_scanning ( &barcode3 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
}

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 barcode3_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

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

static err_t barcode3_process ( barcode3_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t overflow_bytes = 0;
    int32_t rx_cnt = 0;
    int32_t rx_size = barcode3_generic_read( ctx, rx_buf, PROCESS_BUFFER_SIZE );
    if ( ( rx_size > 0 ) && ( rx_size <= APP_BUFFER_SIZE ) ) 
    {
        if ( ( app_buf_len + rx_size ) > APP_BUFFER_SIZE ) 
        {
            overflow_bytes = ( app_buf_len + rx_size ) - APP_BUFFER_SIZE;
            app_buf_len = APP_BUFFER_SIZE - rx_size;
            memmove ( app_buf, &app_buf[ overflow_bytes ], app_buf_len );
            memset ( &app_buf[ app_buf_len ], 0, overflow_bytes );
        }
        for ( rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) 
        {
            if ( rx_buf[ rx_cnt ] ) 
            {
                app_buf[ app_buf_len++ ] = rx_buf[ rx_cnt ];
            }
        }
        return BARCODE3_OK;
    }
    return BARCODE3_ERROR;
}

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