Intermediate
20 min

Control thermal printer heads with NL022 and PIC32MX470F512H to generate printed output

New generation of powerful ARM based multi-head thermal printer controller

Printer Click with 6LoWPAN clicker

Published Jan 06, 2025

Click board™

Printer Click

Dev. board

6LoWPAN clicker

Compiler

NECTO Studio

MCU

PIC32MX470F512H

Thermal printing with real-time monitoring and barcode generation perfect for POS terminals, ticket machines, and industrial meters

A

A

Hardware Overview

How does it work?

Printer Click is based on the NL022, a thermal printer head controller from Norden Logic designed for high-performance control of thermal printer heads, such as Seiko’s LTP02_245 series, including models like LTP02_245_13 with a 7.2V supply and LTP02_245_C1 with a 4.2V supply, but also WinsPu TP2PX, PRT technology PT48DS-B, and YAEN YAEN208. The board receives power through the VIN terminal, which provides a stable and configurable input voltage to accommodate different thermal print heads, ensuring reliable operation across various supply requirements. This advanced controller communicates with the host MCU via the UART interface and adheres to the widely used ESC/POS programming standard, making it a highly adaptable solution for various printing applications, including medical devices, taxi meters, ticket machines, handheld POS terminals, industrial meters, and cash registers. The NL022 excels due to its ARM-based architecture, offering vast RAM and Flash memory, real-time head temperature monitoring, and a

responsive paper-out detection system. It supports user-definable flash storage and incorporates an extensive selection of built-in language fonts covering 170 languages, including UTF-8 and UTF-16 character encoding, as well as Chinese and Japanese script support. Custom font management and compatibility with ESC commands allow users to tailor text and print output to specific requirements. It is highly recommended to verify that your module is running firmware version 1.22. If it is not, you will need to upgrade the firmware to version 1.22 to ensure improved functionality and access to newly supported printer heads. The NL022 also supports a wide range of font attributes such as double width, double height, bold, italic, reverse, underline, and normal styles, ensuring customizable print output. It enables seamless 1D barcode printing, including formats like UPC-A, UPC-E, EAN-13, EAN-8, CODE39, CODE93, ITF25, CODABAR, and CODE128-A, while 2D barcodes, such as QR codes, can be generated directly on-chip using ESC commands. Additionally,

the NL022 integrates essential real-time monitoring functionalities, including an overheat monitor for thermal head protection, a paper-out detection system to prevent printing errors, and a platen-out monitor for smooth operation. As previously mentioned, this board communicates with the host MCU through the UART interface, using the TX and RX pins with a default baud rate of 115200bps for efficient data exchange. In addition to interface pins, the board also uses the INT pin, which functions as a ready-to-send signal. When the INT pin is in a LOW state, the NL022 controller is ready to receive and process data, whereas a HIGH state indicates that the controller is busy and cannot accept new data at that moment. 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. It also comes equipped with a library containing functions and example code that can be used as a reference for further development.

Printer Click hardware overview image

Features overview

Development board

6LoWPAN Clicker is a compact starter development board that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit PIC microcontroller, the PIC32MX470F512H from Microchip, a USB connector, LED indicators, buttons, a mikroProg connector, and a header for interfacing with external electronics. Along with this microcontroller, the board also contains a 2.4GHz ISM band transceiver, allowing you to add wireless communication to your target application. Its compact design provides a fluid and immersive working experience, allowing access anywhere

and under any circumstances. Each part of the 6LoWPAN Clicker development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the 6LoWPAN Clicker programming method, using USB HID mikroBootloader, or through an external mikroProg connector for PIC, dsPIC, or PIC32 programmer, the Clicker board also includes a clean and regulated power supply module for the development kit. The USB Micro-B connection can provide up to 500mA of current for the Clicker board, which is more than enough to operate all onboard and additional modules, or it can power

over two standard AA batteries. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several buttons and LED indicators. 6LoWPAN Clicker is an integral part of the Mikroe ecosystem, allowing you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

6LoWPAN clicker double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC32

MCU Memory (KB)

512

Silicon Vendor

Microchip

Pin count

64

RAM (Bytes)

131072

You complete me!

Accessories

Thermal Printer Head – 7.2V (LTP02-245-13C) is a high-resolution thermal line printer head from Seiko Printers that delivers precision and reliability with 384 printable dots per line. Featuring a high-density print head of 8 dots/mm and a maximum print speed of 100mm/s, it ensures clear, fast, and low-noise operation. Its compact dimensions of 67.3×18.1×30.0mm and lightweight design of 28g simplify integration, while the platen unit open mechanism enables easy paper installation. Maintenance-free functionality and precise 0.03125mm paper feed pitch further enhance its performance. This printer head is ideal for applications such as measuring instruments, analyzers, POS systems, communication terminals, and data terminal devices, where reliable and efficient printing is essential.

Printer Click accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
ID COMM
RE5
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Ready-to-Send
RD0
INT
UART TX
RF4
TX
UART RX
RF5
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Printer Click Schematic schematic

Step by step

Project assembly

PIC32MZ clicker front image hardware assembly

Start by selecting your development board and Click board™. Begin with the 6LoWPAN clicker as your development board.

PIC32MZ clicker front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Micro B Connector Clicker Access - 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
Flip&Click PIC32MZ 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

Printer Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.

Example Description

This example demonstrates the use of Printer Click board by providing user interaction with a thermal printer, allowing the user to check paper status, display commands, and execute various printing tasks based on user commands through a UART interface.

Key functions:

  • printer_cfg_setup - Config Object Initialization function.

  • printer_init - Initialization function.

  • printer_default_cfg - Click Default Configuration function.

  • printer_get_status - This function reads the paper status and temperature of the printer and stores results in ctx->status string buffer.

  • printer_get_fw_info - This function reads the firmware information of the printer and stores results in ctx->fw_info string buffer.

  • printer_print_string_lf - This function prints a string message with line feed.

Application Init
Initializes the driver, performs the Click default configuration, and displays the list of supported commands on the USB UART.

Application Task
Checks the paper status and processes user commands.

Additional Notes and Information
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.

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 Printer Click Example.
 *
 * # Description
 * This example demonstrates the use of Printer Click board by providing user interaction
 * with a thermal printer, allowing the user to check paper status, display commands,
 * and execute various printing tasks based on user commands through a UART interface.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver, performs the Click default configuration, and displays the list
 * of supported commands on the USB UART.
 *
 * ## Application Task
 * Checks the paper status and processes user commands.
 * 
 * @note
 * The default printer head type is set to LTP02-245-13.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "printer.h"

static printer_t printer;
static log_t logger;

/**
 * @brief Printer check paper function.
 * @details This function checks if the paper is presented and feeds the newly inserted paper.
 * @return None.
 * @note None.
 */
static void printer_check_paper ( printer_t *ctx );

/**
 * @brief Printer display commands function.
 * @details This function displays the list of supported terminal commands on the USB UART.
 * @return None.
 * @note None.
 */
static void printer_display_commands ( void );

/**
 * @brief Printer parse command function.
 * @details This function checks if the input command is supported and executes it.
 * @param[in] ctx : Click context object.
 * See #printer_t object definition for detailed explanation.
 * @param[in] command : Command input, for more details refer to @b printer_display_commands function.
 * @return @li @c  0 - Success,
 *         @li @c -1 - Wrong command or command is not executed properly.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t printer_parse_command ( printer_t *ctx, uint8_t command );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    printer_cfg_t printer_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.
    printer_cfg_setup( &printer_cfg );
    PRINTER_MAP_MIKROBUS( printer_cfg, MIKROBUS_1 );
    if ( UART_ERROR == printer_init( &printer, &printer_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( PRINTER_ERROR == printer_default_cfg ( &printer ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }

    printer_display_commands ( );
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    uint8_t command = 0;
    printer_check_paper ( &printer );
    if ( 1 == log_read ( &logger, &command, 1 ) ) 
    {
        printer_parse_command ( &printer, command );
    }
}

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 printer_check_paper ( printer_t *ctx )
{
    static uint8_t valid_change = 0;
    static uint8_t no_paper = 0;
    if ( PRINTER_OK == printer_get_status ( ctx ) )
    {
        if ( '0' == printer.status[ 0 ] )
        {
            if ( !no_paper )
            {
                // Confirm paper status change with 10 consecutive validation before taking actions
                if ( ++valid_change > 10 )
                {
                    log_printf ( &logger, "No paper detected!\r\n" );
                    no_paper = 1;
                    valid_change = 0;
                }
            }
        }
        else
        {
            if ( no_paper )
            {
                // Confirm paper status change with 10 consecutive validation before taking actions
                if ( ++valid_change > 10 )
                {
                    // Feeding inserted paper
                    for ( uint8_t cnt = 0; cnt < 5; cnt++ )
                    {
                        printer_print_lf ( ctx );
                        Delay_ms ( 10 );
                    }
                    log_printf ( &logger, "Paper OK!\r\n" );
                    no_paper = 0;
                    valid_change = 0;
                }
            }
        }
        Delay_ms ( 100 );
    }
}

static void printer_display_commands ( void )
{
    log_printf( &logger, "--- UART commands list (no case sensitive) ---\r\n" );
    log_printf( &logger, "'+' - New line / Feed paper.\r\n" );
    log_printf( &logger, "'T' - Print \"MIKROE - Printer Click\" message.\r\n" );
    log_printf( &logger, "'R' - Print POS receipt sample.\r\n" );
    Delay_ms ( 10 );
    log_printf( &logger, "'A' - Print tab and alignment sample.\r\n" );
    log_printf( &logger, "'S' - Get status.\r\n" );
    log_printf( &logger, "'F' - Get firmware information.\r\n" );
    log_printf( &logger, "'L' - Display commands list.\r\n" );
    Delay_ms ( 10 );
}

static err_t printer_parse_command ( printer_t *ctx, uint8_t command )
{
    err_t error_flag = PRINTER_OK;
    log_printf( &logger, "\r\n" );
    switch ( command )
    {
        case '+': 
        {
            log_printf( &logger, "Printing New Line / Feed paper\r\n" );
            error_flag |= printer_print_lf ( ctx );
            break;
        }
        case 'T': case 't': 
        {
            log_printf( &logger, "Printing \"MIKROE - Printer Click\" message.\r\n" );
            error_flag |= printer_soft_init ( ctx );
            error_flag |= printer_set_alignment ( ctx, PRINTER_ALIGN_CENTER );
            error_flag |= printer_set_font_type ( ctx, PRINTER_FONT_TYPE_NORMAL );
            error_flag |= printer_print_string_lf ( ctx, "MIKROE - Printer Click" );
            error_flag |= printer_print_lines ( ctx, 1 );
            break;
        }
        case 'R': case 'r': 
        {
            log_printf( &logger, "Printing POS receipt sample.\r\n" );
            error_flag |= printer_soft_init ( ctx );
            error_flag |= printer_set_font_grayscale ( ctx, PRINTER_GRAYSCALE_4 );
            error_flag |= printer_set_alignment ( ctx, PRINTER_ALIGN_CENTER );
            error_flag |= printer_set_font_type ( ctx, PRINTER_FONT_TYPE_BOLD );
            error_flag |= printer_print_string_lf ( ctx, "MIKROE" );
            error_flag |= printer_set_font_type ( ctx, PRINTER_FONT_TYPE_NORMAL );
            error_flag |= printer_print_lines ( ctx, 1 );
            error_flag |= printer_print_string_lf ( ctx, "Customer Receipt" );
            error_flag |= printer_print_lines ( ctx, 2 );
            error_flag |= printer_set_alignment ( ctx, PRINTER_ALIGN_LEFT );
            error_flag |= printer_print_string_lf ( ctx, "Date: DD/MM/YYYY" );
            error_flag |= printer_print_string_lf ( ctx, "PID: 034/344/00288394" );
            error_flag |= printer_print_lines ( ctx, 2 );
            error_flag |= printer_print_string_lf ( ctx, "  Qty      Item      Price" );
            error_flag |= printer_print_string_lf ( ctx, "................................" );
            error_flag |= printer_print_string_lf ( ctx, "2x  1L 1.5% Milk     $3.98" );
            error_flag |= printer_print_string_lf ( ctx, "6x  1L 3.5% Milk     $16.75" );
            error_flag |= printer_print_string_lf ( ctx, "10x 100g Yogurt Cup  $8.50" );
            error_flag |= printer_print_string_lf ( ctx, "................................" );
            error_flag |= printer_set_font_type ( ctx, PRINTER_FONT_TYPE_BOLD );
            error_flag |= printer_print_string_lf ( ctx, "Total:              $29.23" );
            error_flag |= printer_print_lines ( ctx, 1 );
            error_flag |= printer_set_font_type ( ctx, PRINTER_FONT_TYPE_NORMAL );
            error_flag |= printer_print_string_lf ( ctx, "Incl. 19% VAT $5.55 (Net $23.68)" );
            error_flag |= printer_print_string_lf ( ctx, "................................" );
            error_flag |= printer_set_font_type ( ctx, PRINTER_FONT_TYPE_DOUBLE_HEIGHT );
            error_flag |= printer_print_string_lf ( ctx, "Credit Card         $29.23" );
            error_flag |= printer_print_lines ( ctx, 2 );
            error_flag |= printer_set_alignment ( ctx, PRINTER_ALIGN_CENTER );
            error_flag |= printer_print_string_lf ( ctx, "THANK YOU FOR YOUR VISIT" );
            error_flag |= printer_print_lines ( ctx, 2 );
            break;
        }
        case 'A': case 'a': 
        {
            uint8_t tabs[ 3 ] = { 8, 24, 38 };
            log_printf( &logger, "Printing tab and alignment sample.\r\n" );
            error_flag |= printer_soft_init ( ctx );
            error_flag |= printer_set_alignment ( ctx, PRINTER_ALIGN_LEFT );
            error_flag |= printer_set_horizontal_tab ( ctx, tabs, 3 );
            error_flag |= printer_set_font_type ( ctx, PRINTER_FONT_TYPE_NORMAL );
            error_flag |= printer_print_string_lf ( ctx, "................................" );
            error_flag |= printer_print_string_lf ( ctx, "No Tab: abcd" );
            error_flag |= printer_horizontal_tab ( ctx );
            error_flag |= printer_print_string ( ctx, "Tab1" );
            error_flag |= printer_horizontal_tab ( ctx );
            error_flag |= printer_print_string ( ctx, "Tab2" );
            error_flag |= printer_horizontal_tab ( ctx );
            error_flag |= printer_print_string_lf ( ctx, "Tab3" );
            error_flag |= printer_print_string_lf ( ctx, "................................" );
            error_flag |= printer_set_abs_print_pos ( ctx, 50 );
            error_flag |= printer_print_string_lf ( ctx, "Abs: 1234" );
            error_flag |= printer_print_string_lf ( ctx, "................................" );
            error_flag |= printer_set_alignment ( ctx, PRINTER_ALIGN_CENTER );
            error_flag |= printer_print_string_lf ( ctx, "Center: abcd" );
            error_flag |= printer_set_alignment ( ctx, PRINTER_ALIGN_RIGHT );
            error_flag |= printer_print_string_lf ( ctx, "Right: abcd" );
            error_flag |= printer_set_alignment ( ctx, PRINTER_ALIGN_LEFT );
            error_flag |= printer_print_string_lf ( ctx, "Left: abcd" );
            error_flag |= printer_print_string_lf ( ctx, "................................" );
            break;
        }
        case 'S': case 's': 
        {
            error_flag |= printer_get_status ( ctx );
            if ( PRINTER_OK == error_flag )
            {
                log_printf ( &logger, "--- Status ---\r\n" );
                log_printf ( &logger, "%s", printer.status );
                if ( '0' == printer.status[ 0 ] )
                {
                    log_printf ( &logger, "No paper detected!\r\n" );
                }
                else
                {
                    log_printf ( &logger, "Paper OK!\r\n" );
                }
            }
            break;
        }
        case 'F': case 'f': 
        {
            error_flag |= printer_get_fw_info ( ctx );
            if ( PRINTER_OK == error_flag )
            {
                log_printf ( &logger, "--- Firmware information ---\r\n" );
                log_printf ( &logger, "%s", printer.fw_info );
                uint8_t head_type_index = strlen ( ( char * ) printer.fw_info ) - 3;
                log_printf ( &logger, "Printer head type: " );
                if ( '0' == printer.fw_info[ head_type_index ] )
                {
                    log_printf ( &logger, "MM58_FTP628MCL101\r\n" );
                }
                else if ( '1' == printer.fw_info[ head_type_index ] )
                {
                    log_printf ( &logger, "MM80_FTP638MCL101\r\n" );
                }
                else if ( '2' == printer.fw_info[ head_type_index ] )
                {
                    log_printf ( &logger, "MM58_LTP02_245_13\r\n" );
                }
                else if ( '3' == printer.fw_info[ head_type_index ] )
                {
                    log_printf ( &logger, "MM58_LTP02_245_C1\r\n" );
                }
                else
                {
                    log_printf ( &logger, "UNKNOWN\r\n" );
                }
            }
            break;
        }
        case 'L': case 'l': 
        {
            printer_display_commands ( );
            break;
        }
        default :
        {
            log_error( &logger, "Unknown command." );
            error_flag |= PRINTER_ERROR;
            break;
        }
    }
    log_printf( &logger, "----------------------------------------------\r\n" );
    Delay_ms ( 100 );
    return error_flag;
}

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