Internet of Things Printer for Raspberry Pi

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
User avatar
MattPackwood
 
Posts: 95
Joined: Wed Jul 23, 2014 9:13 pm

Internet of Things Printer for Raspberry Pi

Post by MattPackwood »

Hi,

I am trying to rebuild a unit, I am running "stretch"

The error I get trying to run:

Code: Select all

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

Matt

User avatar
adafruit_support_carter
 
Posts: 29167
Joined: Tue Nov 29, 2016 2:45 pm

Re: Internet of Things Printer for Raspberry Pi

Post by adafruit_support_carter »

Do you know what version "python" is on your setup? Can find out with:

Code: Select all

python --version

User avatar
MattPackwood
 
Posts: 95
Joined: Wed Jul 23, 2014 9:13 pm

Re: Internet of Things Printer for Raspberry Pi

Post by MattPackwood »

Code: Select all

Python 2.7.13

User avatar
adafruit_support_carter
 
Posts: 29167
Joined: Tue Nov 29, 2016 2:45 pm

Re: Internet of Things Printer for Raspberry Pi

Post by adafruit_support_carter »

That's probably the issue. The library is now Python 3.
https://github.com/adafruit/Python-Ther ... /README.md

User avatar
MattPackwood
 
Posts: 95
Joined: Wed Jul 23, 2014 9:13 pm

Re: Internet of Things Printer for Raspberry Pi

Post by MattPackwood »

Hi,

That got me a lot closer, I put an issue in the repository as well:

I am getting the following when I run

Code: Select all

main.py

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

User avatar
DeluxCode
 
Posts: 9
Joined: Sun Nov 14, 2021 10:07 am

Re: Internet of Things Printer for Raspberry Pi

Post by DeluxCode »

Hello,

We are getting the exact same error from main.py - so looking forward to some help.

We noticed that in the new cloned version of main.py referenced above, all the internal calls are still to python and not python3. We tried updating those, but it doesn't get rid of this error.

Thanks!

User avatar
DeluxCode
 
Posts: 9
Joined: Sun Nov 14, 2021 10:07 am

Re: Internet of Things Printer for Raspberry Pi

Post by DeluxCode »

Figured out the problem for the printer.printImage line...

Turns out that the function printImage calls an Image.open on the input which expects a string, not the output of Image.open.

So if you change

Code: Select all

printer.printImage(Image.open('gfx/hello.png'), True)
to

Code: Select all

printer.printImage('gfx/hello.png', True)
in main.py, it will work. Note that this mistake also exists for a few other images in main.py, so you need to fix those too.

Now on to the next problems... can't use forecast.py as written because DarkSky is being shut down and we get some error messages from the number puzzle code (can't enter name as the forum says it is a banned word????)

User avatar
MattPackwood
 
Posts: 95
Joined: Wed Jul 23, 2014 9:13 pm

Re: Internet of Things Printer for Raspberry Pi

Post by MattPackwood »

Now I am "at"....

Code: Select all

pi@iotp:~/Python-Thermal-Printer $ sudo python3 main.py 
Traceback (most recent call last):
  File "forecast.py", line 17, in <module>
    from Adafruit_Thermal import *
  File "/home/pi/Python-Thermal-Printer/Adafruit_Thermal.py", line 725
    def print(self, *args, **kwargs):
            ^
SyntaxError: invalid syntax
Traceback (most recent call last):
  File "BANNED-gfx.py", line 25, in <module>
    from Adafruit_Thermal import *
  File "/home/pi/Python-Thermal-Printer/Adafruit_Thermal.py", line 725
    def print(self, *args, **kwargs):
            ^
SyntaxError: invalid syntax
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):
            ^
SyntaxError: invalid syntax
Traceback (most recent call last):
  File "main.py", line 166, in <module>
    lastId = result.rstrip('\r\n')
TypeError: a bytes-like object is required, not 'str'

User avatar
adafruit_support_carter
 
Posts: 29167
Joined: Tue Nov 29, 2016 2:45 pm

Re: Internet of Things Printer for Raspberry Pi

Post by adafruit_support_carter »

What are the constraints of your current application? Are you required to stick with buster and Python 2? Or could you update your setup to latest OS release and Python 3?

User avatar
DeluxCode
 
Posts: 9
Joined: Sun Nov 14, 2021 10:07 am

Re: Internet of Things Printer for Raspberry Pi

Post by DeluxCode »

We finally got everything to work. Here is the steps it took...

1) Switched to python3. We updated some of the libraries from python versions to python3 versions in the 'sudo apt-get install' step. Not sure if this was necessary or not. We also edited main.py to use python3 for all the subprocess calls.
2) Edited Adafruit_thermal.py to update the function printImage. For this we commented out the line that said image = Image.open(image_file) and added a line that said image=image_file. The original line generates an error because an open image has already been passed in as the input to the overall function and not jus a text string for the file name (this is true in calls from both main.py and the number puzzle python code - sorry can't type it in directly because the forum is saying the word is banned).
3) Wrote our own forecast.py to get a weather report from the National Weather Service. Obviously, this won't work for outside the US, but DarkSky is being shutdown and we needed an alternative.

Hope this helps!

User avatar
MattPackwood
 
Posts: 95
Joined: Wed Jul 23, 2014 9:13 pm

Re: Internet of Things Printer for Raspberry Pi

Post by MattPackwood »

Any chance you have sour code somewhere I can steal (I mean borrow) it from?

User avatar
DeluxCode
 
Posts: 9
Joined: Sun Nov 14, 2021 10:07 am

Re: Internet of Things Printer for Raspberry Pi

Post by DeluxCode »

We don't have it posted anywhere yet, but would be happy too. Is there a central place we can load up the code? Seems it would be good for others trying to follow in the instructions in the future too.

User avatar
MattPackwood
 
Posts: 95
Joined: Wed Jul 23, 2014 9:13 pm

Re: Internet of Things Printer for Raspberry Pi

Post by MattPackwood »

You could post it to GitHub, either under your own repository or suggest / do a pull request for the code in the Adafruit repository?

User avatar
MattPackwood
 
Posts: 95
Joined: Wed Jul 23, 2014 9:13 pm

Re: Internet of Things Printer for Raspberry Pi

Post by MattPackwood »

Or you could send me the files...

My google email address is [email protected]

Matt

rcb
 
Posts: 25
Joined: Sun Sep 15, 2013 6:25 pm

Re: Internet of Things Printer for Raspberry Pi

Post by rcb »

I second the motion. It would be useful for others to update the GitHub so that the software for the printer is up-to-date and works with the printer kit Adafruit currently sells. Adafruit should make it easy for for DeluxCode to post the required update.

Locked
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”