Skip to content
This repository was archived by the owner on May 16, 2023. It is now read-only.

Add ability to print bitmaps #21

Closed
wants to merge 6 commits into from
Closed

Conversation

greg-elmi
Copy link
Contributor

@greg-elmi greg-elmi commented Sep 17, 2020

Works at firmware 2.168. Should work on 2.68 but all the new methods are contained in thermal_printer_2168.py file.

I tested only on printing bitmaps so setting timeouts for communication was irrelevant but if it will be I'll fix it

Potentially closes #16

@greg-elmi
Copy link
Contributor Author

I'll have time to get back to this on Monday

@tannewt
Copy link
Member

tannewt commented Sep 17, 2020

@dherrada Do you have a printer you can test with?

@evaherrada
Copy link
Collaborator

evaherrada commented Sep 18, 2020

@tannewt yep. I can test this Monday or Tuesday if that’s soon enough

@tannewt
Copy link
Member

tannewt commented Sep 18, 2020

@dherrada That'd be great! Thanks!

@greg-elmi
Copy link
Contributor Author

Do you have an idea how to require installation of numpy, imageio and math but only in case you are using bitmap printing?
And how to do that in an elegant way? I think importing those modules in print_bitmap() is ugly. But importing them for the whole thermal_printer_2168.py is an overkill. And on the same principle adding them to requirements.txt just as new positions (without some conditional dependency chain) is very strict for people that don't want to print bitmaps.

Any ideas?

@tannewt
Copy link
Member

tannewt commented Sep 21, 2020

@greg-elmi What about a separate library? That will allow you to split requirements and imports. If you just want to split imports, you could create a separate module. It could take in the basic thermal printer object.

@greg-elmi
Copy link
Contributor Author

@tannewt For now I'll just add new positions to requirements.txt. I'll think about better separation in future pull requests

@tannewt
Copy link
Member

tannewt commented Sep 23, 2020

@dherrada Have you tested this yet?

@evaherrada
Copy link
Collaborator

evaherrada commented Sep 24, 2020

@tannewt Nope, I've been pretty busy with school this week, so I haven't really had a chance to. I will possibly have some time tonight to test, but if I don't, I'll definitely test tomorrow. Sorry for the delay.

@evaherrada
Copy link
Collaborator

@greg-elmi Is there any way you could make this not use imageio and numpy? The reason for that is that (to my knowledge) they are not available for circuitpython, so we wouldn't be able to use them with CircuitPython boards.

@evaherrada evaherrada self-requested a review September 25, 2020 17:13
@evaherrada
Copy link
Collaborator

@greg-elmi aside from that, this is actually really good. I know there are ways of doing all the stuff that you used imageio and numpy for in circuitpython, although it probably won't be as clean.

@greg-elmi
Copy link
Contributor Author

Is there any way you could make this not use imageio and numpy?

@dherrada I don't know. I haven't used circuitpython. I'll read about it and try.
Did you started working on something and have anything i could base on (I saw your comment in issue #16 but couldn't find on your profile any public repository regarding the subject)?

@evaherrada
Copy link
Collaborator

@greg-elmi Yeah, I never really got to it.

@greg-elmi
Copy link
Contributor Author

Right now I am doing other project but I'll sit to it when I'll finish it (don't hold your breath)

@kattni
Copy link
Contributor

kattni commented Jan 6, 2021

@dherrada Have you had a chance to take a look at this?

@evaherrada
Copy link
Collaborator

@kattni If by take a look at it you mean test it, then yes. I tested it on the Pi and it worked. I didn't test it on a CircuitPython board since it uses libraries not available for CircuitPython. If you mean to try to adapt it to work with CircuitPython as well, then no.

@jposada202020
Copy link

Proposal

  1. We could use this as an example, that way folks could still use this
  2. @kmatch98 do you think there is any way that we could translate this code to CircuitPython? I think is feasible but you are more familiar dealing with bitmaps.
    Thanks.

@kmatch98
Copy link

The file thermal_printer_2168.py uses some libraries that are currently not available in circuitpython. Here is the closest CircuitPython libraries that could be used in their place. However, it will take updates to the code to make it work.

imageio - could use imageload in CircuitPython
numpy - could use ulab in CircuitPython

The CircuitPython libraries don't exactly match the currently imported libraries. I took a quick look at it, the main work is in the print_bitmap function. I suspect that it is possible to convert to using bitmaps in CircuitPython. Seems like folks with a printer would want to print bitmaps. Need to find someone with the hardware that is interested in making the update.

@jposada202020
Copy link

@kattni
I guess only easy path is to add this an example for the time being, thoughts?

@jposada202020
Copy link

@greg-elmi Thanks again for your contribution. After a deeper reflecting on this:

  1. As it is, this PR will imply porting some functionalities to be compatible with CircuitPython. I am not sure that this is in the scope of this PR.
  2. The code included is very distant that methods currently used in our libraries. please see the following guide.
    https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html
    and if some libraries code examples.
    https://github.com/adafruit/Adafruit_CircuitPython_MCP9808
    https://github.com/adafruit/Adafruit_CircuitPython_SHT4x
    https://github.com/adafruit/Adafruit_CircuitPython_ADT7410/blob/master/adafruit_adt7410.py
    Our main goal is to have some standardization on the libraries to facilitate maintainability. So to include this as an example code will need some refactoring done.

Let me know your thoughts. Thanks again.

@greg-elmi
Copy link
Contributor Author

@jposada202020 Feel free to do with this PR whatever you want. I don't think I'll have time to conform with your design rules as we moved on with our project and this portion of code is already approved (We are not planing to work on it any time soon).
(So I won't give you false hope I'll finish this. Maybe I'll do but in private time or when we'll get back to it for optimization but I doubt it).

As I understand It wont work on CircuitPython boards because of the bloated libraries (numpy and imageio). So in this form I suppose you should close the pull request. But I think it should be visible for people like me who use CircuitPython on Raspberry Pi and don't care.

For people working on CircuitPython boards I suggest for now such workaround (I didn't test it):

Modify on a PC. print_bitmap method in such way so it wont call
self._print_horizontal(mode, img_lx, img_hx, img_ly, img_hy, data)

but instead it will pickle (mode, img_lx, img_hx, img_ly, img_hy, data)

then you can transfer result files on a board and use _print_horizontal directly with upickled data.

@jposada202020
Copy link

Thanks will do :)

@jposada202020
Copy link

I will close this for now, you have a good point for the visibility if someone could work in getting the code according to the standard, that could be in an example or in the community bundle.

@Domanaik
Copy link

Domanaik commented Dec 7, 2021

@jposada202020 Feel free to do with this PR whatever you want. I don't think I'll have time to conform with your design rules as we moved on with our project and this portion of code is already approved (We are not planing to work on it any time soon). (So I won't give you false hope I'll finish this. Maybe I'll do but in private time or when we'll get back to it for optimization but I doubt it).

As I understand It wont work on CircuitPython boards because of the bloated libraries (numpy and imageio). So in this form I suppose you should close the pull request. But I think it should be visible for people like me who use CircuitPython on Raspberry Pi and don't care.

For people working on CircuitPython boards I suggest for now such workaround (I didn't test it):

Modify on a PC. print_bitmap method in such way so it wont call self._print_horizontal(mode, img_lx, img_hx, img_ly, img_hy, data)

but instead it will pickle (mode, img_lx, img_hx, img_ly, img_hy, data)

then you can transfer result files on a board and use _print_horizontal directly with upickled data.

Hello @greg-elmi

I am a raspberry pi user to with a new Adafruit Thermal Printer. A2, GV2.19.08
How can i use it, so i can print bitmaps? Can you help me?

Thanks
Dominique

@evaherrada
Copy link
Collaborator

@Domanaik Yeah so you're going to want to clone https://github.com/greg-elmi/Adafruit_CircuitPython_Thermal_Printer and then run the example @greg-elmi created

@Domanaik
Copy link

Domanaik commented Dec 8, 2021

@Domanaik Yeah so you're going to want to clone https://github.com/greg-elmi/Adafruit_CircuitPython_Thermal_Printer and then run the example @greg-elmi created

Hello @dherrada

Thanks for helping me. Im sorry, im kinda new to python.. I only working with C# and PowerShell ;(

I cloned it. The example is running, but in the example the part with print_bitmap is missing. Sadly i dont know how to import the new file.
I changed the example, so I load firmware 2.168. (I dont know what my printer has, on the testpage i see GV2.19.08, that seems very old compared to 2.64, 2.68 or 2.168.. I just bought the printer from adafruit).
I tried running
printer.print_bitmap("/var/www/html/data/images/20211207_211826.jpg")
but it tells me 'AttributeError: 'ThermalPrinter' object has no attribute 'print_bitmap''
What am i doing wrong? :(

@evaherrada
Copy link
Collaborator

@Domanaik I think you need to make sure that the adafruit version of thermal printer isn't installed. I think you're going to want to uninstall it with pip/pip3 and then run the example from the top-level directory of greg-elmi:master

@zapa1928
Copy link

zapa1928 commented Dec 10, 2021

@Domanaik

on the testpage i see GV2.19.08

That in fact states you have newer firmware than 2.168 as 2.168 is 2.16.08, which i worked with
And I only presume that 2.64 was 2.6.04, and 2.68 was 2.6.08 (I didn't have them on my bench so it's only a guess).

@tekktrik tekktrik self-assigned this Jan 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add ability to print image
9 participants