How to Interface Thermal Printer with Arduino UNO

Introduction

The thermal printer you may have come across this term or you may have seen this printing machine in a handheld card swiping machine, in an ATM, in petrol pumps, etc… Right after the payment, you get a received payment in a small paper. Everywhere when it comes to a small readily available cost-effective printing solution to a big machine or a handheld device. Now a day’s thermal printer is used in almost every corner of applications where printing is becoming an add-on feature to the device or machine.

Thermal Printer uses a special quality of paper known as thermo-chromic paper, this paper is active to a temperature that changes its color when a specific amount of heat or proper temperature is provided to this paper. So when a signal maintains a specific temperature at the head of the printer and paper starts to pass through it, According to the heated head the color of the paper turns into blue/black, and thus we can see printed content on it.

In this tutorial, we have a block diagram, circuit explanation, and code explanation and the end upload the code and test the thermal printer using the Adafruit library.

About Thermal Printer

When interfacing with a thermal printer, we typically use communication protocols like Serial (RS232, TTL) and USB. In this case, I am using TTL serial mode because it is straightforward and easy to use.

Power Rating and Requirements:

The printer requires a 9V DC power supply. This means we need to use a 9V DC power adapter. For example, if you have a 12V, 2A SMPS (Switched-Mode Power Supply), you can use a buck converter to step down the voltage to the required 9V, ensuring the printer receives the correct power. A buck converter efficiently reduces the voltage while maintaining the necessary current, providing the 9V, 2A needed by the printer.

Serial Communication:

The printer communicates via TTL (Transistor-Transistor Logic) serial communication. This is done through the available TTL pins on the printer. I chose not to use RS232 to simplify the circuitry. RS232 is another common serial communication method, but it requires additional components, like an RS232 to TTL converter, to interface with most microcontrollers.

Example How to setup:

Powering the Printer:

  • You have a 12V, 2A SMPS. Using a buck converter, you step down the voltage to 9V while ensuring the current rating remains sufficient. Connect the 9V output to the printer’s power input.
  • This setup ensures the printer gets a stable 9V, 2A supply, which is crucial for its operation.

Setting Up Serial Communication:

  • Connect the printer’s TTL serial pins to the corresponding pins on your microcontroller (e.g., Arduino). Typically, you connect the TX (transmit) pin of the printer to the RX (receive) pin of the microcontroller and the RX pin of the printer to the TX pin of the microcontroller.
  • Use the appropriate baud rate (usually specified in the printer’s manual) to establish communication between the microcontroller and the printer. For instance, a common baud rate might be 9600 bps.

Sending Data to the Printer:

  • Using a simple serial communication code, you can send text or commands from the microcontroller to the printer. For example, in an Arduino setup, you might use the Serial.write or Serial.print commands to send data.
  • Here’s a basic Arduino code snippet to send “Hello, World!” to the printer:
void setup() {
  Serial.begin(9600);  // Initialize serial communication at 9600 bps
}

void loop() {
  Serial.println("Hello, World!");  // Send text to the printer
  delay(1000);  // Wait for a second before sending the next line
}

Testing the Setup:

  • After uploading the code to the microcontroller, the printer should start printing “Hello, World!” every second. This confirms that the power and communication setup is correct.

By following these steps, you can efficiently set up and use a thermal printer with a microcontroller using TTL serial communication and the appropriate power supply.

Hardware Requirements

Disclaimer: It may contains Amazon affiliate links. which means I can get a small commission on the sale. This might be your indirect help to me. Thank You 🙏
  • Arduino UNO (HERE)
  • Thermal Printer (HERE)
  • Small Bread Board (HERE)
  • Connectors (HERE)
  • 12v,2AMP Power adapter (HERE)

Software Requirements

  • Arduino IDE (You can download it from HERE)
  • Printer Adafruit library

Block Diagram

Circuit Diagram

Circuit Explanation

Connections from Thermal Printer Module:

  • TX (Transmit) pin of the thermal printer connects to Arduino RX (Receive) pin (pin 0).
  • RX (Receive) pin of the thermal printer connects to Arduino TX (Transmit) pin (pin 1).
  • Note: In Arduino, pin 0 is RX and pin 1 is TX by default. However, for some Arduino models, including the Uno, these pins are also accessible through the digital pins 0 (RX) and 1 (TX).

Power Supply:

The thermal printer typically operates at 5V. Ensure to connect the VCC and GND pins of the printer to the Arduino’s 5V and GND respectively.

Logic Level Conversion (if required):

Some thermal printers operate at 3.3V logic levels. If your printer uses 3.3V logic levels and your Arduino operates at 5V logic levels, you might need a logic level converter to interface them properly. This is crucial to prevent damaging the printer.

Arduino Sketch:

  • Use the Arduino Serial library (Serial.begin(), Serial.print(), etc.) to send commands and data to the thermal printer.
  • Ensure to configure the correct baud rate in your Arduino sketch (Serial.begin() function).

Example Code Snippet:

#include <SoftwareSerial.h>

// SoftwareSerial object for communication with the thermal printer
SoftwareSerial printerSerial(5, 6);  // RX, TX pins on Arduino

void setup() {
  // Start serial communication with Arduino hardware serial port
  Serial.begin(9600);
  // Start software serial communication with the printer
  printerSerial.begin(9600);
}

void loop() {
  // Example: Print text to the thermal printer
  printerSerial.print("Hello, world!\n");
  delay(1000);  // Delay between prints
}

Explanation:

  • SoftwareSerial: Arduino Uno has only one hardware serial port (pins 0 and 1), which is typically used for programming and debugging. If you need to communicate with another serial device (like the thermal printer) using different pins (5 and 6 in this case), you can use the SoftwareSerial library to create a secondary serial port.
  • printerSerial(5, 6): Initializes a SoftwareSerial object named printerSerial using Arduino digital pins 5 (RX) and 6 (TX).
  • setup(): Configures both the hardware serial (for communication with the Arduino IDE) and software serial (for communication with the thermal printer).
  • loop(): Example code to send data (printerSerial.print()) to the thermal printer. Adjust the content based on the specific commands and data format required by your thermal printer.

Ensure to refer to the specific datasheet or documentation provided with your thermal printer module for any additional configuration or commands needed to operate the printer correctly.

Source Code

#include "Adafruit_Thermal.h"
#include "SoftwareSerial.h"

#define TX_PIN 6 // Arduino transmit  YELLOW WIRE  labeled RX on printer
#define RX_PIN 5 // Arduino receive   GREEN WIRE   labeled TX on printer

SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first
Adafruit_Thermal printer(&mySerial);     // Pass addr to printer constructor
void setup() {
  mySerial.begin(9600);  // Initialize SoftwareSerial
  printer.begin();        // Init printer (same regardless of serial type)
  printer.justify('L');
  printer.println("***  MY ENGINEERING STUFFS  ***\n");
  printer.justify('C');
  printer.setSize('L');        // Set type size, accepts 'S', 'M', 'L'
  printer.println("TOKEN NUMBER");
  printer.boldOn();
  printer.setSize('L');
  printer.println("001\n");
  printer.boldOff();
  printer.justify('C');
  printer.setSize('S');
  printer.println("***  HAVE A NICE DAY  ***");
  printer.justify('C');
  printer.print("DATE:24/01/2018\t");
  printer.println("TIME: 00:07");
  printer.println("TODAY: WEDNESDAY");   
  printer.write(10);
  printer.write(10);
  printer.write(10);
}

void loop() {
}

Find More Projects Below

Leave a Comment

Your email address will not be published. Required fields are marked *