99-com.rules Raspberry to Escpos Printer

99-com.rules Raspberry to Escpos Printer

Today, in this project we will learn how to interface a Thermal Printer with Raspberry Pi using a hardware series advice, to impress a test receipt that contains various elements similar a Logo, a QR Code, or barcode along with diverse other text and graphical characters. Equally nosotros all know, Raspberry Pi is a portable development board and we accept already built many
raspberry pi based projects
previously. In this project, we will exist
Interfacing a
Thermal Printer with Raspberry Pi,
then by using Serial communication and thepython-escpos library we will control the thermal printer from raspberry pi and impress text and graphical images.You lot should check out our previous articles, where nosotros already interfaced thermal printer with
Arduino Uno

Before going farther allow usa have a look at these steps that volition be involved,

  1. Enable the Hardware Serial through

  2. Connections for
    Thermal printer
    Pi three
  3. Figure out how the
    commands work.
  4. Install the library from GitHub.
  5. Nosotros will exercise some basic coding to print
    QR Code,
  6. We will try Print a sample Receipt
  7. Conclusion

Components for Interfacing the Thermal Printer with Raspberry Pi

Component Name Qty
Thermal Printer Maxim PNP-500 1
Raspberry Pi three or Raspberry Pi 0 1
Jumper Wires Male to Female As required
9V 1 Amp Adaptor ane

The above table is showing the list of components I am using as of now, you tin have a different set of thermal printers and Raspberry Pi versions. Also, my printer requires at least 6 Volts to operate. (Please check the
user transmission
while selecting the ability source).

What is a Thermal Printer?

A thermal printer is a printer that uses heating head-on thermal papers to produce images. Its quality of print, ease of installation, minimum use of external components, and low ability consumption, makes it more than popular amongst token or ticket counters, grocery stores, tiffin centers, amusement centers, healthcare, corporate industries, etc. It’south both eco-friendly besides as a price-effective solution for pocket-sized-scale use as no ink Cartridge or ribbon is used.

It provides a noise-free performance forth with faster monochromatic printing. Brand sure to use the printer with an optimized temperature of print caput as it may get damaged on operating with high temperature.

99-com.rules Raspberry to Escpos Printer

In our instance, nosotros are using a thermal printer that can be interfaced using RS232 mode or Serial TTL. I am using a 9V adaptor to power it upward. By default, the baud rate of almost of the printers is
9600. We will utilize the
TTL fashion
of communication in this case. For more than technical details of the printer please
download Brochure.

Impress Method

Thermal Direct Line Printing

Paper loading method

Easy paper loading

Newspaper width

57 mm

Print width

48 mm

Print speed

250 mm/sec

Resolution ratio

eight dots/mm (384 dots/line)

Life of printing head

50 km

Press speed

l mm/sec

Max. printing speed

lxxx mm/sec

Graphic symbol size

9 x 17 • 12 x 24

Chinese character fonts


Chinese character size

12 ten 24 dots • 24 ten 24 dots

Outline dimension

76.viii ten 77.4 x 47.half dozen (WxDxH mm)


72.8 x 73.four (WxD mm)

Embedded depth

34.65 mm

Paper roll specification

Width : 58 mm, max. diameter: 40 mm


Serial (RS232C,TTL) / USB

Input power

DC5-9V • 12V

Operating temperature


Storage temperature


Operating humidity


Storage humidity


Read:  Epson Tm T88v Cannot Communicate With Printer

Near of the printers work on ESC Point of service commands for interfacing with computers which was designed past EPSON. It was mostly used in some inkjet printers, dot matrix printers and is nevertheless widely used in many receipts thermal printers for controlling them. As of 2014, few modern non-Epson printers use ESC/P instead and virtually are driven through a standardized page description language, usually, PCL or PostScript, or they use proprietary protocols such equally Hardware Code Pages.

This thermal printer works on ESC/POS command for which we will be using the defended library.

Enabling Serial Port of our Raspberry Pi

In the terminal, write the following command and so press enter.

sudo raspi-config

You volition come across the configuration page, then navigate to ‘interfacing option’ through the arrow keys. After pressing enter, get to the ‘series port enable/disable’ choice. Press ‘no’ for enabling the
serial login beat
and then printing ‘yep’ for enabling the ‘Hardware Series port’. Click ‘ok’ and and so click on the ‘finish push button’
to reboot your pi.

Now past doing so, you have enabled your Hardware Serial i.eastward. ‘

which is dedicated for

 This tin be determined by inbound the following command on Pi-three.

ls -l /dev

Yous’ll see the post-obit screenshot.Serial 1
is being used by the
onboard Bluetooth
of the Raspberry Pi 3. And so, nosotros will only be using the Serial 0 for the Thermal printer that is to be continued to GPIO 14 and GPIO 15 as TX-D0 and RX-D0.

Enabling Serial Port of our Raspberry Pi

Now nosotros will connect the Printer with our Raspberry Pi and provide 9V Supply to the Printer.

Connection Diagram for Interfacing Thermal Printer and Raspberry Pi 3

Here you can see that RXD of the Printer is connected to the TXD of the Raspberry Pi and the TXD of the Thermal printer is connected to the RXD of the Raspberry Pi 3.

Connection Diagram for Interfacing Thermal Printer and Raspberry Pi 3

Besides, one tin can note that TDR and GND are gear up to GND every bit of now. My printer was not press until I put TDR to the footing.

Read:  Pdf Printer Windows 7 64 Bit Free

Interfacing Thermal Printer on Raspberry Pi

Lawmaking for Interfacing Thermal Printer and Raspberry Pi

As nosotros have discussed earlier, the thermal printer can be controlled by passing appropriate
ESC POS Command. But for now, we are using a library to interface it as this library volition ship the data past using the same commands and your desired print would become easy. It is quite circuitous to understand the basic nature of the printers based on ESC Command but once y’all larn the basics, it would become a slice of cake for you.

Now for installation of the library write the following command in the terminal.

sudo pip install python-escpos

Past doing so, you will exist able to use the library. We will be using the serial UART protocol for interfacing.

Printing Text
on Thermal Printer

Hither we will be testing our first lawmaking on the printer that will impress the text “Hello World” followed by a QR code.

from escpos.printer import Serial """ 9600 Baud, 8N1, Flow Control Enabled """ p = Serial(devfile='/dev/serial0,            baudrate=9600,            bytesize=8,            parity='Northward',            stopbits=ane,            timeout=1.00,            dsrdtr=True) p.text("Hullo World\due north")

Now y’all can have a look at the detailed
for learning and exploring the functions and methods of this amazing library.

Setting upward the Text Properties on Thermal Printer

The ‘set()’
function will be used to set the text properties like font manner (‘a’ or ‘b’), alignment, or font size.

p.set(         underline=1,         align="left",         font="a",         width=2,         height=ii,         density=3,         invert=0,         smooth=Simulated,         flip=False, ) p.textln(“Hello World”)

The text can also exist assuming or normal, inverted to black and white, or flip similar upside or downside.

Printing the Barcodes

barcode(information, code_type, pos)
where the arguments will be as follows,

information= “whatsoever data to convert into Barcode” code_type=”blazon of barcode for eg. CODE39, CODE128, UPC-i, etc. “ POS=”position of the barcode data for eg. ‘Beneath’, ABOVE, BOTH, OFF“

For farther details about this method delight refer to the documentation page. It can be noted that the size of the barcode can as well be adjusted by passing the respective arguments.

p.barcode('123456', 'CODE39')

This will print the barcode that will store ‘123456’. Also, this will be of CODE39 type. Moreover, for the alignment of the barcode, you tin use the
role as we discussed before.

Printing Barcodes with Thermal Printer

Printing the QR Code

Now you volition exist amazed to know that the ESCPOS Library has the facility to catechumen your data into a QR Code directly by passing the desired string. For printing a QR Code of your desired information, you can utilise the following Office.

p.qr("Excursion Digest",native=Truthful,size=12)

Hither yous can pass the “Cord data in quotes”, size of the QR lawmaking, and native as True or FALSE.

Printing QR Codes with Thermal Printer

Printing Image using Thermal Printer

Now it’southward time for the epitome printing, here you can locate the image and pass the location equally the argument of the


Here “the path of the image should identify here”, followed by the impl every bit “imageRaster” or “bitImageColumn”  etc. You lot tin take a look at the documentation part for more than details. Just keep in mind that the pixels of width should not be more than than 360 as the page size has a limited width.

Read:  Why My Printer Is Not Printing Properly

Printing Image using Thermal Printer

Print Sample Receipt using Thermal Printer

Then, now it’southward time to print our first Receipt using Thermal Printer but earlier going further please annotation that we are difficult coding the output for now and volition attempt to make it dynamic next time.

Printing Sample Receipt using Thermal Printer

The lawmaking for printing the receipt is as follows:

from escpos.printer import Serial from time import * from datetime import date from datetime import datetime at present = datetime.at present() dt_string = now.strftime("%b/%d/%Y %H:%Grand:%S") print("Today'south engagement:", dt_string) """ 9600 Baud, 8N1, Period Control Enabled ""' p = Serial(devfile='/dev/serial0',            baudrate=9600,            bytesize=eight,            parity='Due north',            stopbits=i,            timeout=one.00,            dsrdtr=True ) p.set(         underline=0,         align="left",         font="a",         width=ii,         height=2,         density=3,         invert=0,         polish=False,         flip=Faux, ) p.text("\n") p.ready(         underline=0,         align="center",         font="a",         width=ii,         tiptop=2,         density=2,         capsize=0,         smooth=False,         flip=False, ) #Printing the image # here location can be your image path in “ ” p.prototype("/habitation/pi/proj on pi0/CD_new_Logo_black.png",impl="bitImageColumn") #printing the initial information p.set up(         underline=0,         align="left", ) p.textln("Circuit Digest\n") p.text("AIRPORT ROAD\due north") p.text("LOCATION : JAIPUR\due north") p.text("TEL : 0141222585\n") p.text("GSTIN : \n") p.text("Neb No. : \due north\n") p.set(         underline=0,         marshal="left",         font="a",         width=2,         height=2,         density=2,         invert=0,         smooth=False,         flip=False,    ) # print the date and fourth dimension of printing every time p.text("DATE : ") p.text(dt_string) p.textln("\n") p.textln("CASHIER : ") p.textln(" ===========================") p.textln("      ITEM   QTY  PRICE    GB") p.textln(" --------------------------") p.textln("IR SENSOR  2  30   60") p.textln("ULTRASONIC  ii  80   160") p.textln("RASPBERRY  one  3300   3300") p.textln("ADOPTOR  2  120   240") p.textln(" --------------------------") p.textln("     SUBTOTAL:  3760") p.textln("     Disbelieve:  0.eight") p.textln("     VAT @ 18%: 676.8") p.textln(" ===========================") p.textln("    Neb Total: 4436.8") p.textln("     TENDERD:  0.8") p.textln("     BALANCE: 676.8") p.textln(" --------------------------") p.textln("          Give thanks YOU") p.textln(" ===========================") p.set(         underline=0,         marshal="centre",         font="a",         width=two,         height=2,         density=2,         invert=0,         polish=False,         flip=Imitation,   ) p.qr("Circuit Assimilate",native=True,size=12) p.textln("") p.barcode('123456', 'CODE39') #if your printer has newspaper cuting facility then you can employ this function p.cut() print("done")


We can have multiple ideas of printing text in different fonts, and various sizes on the thermal printer. In this commodity, we have learned some bones functionalities of the thermal printer and what commands does information technology support, i.eastward. ESCPOS in our case. Besides, we come up to know that thermal printers are the handiest in daily usage, have a long life, and have less maintenance. Information technology can print up to 50Kms of fully dense written newspaper roles. We will effort to impress some more tables and aligned text side by side time, till then stay connected.

99-com.rules Raspberry to Escpos Printer

Check Also

Alasan Kertas Novel Tidak Bisa Di Printer Biasa

Alasan Kertas Novel Tidak Bisa Di Printer Biasa

Alasan Kertas Novel Tidak Bisa Di Printer Biasa Pasti kamu setuju bahwa printer sangat dibutuhkan …