Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days. On MLK Day no orders will be shipped.
0

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/
Please be positive and constructive with your questions and comments.

Internet of Things Printer for Raspberry Pi

by MattPackwood on Fri Nov 19, 2021 10:49 am

Hi,

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

The error I get trying to run:
Code: Select all | TOGGLE FULL SIZE
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

MattPackwood
 
Posts: 74
Joined: Wed Jul 23, 2014 9:13 pm

Re: Internet of Things Printer for Raspberry Pi

by adafruit_support_carter on Fri Nov 19, 2021 4:15 pm

Do you know what version "python" is on your setup? Can find out with:
Code: Select all | TOGGLE FULL SIZE
python --version

adafruit_support_carter
 
Posts: 22282
Joined: Tue Nov 29, 2016 2:45 pm

Re: Internet of Things Printer for Raspberry Pi

by MattPackwood on Fri Nov 19, 2021 4:26 pm

Code: Select all | TOGGLE FULL SIZE
Python 2.7.13

MattPackwood
 
Posts: 74
Joined: Wed Jul 23, 2014 9:13 pm

Re: Internet of Things Printer for Raspberry Pi

by adafruit_support_carter on Fri Nov 19, 2021 4:32 pm

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

adafruit_support_carter
 
Posts: 22282
Joined: Tue Nov 29, 2016 2:45 pm

Re: Internet of Things Printer for Raspberry Pi

by MattPackwood on Sun Nov 21, 2021 9:22 pm

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 | TOGGLE FULL SIZE
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

MattPackwood
 
Posts: 74
Joined: Wed Jul 23, 2014 9:13 pm

Re: Internet of Things Printer for Raspberry Pi

by DeluxCode on Mon Nov 22, 2021 9:52 pm

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!

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

Re: Internet of Things Printer for Raspberry Pi

by DeluxCode on Wed Nov 24, 2021 9:59 am

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 | TOGGLE FULL SIZE
printer.printImage(Image.open('gfx/hello.png'), True)

to
Code: Select all | TOGGLE FULL SIZE
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????)

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

Re: Internet of Things Printer for Raspberry Pi

by MattPackwood on Fri Nov 26, 2021 11:37 am

Now I am "at"....

Code: Select all | TOGGLE FULL SIZE
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 "sudoku-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'

MattPackwood
 
Posts: 74
Joined: Wed Jul 23, 2014 9:13 pm

Re: Internet of Things Printer for Raspberry Pi

by adafruit_support_carter on Mon Nov 29, 2021 2:57 pm

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?

adafruit_support_carter
 
Posts: 22282
Joined: Tue Nov 29, 2016 2:45 pm

Re: Internet of Things Printer for Raspberry Pi

by DeluxCode on Tue Nov 30, 2021 9:55 pm

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!

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

Re: Internet of Things Printer for Raspberry Pi

by MattPackwood on Tue Dec 14, 2021 7:08 pm

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

MattPackwood
 
Posts: 74
Joined: Wed Jul 23, 2014 9:13 pm

Re: Internet of Things Printer for Raspberry Pi

by DeluxCode on Sun Dec 19, 2021 8:35 am

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.

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

Re: Internet of Things Printer for Raspberry Pi

by MattPackwood on Sun Dec 19, 2021 12:41 pm

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

MattPackwood
 
Posts: 74
Joined: Wed Jul 23, 2014 9:13 pm

Re: Internet of Things Printer for Raspberry Pi

by MattPackwood on Tue Dec 21, 2021 1:12 pm

Or you could send me the files...

My google email address is mattpackwood@google.com

Matt

MattPackwood
 
Posts: 74
Joined: Wed Jul 23, 2014 9:13 pm

Re: Internet of Things Printer for Raspberry Pi

by rcb on Thu Dec 30, 2021 1:02 pm

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.
rcb
 
Posts: 25
Joined: Sun Sep 15, 2013 6:25 pm

Please be positive and constructive with your questions and comments.