Intermediate
20 min

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

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

Printer Click with Nucleo 64 with STM32G071RB MCU

Published Jan 06, 2025

Click board™

Printer Click

Dev. board

Nucleo 64 with STM32G071RB MCU

Compiler

NECTO Studio

MCU

STM32G071RB

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

Nucleo-64 with STM32G071RB MCU offers a cost-effective and adaptable platform for developers to explore new ideas and prototype their designs. This board harnesses the versatility of the STM32 microcontroller, enabling users to select the optimal balance of performance and power consumption for their projects. It accommodates the STM32 microcontroller in the LQFP64 package and includes essential components such as a user LED, which doubles as an ARDUINO® signal, alongside user and reset push-buttons, and a 32.768kHz crystal oscillator for precise timing operations. Designed with expansion and flexibility in mind, the Nucleo-64 board features an ARDUINO® Uno V3 expansion connector and ST morpho extension pin

headers, granting complete access to the STM32's I/Os for comprehensive project integration. Power supply options are adaptable, supporting ST-LINK USB VBUS or external power sources, ensuring adaptability in various development environments. The board also has an on-board ST-LINK debugger/programmer with USB re-enumeration capability, simplifying the programming and debugging process. Moreover, the board is designed to simplify advanced development with its external SMPS for efficient Vcore logic supply, support for USB Device full speed or USB SNK/UFP full speed, and built-in cryptographic features, enhancing both the power efficiency and security of projects. Additional connectivity is

provided through dedicated connectors for external SMPS experimentation, a USB connector for the ST-LINK, and a MIPI® debug connector, expanding the possibilities for hardware interfacing and experimentation. Developers will find extensive support through comprehensive free software libraries and examples, courtesy of the STM32Cube MCU Package. This, combined with compatibility with a wide array of Integrated Development Environments (IDEs), including IAR Embedded Workbench®, MDK-ARM, and STM32CubeIDE, ensures a smooth and efficient development experience, allowing users to fully leverage the capabilities of the Nucleo-64 board in their projects.

Nucleo 64 with STM32G071RB MCU double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M0

MCU Memory (KB)

128

Silicon Vendor

STMicroelectronics

Pin count

64

RAM (Bytes)

36864

You complete me!

Accessories

Click Shield for Nucleo-64 comes equipped with two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the STM32 Nucleo-64 board with no effort. This way, Mikroe allows its users to add any functionality from our ever-growing range of Click boards™, such as WiFi, GSM, GPS, Bluetooth, ZigBee, environmental sensors, LEDs, speech recognition, motor control, movement sensors, and many more. More than 1537 Click boards™, which can be stacked and integrated, are at your disposal. The STM32 Nucleo-64 boards are based on the microcontrollers in 64-pin packages, a 32-bit MCU with an ARM Cortex M4 processor operating at 84MHz, 512Kb Flash, and 96KB SRAM, divided into two regions where the top section represents the ST-Link/V2 debugger and programmer while the bottom section of the board is an actual development board. These boards are controlled and powered conveniently through a USB connection to program and efficiently debug the Nucleo-64 board out of the box, with an additional USB cable connected to the USB mini port on the board. Most of the STM32 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 STM32 Nucleo-64 board with our Click Shield for Nucleo-64, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Nucleo-64 accessories 1 image

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
PB12
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
PC14
INT
UART TX
PA2
TX
UART RX
PA3
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

Click Shield for Nucleo-64 accessories 1 image hardware assembly

Start by selecting your development board and Click board™. Begin with the Nucleo 64 with STM32G071RB MCU as your development board.

Click Shield for Nucleo-64 accessories 1 image hardware assembly
Nucleo 64 with STM32F401RE MCU front image hardware assembly
LTE IoT 5 Click front image hardware assembly
Prog-cut hardware assembly
LTE IoT 5 Click complete accessories setup image hardware assembly
Board mapper by product8 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
Clicker 4 for STM32F4 HA 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.