Arduino Code

To send data to the printer, we will use a 5V TTL serial connection. This is not the same as the 10V RS232 serial from a computer’s 9-pin serial port — don’t connect the printer directly to a standard PC port or you may damage it. It’s possible to use something like an FTDI cable to talk to the printer, but we’re going to assume that nearly everyone will want to use it with a microcontroller. This tutorial shows how to wire it up to an Arduino, and our example code is Arduino-compatible. Any microcontroller that can output TTL serial will work, with suitable adaptation to the code.

To start, we’ll connect to the data cable of the printer. An easy way to connect is to simply press 22AWG or so wires of matching colors into the plug, then use those to extend the connection to an Arduino.

For Product #597

The "Mini Thermal Printer"s data cable has three wires

  • black = GROUND
  • yellow = data IN to the printer
  • green = data OUT of the printer

On the power cable, connect red to 5-9VDC power and black to power ground

For Product #2751

The "Tiny Thermal Printer"s data cable has five wires

  • black = GROUND
  • green = data IN to the printer - Opposite of the Mini Thermal printer!
  • yellow = data OUT of the printer - Opposite of the Mini Thermal printer!

leave red and blue not connected to anything

On the power cable, connect red to 5-9VDC power and black to power ground

For Product #2752

The "Nano Thermal Printer"s data cable has five wires and no power cable

  • black = GROUND
  • blue = data IN to the printer (labeled RX on the PCB)
  • green = data OUT of the printer (labeled TX on the PCB)
  • red = 5-9VDC power (connect the ground of the power plug to the same ground as data above)
  • yellow = DTR, not used at this time, skip!

For Product #2753

The "Thermal Printer Guts"s data cable has five wires and no power cable

This cable may not have colors in which case look for the text on the connector. Its, sadly, covered when you plug in the cable

  • VH = 5-9VDC power (connect the ground of the power plug to the same ground as data above)
  • GND = GROUND
  • labeled RX on the PCB = data IN to the printer
  • labeled TX on the PCB = data OUT of the printer
  • DTR, not used at this time, skip!

Connect to Arduino

At the Arduino end, the Data OUT wire connects to digital pin 5, Data In goes to digital pin 6 and Ground to any of the GND pins. You can change the digital pins later, but to match the example code, stick to this for now!

Note the colors of the wires below don't necessarily match the colors of the data cable, so double check the in and out designation for your product, they're all different!

Install Library

Now its time to download the Arduino library code.

Go to the Arduino Library manager under Sketch -> Include Library -> Manage Libraries...

From within the manager install Adafruit Thermal Printer library

We also have a great tutorial on Arduino library installation at:
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use

After installing the library, restart the Arduino IDE.

You should now be able to access the sample code by navigating through menus in this order: File→Sketchbook→Libraries→Adafruit_Thermal→A_printertest

If your printer test page shows 'BAUDRATE: 9600', you'll need to make a small change to the library source code. Using a text editor (Notepad, etc.) open the file Adafruit_Thermal.cpp and change this line:

#define BAUDRATE  19200
to this:
#define BAUDRATE  9600

Some printers arrive from the factory set for 19200 baud, but a few may be set to 9600. This will not negatively impact the performance of your unit! The speed of the paper through the printer is already much less than this and you will not see any difference…it's strictly a data protocol issue of getting the microcontroller and printer communicating.

OK upload the sketch (with baudrate change if necessary) to the Arduino. You should see the printer print out the example receipt which includes all the capabilities of the library.

 

If this does not work, first check that the printer and Arduino are both powered, and that the data in, out and ground wires are properly connected to the Arduino.

This guide was first published on Sep 02, 2012. It was last updated on Oct 18, 2018. This page (Arduino Code) was last updated on Jan 25, 2018.