Git Product home page Git Product logo

python-thermal-printer's Introduction

!!! NOTE !!!

THIS REPOSITORY IS ARCHIVED AND IS NO LONGER SUPPORTED OR MAINTAINED

Python-Thermal-Printer Module

Python3 port of the original Adafruit Python-Thermal-Printer library.

Getting Started

Install Raspbian Buster and Wire the printer according to this. I powered the printer with the GPIO pins as well.

Run a test to see if the printer is working by punching in these commands into the terminal.

stty -F /dev/serial0 19200
echo -e "This is a test.\\n\\n\\n" > /dev/serial0

Installing

Update the system and install prerequisites.

sudo apt-get update
sudo apt-get install git cups wiringpi build-essential libcups2-dev libcupsimage2-dev python3-serial python-pil python-unidecode

Install the printer driver. Don't worry about the warnings that g++ gives.

git clone https://github.com/adafruit/zj-58
cd zj-58
make
sudo ./install

Make the printer the default printer. This is useful if you are going to be doing other things with it.

sudo lpadmin -p ZJ-58 -E -v serial:/dev/serial0?baud=19200 -m zjiang/ZJ-58.ppd
sudo lpoptions -d ZJ-58

Restart the system. Clone this repository and try to run printertest.py.

git clone https://github.com/galacticfan/Python-Thermal-Printer/
cd Python-Thermal-Printer
python3 printertest.py

Let me know if you have any issues.

python-thermal-printer's People

Contributors

bsmithyman avatar caternuson avatar codedelux avatar gregorspamsa avatar jmzjmzjmz avatar kitlaan avatar kso512 avatar ladyada avatar masatomukoda avatar nathanllee1 avatar paintyourdragon avatar sauntheninja2 avatar zackdotcomputer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-thermal-printer's Issues

Handling accents

Hello ! I'm French and I'm having troubles at printing accents (é, à,...) prints different characters. I've found it is a problem between Latin-1 and ISO_8859, I've tried many different things but still didn't find a solution... how would it possible to fix this ?
Thank you all for your help 🙏

Print Speed

While testing printer (connecting VCC while pressing feed button) its speed dramatically increases if I use 9V instead of 5V.

But printertest.py not affected by this voltage change. It still prints slowly. It seems it waits some time between every "rows" whereas it prints continuously while testing. Is there any configuration for this ?

Thanks

Printing the graph using thermal printer(printing graph image is not clear)

Hello there,
I want to print graph using thermal printer connected to beaglebone black. But printed graph images did not display clear enough. How can I make printings sharp? sudoku-txt and gfx examples in this repository have really huge difference in sharpness, one is displaying image and another created lines to display it. Do I also need to do printings using lines? Or how can overcome this?
Thank you
Regards,

SerialException: write failed: [Errno 5] Input/output error

Connected Thermal printer with Ubuntu PC but not working
Given all permission to USB port

Traceback (most recent call last):
File "/media/abhishek/New Volume/OSPL_Energy/ABS sensor tester/Knorr_bremse/thermal_printer.py", line 22, in
printer.inverseOn()
File "/media/abhishek/New Volume/OSPL_Energy/ABS sensor tester/Knorr_bremse/Adafruit_Thermal.py", line 402, in inverseOn
self.writeBytes(29, 66, 1)
File "/media/abhishek/New Volume/OSPL_Energy/ABS sensor tester/Knorr_bremse/Adafruit_Thermal.py", line 189, in writeBytes
super(Adafruit_Thermal, self).write(chr(arg))
File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 571, in write
raise SerialException('write failed: {}'.format(e))
SerialException: write failed: [Errno 5] Input/output error

Issues Running

When running

python main.py
or
python calibrate.py
or
python printertest.py

The script never runs, running with -v shows the loading stops at
import io # precompiled from /usr/lib/python2.7/io.pyc
import _io # builtin

Darksky API is no longer available for new users

Hi Adafruit, the DarkSky API that the forecast.py and timetemp.py scripts rely on is no longer available for new users. This will limit the utility of the current guides for the IOT printer and related projects.

Implement experimental DTR handshake

I'm attempting to implement the hardware handshake in #27 based on the arduino printer library. However, I'm having issues getting it to work correctly. Any pointers would be appreciated!

Non ASCII Characters

Hi - I'm using this library to receive SMS text messages and print. Works, well, but I just discovered that any text other than straight ASCII causes an exception.

UnicodeEncodeError: 'ascii' codec can't encode character u'\xc4' in position 14: ordinal not in range(128)

If someone could fix this either to print a print-able like character or just strip anything above 128, that would be wonderful!

Great library!

Update pi-thermal-printer docs

I'm assuming that some folks are coming to this package from Adafruit's pi-thermal-printer documentation.
This package has been updated to use python3

This means that the command to run the test should be python3 printertest.py as written in the Readme here.
But this also means that the package to be installed should be changed to python3-serial meaning that you need to run apt-get install python3-serial to install that package.

Rss

Hello! How to print RSS and instagram feed? Could you give me some input? I had a look to the code but I'm just approaching to python and I don't know from where to start... Thank you!

Support for USB connection?

Hi,

Thanks for the library! I am using a Tiny printer that comes with a USB connection. On a Mac, I can't seem to find the serial connection (e.g. in /dev/) - the device only shows up via USB. Is it possible to initialize a printer object over USB?

Thanks,
Vincent

When trying to run python3 printertest.py I get a termios.error: (25, 'Inappropriate ioctl for device') error

When trying to run python3 printertest.py (on my pi zero w) I get the error:

File "/home/pi/.local/lib/python3.9/site-packages/serial/serialposix.py", line 398, in _reconfigure_port
    orig_attr = termios.tcgetattr(self.fd)
termios.error: (25, 'Inappropriate ioctl for device')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/Python-Thermal-Printer/printertest.py", line 5, in <module>
    printer = Adafruit_Thermal("/dev/usb/lp0", 9600, timeout=5)
  File "/home/pi/Python-Thermal-Printer/Adafruit_Thermal.py", line 84, in __init__
    Serial.__init__(self, *args, **kwargs)
  File "/home/pi/.local/lib/python3.9/site-packages/serial/serialutil.py", line 244, in __init__
    self.open()
  File "/home/pi/.local/lib/python3.9/site-packages/serial/serialposix.py", line 332, in open
    self._reconfigure_port(force_update=True)
  File "/home/pi/.local/lib/python3.9/site-packages/serial/serialposix.py", line 401, in _reconfigure_port
    raise SerialException("Could not configure port: {}".format(msg))
serial.serialutil.SerialException: Could not configure port: (25, 'Inappropriate ioctl for device')

In printertest.py I change the printer setup line to:
printer = Adafruit_Thermal("/dev/usb/lp0", 9600, timeout=5)

This is because I could only get the first test to work with /dev/usb/lp0 and my print test page said it is 9600.

Weird characters

When i run ./printertest.py, i get weird characters printed

img_4225

any ideas why?

Intermittent garbage printed

I'm running this off the raspberry pi adafruit package - Typically the printer runs fine, but once in a while - especially when printing mulitline text, it'll switch and start printing out random characters. The next time I run the print command it resolves itself, but I'm not sure how to debug why it switches into garbage mode?

Add image resize

In printImage() function add image resize
for example:

if width > 384:
            width = 384
            height = int(float(width) / 384 * height)
            image = image.resize((width, height))

Rotating Text Question

How would I go about rotating the orientation of the text? (I want to create a single stream of text that runs length-wise along the paper.) I was looking at the character command masks (in Adafruit_Thermal.py, line 280 - 290) and experimenting with creating a new one with no luck.

cups/cups.h: No such file or directory

Hi! When I try to Make when Installing the printer driver I get this error:

pi@XKCD:~/zj-58 $ make gcc -Wl,-rpath,/usr/lib -Wall -fPIC -O3 -std=gnu89 -c rastertozj.c rastertozj.c:3:10: fatal error: cups/cups.h: No such file or directory 3 | #include <cups/cups.h> | ^~~~~~~~~~~~~ compilation terminated. make: *** [Makefile:16: rastertozj.o] Erro

Any ideas? Thanks

UpsideDownOn

I seem to be unable to get upside down printing working on the thermal printer I have connected to a raspberry pi.

The following:

printer = Adafruit_Thermal.Adafruit_Thermal('/dev/serial0', 19200, timeout=5)
printer.upsideDownOn()
printer.println("hello")

prints in the same manner had I not called upsideDownOn().

Does this feature actually exist? Is this an issue with the inherited pyserial code?

Thanks for the help!

Error running "main.py"

Hi, I am getting the following...

Traceback (most recent call last):
  File "main.py", line 101, in <module>
    printer.printImage(Image.open('gfx/hello.png'), True)
  File "/home/pi/Python-Thermal-Printer/Adafruit_Thermal.py", line 552, in printImage
    image = Image.open(image_file)
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2643, in open
    prefix = fp.read(16)
AttributeError: 'PngImageFile' object has no attribute 'read'

Matt

Instagram or IFTTT support

Hello... Is there a way to add Instagram pictures from hashtag? Or better, is there a way to set up a python script that could receive web hooks from IFTTT Make module? Hope some developers could help me!

ModuleNotFoundError: No module named 'RPi'

So i got everything set up and even the "printertest.py" works perfectly.
But if i try to run
python3 main.py
it fails with the following error message:

Traceback (most recent call last):
  File "main.py", line 18, in <module>
    import RPi.GPIO as GPIO
ModuleNotFoundError: No module named 'RPi'

or
python3 twitter.py
it fails with:

Traceback (most recent call last):
  File "twitter.py", line 30, in <module>
    import base64, HTMLParser, httplib, json, sys, urllib, zlib
ModuleNotFoundError: No module named 'HTMLParser'

If i try to run it with
python main.py
respectively
python twitter.py
it fails with:

Traceback (most recent call last):
  File "twitter.py", line 32, in <module>
    from Adafruit_Thermal import *
  File "/home/pi/Python-Thermal-Printer/Adafruit_Thermal.py", line 725
    def print (self, *args, **kwargs):
            ^


I'm not very into python, but I know it has something to do with the different python versions.
I hope somebody can help me here.

hasPaper crashes

There's an error with the hasPaper call, we consistently get this when we call printer.hasPaper()

Traceback (most recent call last):
  File "vcprint.py", line 27, in <module>
    if(not printer.hasPaper()):
  File "/home/pi/Python-Thermal-Printer/Adafruit_Thermal.py", line 534, in hasPaper
    stat = ord(self.read(1)) & 0b00000100
TypeError: ord() expected a character, but string of length 0 found

Latest versions of Pillow and Python3 printImage fails if given an Image object

Issue:

Inside the Adafruit_Thermal.py file, the printImage function will fail on Python3 and latest Pillow (e.g. a clean Raspbian install) if you pass it an already instantiated PIL Image object instead of a string path as the image_file parameter. This is especially a problem because the sudoku-gfx.py file does exactly that.

Resolution:

We should check whether the parameter is a string or not before calling Image.open. If it is not a string, I think it is fine to assume it is instead an Image.

Issues while running the image print python code on raspberry pi3 (latest stretch raspian lite version)

Hello Experts,

pip3 install pyserial
pip3 install image
python3 sudoku-gfx.py

pi@camera1-rpi3:~/Python-Thermal-Printer $ python3 sudoku-gfx.py 
Traceback (most recent call last):
  File "sudoku-gfx.py", line 29, in <module>
    printer = Adafruit_Thermal("/dev/serial0", 9600, timeout=5)
  File "/home/pi/Python-Thermal-Printer/Adafruit_Thermal.py", line 96, in __init__
    self.wake()
  File "/home/pi/Python-Thermal-Printer/Adafruit_Thermal.py", line 606, in wake
    self.writeBytes(255)
  File "/home/pi/Python-Thermal-Printer/Adafruit_Thermal.py", line 190, in writeBytes
    super(Adafruit_Thermal, self).write(chr(arg))
  File "/home/pi/.local/lib/python3.5/site-packages/serial/serialposix.py", line 532, in write
    d = to_bytes(data)
  File "/home/pi/.local/lib/python3.5/site-packages/serial/serialutil.py", line 63, in to_bytes
    raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))
TypeError: unicode strings are not supported, please encode to bytes: 'ÿ'
pi@camera1-rpi3:~/Python-Thermal-Printer $ 

Getting the above error logs while running the sudoku image based printer example.
Can you please help me to solve the issue ?
Thanks for the help.

SyntaxError - please help -

i reinstalled and updated from this repo.

any suggestions.

thanks.

pi@raspberrypi:~/Python-Thermal-Printer $ python printertest.py
Traceback (most recent call last):
File "printertest.py", line 3, in
from Adafruit_Thermal import *
File "/home/pi/Python-Thermal-Printer/Adafruit_Thermal.py", line 725
def print(self, *args, **kwargs):
^
SyntaxError: invalid syntax

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.