Instructions for setting up a Tiny Thermal Receipt Printer - TTL Serial / USB on a Raspberry Pi. And how to program it with Python! 😊
Instructions are from here under the "Install Software" section.
Connect the Micro USB cable to the back of the receipt printer, and connect the other end to a USB port on the Raspberry Pi.
Open a terminal in the Raspberry Pi (or SSH connection) and enter these commands:
sudo apt-get update sudo apt-get install git cups wiringpi build-essential libcups2-dev libcupsimage2-dev python-serial python-pil python-unidecode
Use these commands to install the driver:
cd ~ git clone https://github.com/adafruit/zj-58 cd zj-58 make sudo ./install
Open up the receipt printer to reveal the test page. On that test page, check for a baud rate. We will need that number for our next step. Lost the test page?
192000
, enter this command in the terminal:
sudo lpadmin -p ZJ-58 -E -v serial:/dev/ttyUSB0?baud=19200 -m zjiang/ZJ-58.ppd
9600
, enter this command in the terminal:
sudo lpadmin -p ZJ-58 -E -v serial:/dev/ttyUSB0?baud=9600 -m zjiang/ZJ-58.ppd
Enter these two commands to finalize your changes and restart:
sudo lpoptions -d ZJ-58 sudo reboot
python printertest.py
to see if the printer will print.printertest.py
to see how it works, and use that code to build your own programs that use the receipt printer. Make sure that Adafruit_Thermal.py
stays in the same folder as your python programs.Extra information and frequently asked questions.
To re-print the test page, unplug the receipt printer from a power source and hold down the button on the receipt printer. Continue holding the button and plug the receipt printer in for two more seconds. A test page should begin printing.
printertest.py
do?The most important parts are the beginning and end. The rest is pretty self explanatory. It will print certain things out depending on what options are set. Run it, take a look at the test paper, and compare it to the code to see what it does.
#!/usr/bin/python
< Declares that the script is written in Python
from Adafruit_Thermal import *
< Imports the "Adafruit_Thermal" classes from the file Adafruit_Thermal.py that should be in the same folder.
printer = Adafruit_Thermal("/dev/ttyUSB0", 9600, timeout=5)
< Assigns the printer variable to the receipt printer, which can be found at /dev/ttyUSB0 and has a baud rate of 9600.
printer.sleep()
< Tells printer to sleep
printer.wake()
< Calls wake() before printing again, even if reset
printer.setDefault()
< Restores printer to default settings (no bold, no italics, etc)
Run calibrate.py
(in the same folder as printertest.py
) and follow these directions:
Run
calibrate.py
before using the printer for the first time, any time a different power supply is used, or when using paper from a different source.Prints a series of black bars with increasing "heat time" settings. Because printed sections have different "grip" characteristics than blank paper, as this progresses the paper will usually at some point jam -- either uniformly, making a short bar, or at one side or the other, making a wedge shape. In some cases, the Pi may reset for lack of power.
Whatever the outcome, take the last number printed BEFORE any distorted bar and enter in in Adafruit_Thermal.py as defaultHeatTime (around line 53).
You may need to pull on the paper as it reaches the jamming point, and/or just abort the program, press the feed button and take the last good number.