Willpiam
Posts: 27
Joined: Thu Feb 26, 2015 11:16 pm

Thermal printer trouble

Thu Nov 24, 2016 2:05 am

Hi I'm trying to make an instant camera out of a raspberry pi 3, a USB thermal printer, the raspberry pi camera, and a driver program (Excuse me if I'm using the term driver incorrectly) from adafruit called Adafruit_Thermal.py.

My problem is that when I try to run my program (actually at the moment just a standard program that came with the adafruit package called sudoku-gfx.py) it prints about half a line then stops. I'm using a USB thermal printer. Part of the setup was to tell the program to use a file called /dev/ttyUSB0. When the printer is connected to power this file can be found. When it's not this file does not exist. What's interesting is after I run this program, and I get my error message, if I go to find that file it will have been replaced by /dev/ttyUSB1.

Something else that was strange is yeasterday I had fixed this problem by changing the 'default port' to /dev/ttyUSB0 in the Adafruit_Thermal.py program. Strangely it seems I had only fixed my issue temporarily. The code was working fine yesterday but for some reason today it no longer works.

The error message looks like this:

Traceback (most recent call last): File "/home/pi/Documents/Python-Thermal-Printer-master/sudoku-gfx.py", line 237, in <module> main() File "/home/pi/Documents/Python-Thermal-Printer-master/sudoku-gfx.py", line 46, in main printer.printImage(bg, True) # This does the printing File "/home/pi/Documents/Python-Thermal-Printer-master/Adafruit_Thermal.py", line 489, in printImage self.printBitmap(width, height, bitmap, LaaT) File "/home/pi/Documents/Python-Thermal-Printer-master/Adafruit_Thermal.py", line 442, in printBitmap self.writeBytes(18, 42, chunkHeight, rowBytesClipped) File "/home/pi/Documents/Python-Thermal-Printer-master/Adafruit_Thermal.py", line 173, in writeBytes super(Adafruit_Thermal, self).write(chr(arg)) File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 489, in write raise SerialException('write failed: %s' % (v,)) SerialException: write failed: [Errno 19] No such device

The driver program I'm using can be found here:
https://github.com/adafruit/Python-Thermal-Printer

If you can help in anyway or even simply recommend a better way of doing this please let me know. Thanks you.

User avatar
DougieLawson
Posts: 39126
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Thermal printer trouble

Thu Nov 24, 2016 6:26 am

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Willpiam
Posts: 27
Joined: Thu Feb 26, 2015 11:16 pm

Re: Thermal printer trouble

Fri Nov 25, 2016 9:18 pm

DougieLawson wrote:Try using Stewart Russell's stuff
http://scruss.com/blog/2015/07/12/therm ... -pi-zj-58/
I have already tried this and had a different set of issues. However I think the underlying issue could have been the same as what I'm experiencing now. The problem I was having with that process was that when I went to print something the print wouldn't go through. Yes I was able to get the first few prints to work but nothing worked after a while.

User avatar
scruss
Posts: 3218
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Thermal printer trouble

Sat Nov 26, 2016 12:26 am

Do you have another USB serial device attached? The serial interface shouldn't change from 0 to 1 unless something is in contention with the original port.

At times like this, the /dev/serial aliases - which map devices by path and id - can be useful. There can be problems if you have identical counterfeit "FTDI" adapters, but usually you can pick a device in /dev/serial and it will stay unchanged
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

Willpiam
Posts: 27
Joined: Thu Feb 26, 2015 11:16 pm

Re: Thermal printer trouble

Sat Nov 26, 2016 1:47 am

scruss wrote:Do you have another USB serial device attached? The serial interface shouldn't change from 0 to 1 unless something is in contention with the original port.

At times like this, the /dev/serial aliases - which map devices by path and id - can be useful. There can be problems if you have identical counterfeit "FTDI" adapters, but usually you can pick a device in /dev/serial and it will stay unchanged
I have a wired keyboard, USB Bluetooth mouse, and the raspberry pi camera attached in addition to the printer. I'll look into this.

User avatar
scruss
Posts: 3218
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Thermal printer trouble

Sat Nov 26, 2016 3:54 pm

It's likely not the serial address problem I mentioned, then. You don't have other USB serial devices attached.

I've found that CUPS just sometimes decides that these printers have disconnected, and not much short of a reboot with the printer attached and powered on will make it change its mind. This isn't a satisfactory situation, I realize, but getting to the root of CUPS problems takes time and patience. Alternatively, drive the printer directly without involving CUPS. CUPS doesn't really understand roll-fed printers very well.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

Willpiam
Posts: 27
Joined: Thu Feb 26, 2015 11:16 pm

Re: Thermal printer trouble

Mon Nov 28, 2016 12:22 am

scruss wrote:It's likely not the serial address problem I mentioned, then. You don't have other USB serial devices attached.

I've found that CUPS just sometimes decides that these printers have disconnected, and not much short of a reboot with the printer attached and powered on will make it change its mind. This isn't a satisfactory situation, I realize, but getting to the root of CUPS problems takes time and patience. Alternatively, drive the printer directly without involving CUPS. CUPS doesn't really understand roll-fed printers very well.

I uninstalled cups and that didn't really change much. I then enabled the serial interface and rebooted. It worked! I was able to print the sudoku image. However I then tried disabling the serial interface to see if it was actually the serial interface that mattered and it still worked (yes I rebooted). Strange right?

It seems when I change anything about the Pi the printer will work but only for a day or so. It will be working one day and the next it won't. It's feels like changing things on the Pi makes it work but it's not the change that matters it's the simple fact that something, anything, is different. It's a very curious problem.

The way I can think to have this fixed pernimently is to change whether or not the serial interface is enabled, automatically every time the Pi is turned off. I'm not sure if this is posable but I'll look into it.

I'd very much like to understand what's causing this issue because it's so strange to me.
Thanks for your help so far. And I'm still open to ideas :)

Return to “Other projects”