Hi. I am a complete beginner, so apologies. (First post ever).
Trying to build the instant camera project (https://learn.adafruit.com/instant-came ... al-printer) with Raspberry Pi 3 Model B, Raspberry Pi Camera Board v2 and Adafruit USB thermal printer (zj-58).
Lots of head scratching, but managed to get printer to print camera image using a command like this:
raspistill -n -t 200 -w 512 -h 384 -o - | lp
The first image print is great, but every one after that prints a page of garbage before actually printing the image. This continues until I power cycle the printer and then the first one after power cycle is clean (subsequent ones have garbage before the image). See attached picture. (Same thing happens if I try to print a saved image on my Pi).
When I print text from text editor or command line, there’s no initial garbage (just the text I entered prints).
I’ve read that it may be a baud issue (my printer is 9600 baud, version S1.06), but also read that there isn’t a way to adjust the baud if it’s USB connected.
The Device URI is usb://Unknown/Printer?serial=[then a long string of letters and numbers]
Does anyone have any ideas on how to avoid the initial garbage? Is there a command to flush the print buffer or reset the printer in some way before every print? Keep in mind I’m mostly limited to copying other people’s projects and the instant camera one uses a bash script to perform the instant camera project, so if there are command lines I can use before the raspistill command, that would be great.
Of course any other ideas are welcome! Thanks!
USB thermal printer outputting garbage before printing the image
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- camichaels
- Posts: 17
- Joined: Sat Sep 24, 2022 10:25 pm
- mikeysklar
- Posts: 16573
- Joined: Mon Aug 01, 2016 8:10 pm
Re: USB thermal printer outputting garbage before printing the image
Nice quality print.
The garbage output looks like a baud rate mismatch as you mentioned.
There are instructions in the guide for setting the baudrate.
When you printed a test page (button on printer) you should see the baudrate at the bottom. I suspect yours is 19200 and not 9600.
https://learn.adafruit.com/instant-came ... re-1894085
The garbage output looks like a baud rate mismatch as you mentioned.
There are instructions in the guide for setting the baudrate.
When you printed a test page (button on printer) you should see the baudrate at the bottom. I suspect yours is 19200 and not 9600.
Look for the baud rate that’s printed near the bottom of the page. This is typically either 9600 or 19200 baud. This is important…you’ll need to know the correct value for your printer.
On the first line, change the “baud” value to 9600 or 19200 as required for your printer.
Code: Select all
sudo lpadmin -p ZJ-58 -E -v serial:/dev/ttyUSB0?baud=19200 -m zjiang/ZJ-58.ppd
sudo lpoptions -d ZJ-58
- camichaels
- Posts: 17
- Joined: Sat Sep 24, 2022 10:25 pm
Re: USB thermal printer outputting garbage before printing the image
Thanks for such a quick response. I saw those commands in the instructions and followed them to start, but that didn't allow me to print earlier. Back then and just now... when I reentered the commands you suggested, I could not print at all. The job queues, but when I look at the print attributes it says
Unable to open serial port: No such file or directory
And I could not figure out why.
I initially got around this issue by adding another USB printer in the Print Setting GUI and using zj-58 drivers. When I then outputted to that printer, I didn't get stuck in the print queue. But got garbage.
I feel like I'm in an endless loop. When I follow the directions/commands, I cannot print at all. When I add printer manually through Print Settings, I get the garbage headers.
Attached are some hopefully relevant screens.
The "error" image is what the job attributes looks like when I use the command lines to create printer "zj-58".
The "garbage" image is when I use the GUI to add thermal printer "thermal" which prints.
I do see the error screenshot tries to make image a PDF-banner, but the ones that prints shows it as image/jpeg. I ran same command line for both jobs (taking camera image and printing it).
Any clue why I get the "Unable to open serial port" for zj-58 (does document-format-detected offer a clue, like I need to run some type of filter to map camera to jpg?)?
Thanks!
When I use command lines like you suggested. Cannot print...
When I use GUI to add USB printer. Garbage (and likely baud mismatch)...
Unable to open serial port: No such file or directory
And I could not figure out why.
I initially got around this issue by adding another USB printer in the Print Setting GUI and using zj-58 drivers. When I then outputted to that printer, I didn't get stuck in the print queue. But got garbage.
I feel like I'm in an endless loop. When I follow the directions/commands, I cannot print at all. When I add printer manually through Print Settings, I get the garbage headers.
Attached are some hopefully relevant screens.
The "error" image is what the job attributes looks like when I use the command lines to create printer "zj-58".
The "garbage" image is when I use the GUI to add thermal printer "thermal" which prints.
I do see the error screenshot tries to make image a PDF-banner, but the ones that prints shows it as image/jpeg. I ran same command line for both jobs (taking camera image and printing it).
Any clue why I get the "Unable to open serial port" for zj-58 (does document-format-detected offer a clue, like I need to run some type of filter to map camera to jpg?)?
Thanks!
When I use command lines like you suggested. Cannot print...
When I use GUI to add USB printer. Garbage (and likely baud mismatch)...
- mikeysklar
- Posts: 16573
- Joined: Mon Aug 01, 2016 8:10 pm
Re: USB thermal printer outputting garbage before printing the image
You are still setting the baudrate to 9600 via command-line. You need to try the syntax I provided above for 19200 and confirm that baudrate on the printer with a manual test page button press.
The cups installation does have config files under /etc/cups/cupsd.conf you could confirm the baudrate in.
The cups installation does have config files under /etc/cups/cupsd.conf you could confirm the baudrate in.
- camichaels
- Posts: 17
- Joined: Sat Sep 24, 2022 10:25 pm
Re: USB thermal printer outputting garbage before printing the image
Thanks for continuing to look/help.
To be clear, my thermal printer's test page shows 9600 baud.
Are you recommending I change that to 19200 to help with garbage situation? Or did you misread my initial post and thought my printer was NOT 9600?
Will look at cupsd.conf file shortly (darn day job :-).
To be clear, my thermal printer's test page shows 9600 baud.
Are you recommending I change that to 19200 to help with garbage situation? Or did you misread my initial post and thought my printer was NOT 9600?
Will look at cupsd.conf file shortly (darn day job :-).
- mikeysklar
- Posts: 16573
- Joined: Mon Aug 01, 2016 8:10 pm
Re: USB thermal printer outputting garbage before printing the image
I went back and see you mentioned your printer was 9600 baud. I'm used to seeing a photo of the print settings to verify.
There are two things you can try:
1) USB printer mode - I know you have a "tiny" thermal printer, but this might still apply. There are two modes on the mini you can adjust with hodling the self-test + feed buttons.
https://learn.adafruit.com/mini-thermal ... aq-3023793
2) lp and lpr and both setup with cups:
Does this change the behavior to get a second print without garbage chars?
some additional arguments which might help like '-o raw'
https://www.raspberry-pi-geek.com/Archi ... sy-of-CUPS
There are two things you can try:
1) USB printer mode - I know you have a "tiny" thermal printer, but this might still apply. There are two modes on the mini you can adjust with hodling the self-test + feed buttons.
https://learn.adafruit.com/mini-thermal ... aq-3023793
2) lp and lpr and both setup with cups:
Does this change the behavior to get a second print without garbage chars?
Code: Select all
raspistill -n -t 200 -w 512 -h 384 -o - | lpr -o fit-to-page
https://www.raspberry-pi-geek.com/Archi ... sy-of-CUPS
- camichaels
- Posts: 17
- Joined: Sat Sep 24, 2022 10:25 pm
Re: USB thermal printer outputting garbage before printing the image
Mike - thanks for really digging in and providing a ton of solutions to try. I don't know if the printer isn't recent (although I just bought it), but it didn't have 2 buttons, so I couldn't change modes. And the ... fit-to-print almost worked (after a few prints, the printer went back to starting with garbage).
As a newbie, I thought USB was the easiest path. But luckily the printer had pins, so for "fun" I connected directly to GPIO pins and added a new Serial printer with 9600 baud. While the printer is much slower now, it seems like it cleared up the garbage. Again, thanks!
(now I have an issue where the camera doesn't seem to be available with each button press, but I'll bring that question up in a new post)
As a newbie, I thought USB was the easiest path. But luckily the printer had pins, so for "fun" I connected directly to GPIO pins and added a new Serial printer with 9600 baud. While the printer is much slower now, it seems like it cleared up the garbage. Again, thanks!
(now I have an issue where the camera doesn't seem to be available with each button press, but I'll bring that question up in a new post)
- mikeysklar
- Posts: 16573
- Joined: Mon Aug 01, 2016 8:10 pm
Re: USB thermal printer outputting garbage before printing the image
Glad to hear you found a working solution with direct serial. I was hopeful we could clean up the occasional garbage with some more refinement.
Please be positive and constructive with your questions and comments.