adafruit / Adafruit_CircuitPython_Thermal_Printer

CircuitPython module for interacting with serial thermal printers.
MIT License
21 stars 16 forks source link

add ability to print image #16

Open willingham opened 4 years ago

willingham commented 4 years ago

In the prior Python-Thermal-Printer library, there was such a method. https://github.com/adafruit/Python-Thermal-Printer/blob/4ede517529839e0685e632ce3385773852d99df6/Adafruit_Thermal.py#L552

It depends on the _print_bitmap method, which comments say it does not work in this library, so that may need to be a separate issue.

evaherrada commented 4 years ago

I'll try to do this. Doesn't seem super difficult, although I have heard the thermal printer library can be finicky at times.

greg-elmi commented 4 years ago

Currently on my branch testy I have a working draft of implementation that works on 2.168 firmware. According to user manual version 2.68 uses same command for printing so is should be compatible.

https://github.com/greg-elmi/Adafruit_CircuitPython_Thermal_Printer/blob/testy/adafruit_thermal_printer/thermal_printer_2168.py

Minimal test of this method is in file test_print.py

Any suggestions for improvement are welcome. I plan to send pull request sometime in coming 3 weeks I got some time today to format it a little better so I `ve just sent the request

Domanaik commented 2 years ago

Hello, i got a Thermal printer from Adafruit, System A2, Version GV2.19.08 How can i use it, to print bitmap on raspberry pi ?

ladyada commented 2 years ago

you could try https://learn.adafruit.com/networked-thermal-printer-using-cups-and-raspberry-pi

Domanaik commented 2 years ago

This guide currently does not work with TTL thermal printers with the latest firmware (System:A2 Version: GV2.*), i got GV2.19.08

zapa1928 commented 2 years ago

Hello, i got a Thermal printer from Adafruit, System A2, Version GV2.19.08 How can i use it, to print bitmap on raspberry pi ?

Try my fork and start from file https://github.com/greg-elmi/Adafruit_CircuitPython_Thermal_Printer/blob/testy/adafruit_thermal_printer/test_print.py

Bare in mind that this was written on Windows but it also worked on raspberry pi with different paths and with tty(something) instead of COM

Domanaik commented 2 years ago

I forked it and runned the test_print.py (i Changed serial to /dev/serial0 and also Changed the path)

Its starting printing. But the Script Just Stop and doint nothing. The printer printed the following

IMG_20211210_195304.jpg

If i cancel via Ctrl+c IT Shows the following Error:

pi@raspberrypi4:~/Adafruit_CircuitPython_Thermal_Printer/adafruit_thermal_printer $ python3 test_print.py ^CTraceback (most recent call last): File "test_print.py", line 17, in <module> printer.print_bitmap("/var/www/html/data/images/20211207_211826.jpg") File "/home/pi/Adafruit_CircuitPython_Thermal_Printer/adafruit_thermal_printer/thermal_printer_2168.py", line 112, in print_bitmap bitmap = list(map(lambda x: 0.333*x[0]+0.333*x[1]+0.333*x[2], zip(r, g, b))) File "/home/pi/Adafruit_CircuitPython_Thermal_Printer/adafruit_thermal_printer/thermal_printer_2168.py", line 112, in <lambda> bitmap = list(map(lambda x: 0.333*x[0]+0.333*x[1]+0.333*x[2], zip(r, g, b))) KeyboardInterrupt

I know, that i dont have firmware 2.16.8 but, there is no update for 2.19.08

zapa1928 commented 2 years ago

@Domanaik

You can only print bitmaps (I only tested it on bitmaps). So convert your file to bmp format. And it should be ok

That what you printed is my bmp file (elmi2.bmp) so it works.

Domanaik commented 2 years ago

@zapa1928 i did some Testing.

If i Print elmi.bmp its working. With elmi2.bmp it looks strange (top is elmi, bottom is elmi2). with the second half its not lining up properly?

IMG_20211211_132339.jpg

Also, With elmi2 the script never ends. I have to stop it with Ctrl+C, this is the output again pi@raspberrypi4:~/test_print $ python3 test_print.py ^CTraceback (most recent call last): File "test_print.py", line 19, in <module> printer.print_bitmap("elmi2.bmp") File "/home/pi/test_print/adafruit_thermal_printer/thermal_printer_2168.py", line 133, in print_bitmap self._print_horizontal(mode, img_LX, img_HX, img_LY, img_HY, datas) File "/home/pi/test_print/adafruit_thermal_printer/thermal_printer_2168.py", line 146, in _print_horizontal self._uart.write(d) File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 556, in write abort, ready, _ = select.select([self.pipe_abort_write_r], [self.fd], [], None) KeyboardInterrupt So I guess this is a size problem of the bmp?

Any suggestions?

zapa1928 commented 2 years ago

@Domanaik Try checking out master branch, because the link I provided sends to my testing branch and some things may not work. In the picture above it is something size of bitmap related problem but I think I didn't have this kind of problem.

Check if script ends if you won't print bitmap at all. Do just paper check.

Edited: I presume when you print elmi.bmp script ends normally. If that's the case disregard the above check, It won't solve anything.

Domanaik commented 2 years ago

@zapa1928 yes elmi prints normally and Script ends.. So it has to do Something With the newer firmware?

Sad :(