![]() |
python script for gfx hat (LCD for raspberry) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: python script for gfx hat (LCD for raspberry) (/thread-19462.html) Pages:
1
2
|
python script for gfx hat (LCD for raspberry) - domoticity - Jun-30-2019 Hy, i have bought a LCD for my beautifull Pi :) My LCD is the GFX hat : https://shop.pimoroni.com/products/gfx-hat There is an Example for script python but i don't understand, i am a very very very rookie in Python Scripts. what i am looking for with my lcd : Below the screen : display text like "Hello", "name", etc... Top the screen : display Pictogram wich are in this folder "/diagbox/pictures" for example : When the Pi starts, switch on the LCD and display "Hello, boot in progress" After, when the wlan0 and eth0 are up, display a pictogramm for the eth0 and for the wlan0 And leave the screen on, as long as the pi is on. Thank by Advance Thereafter the script give with the Equipment : #!/usr/bin/env python import time import signal from gfxhat import touch, lcd, backlight, fonts from PIL import Image, ImageFont, ImageDraw print("""hello-world.py This basic example prints the text "Hello World" in the middle of the LCD Press any button to see its corresponding LED toggle on/off. Press Ctrl+C to exit. """) led_states = [False for _ in range(6)] width, height = lcd.dimensions() image = Image.new('P', (width, height)) draw = ImageDraw.Draw(image) font = ImageFont.truetype(fonts.AmaticSCBold, 38) text = "Hola gringo" w, h = font.getsize(text) x = (width - w) // 2 y = (height - h) // 2 draw.text((x, y), text, 1, font) def handler(ch, event): if event == 'press': led_states[ch] = not led_states[ch] touch.set_led(ch, led_states[ch]) if led_states[ch]: backlight.set_pixel(ch, 0, 255, 255) else: backlight.set_pixel(ch, 0, 255, 0) backlight.show() for x in range(6): touch.set_led(x, 1) time.sleep(0.1) touch.set_led(x, 0) for x in range(6): backlight.set_pixel(x, 0, 255, 0) touch.on(x, handler) backlight.show() for x in range(128): for y in range(64): pixel = image.getpixel((x, y)) lcd.set_pixel(x, y, pixel) lcd.show() try: signal.pause() except KeyboardInterrupt: for x in range(6): backlight.set_pixel(x, 0, 0, 0) touch.set_led(x, 0) backlight.show() lcd.clear() lcd.show() RE: python script for gfx hat (LCD for raspberry) - metulburr - Jun-30-2019 thats a very specific module. I would contact the authors of that module https://github.com/pimoroni/gfx-hat/issues RE: python script for gfx hat (LCD for raspberry) - noisefloor - Jun-30-2019 Hi, @domoticity : and the question is...? You describe what you intend to do - and that's it. I mean it's fine, but if you expect an answer, you may want to raise a question to answer. General comments: In case you do not understand the code -> learn Python and read the docs for the Python module driving the display. It won't help you at all if I would try to explain the code to you if you have no basic understanding of Python, its object orientation, classes and methods. Displaying stuff is independent of that. To run scripts at boot time, you need to write systemd Service Units to start you scripts. Do you ever have heard of that? Otherwise, you need to dive into this topic as well. Depending on when the hardware drive is loaded by the Linux kernel, your plan may work or not, as it may be that the network is up and running before the driver for the display is even loaded. Or the driver is loaded first but the network is up 0.5 seconds or so later, so you hardly will see the text displayed before. Anyway, systemd has tools to analyze what is run at which point in the booting process. Regards, noisefloor RE: python script for gfx hat (LCD for raspberry) - domoticity - Jul-02-2019 (Jun-30-2019, 08:53 PM)metulburr Wrote: thats a very specific module. I would contact the authors of that module https://github.com/pimoroni/gfx-hat/issuesHy Thank you to answer me . I have sent email.i'm waiting an answer from Author. (Jun-30-2019, 10:36 PM)noisefloor Wrote: Hi, @domoticity : and the question is...? You describe what you intend to do - and that's it. I mean it's fine, but if you expect an answer, you may want to raise a question to answer. General comments: In case you do not understand the code -> learn Python and read the docs for the Python module driving the display. It won't help you at all if I would try to explain the code to you if you have no basic understanding of Python, its object orientation, classes and methods. Displaying stuff is independent of that. To run scripts at boot time, you need to write systemd Service Units to start you scripts. Do you ever have heard of that? Otherwise, you need to dive into this topic as well. Depending on when the hardware drive is loaded by the Linux kernel, your plan may work or not, as it may be that the network is up and running before the driver for the display is even loaded. Or the driver is loaded first but the network is up 0.5 seconds or so later, so you hardly will see the text displayed before. Anyway, systemd has tools to analyze what is run at which point in the booting process. Regards, noisefloor Hy, Thank you to answer me :) I am learning, trying, reading a lot about Python, and i have succeeded to display text on my LCD. And sorry, i have forgotten to post my questions :) But now, i try to display little picture. I documented myself here : http://docs.pimoroni.com/gfxhat/ pil And here my python script : #!/usr/bin/env python import time from gfxhat import lcd, backlight, fonts from PIL import Image, ImageFont, ImageDraw print("""Image boot""") backlight.set_all(240,240,240) backlight.show() lcd.clear() image = Image.open("/home/test.jpg") Image.show() x = 00 y = 00 lcd.set_pixel(x, y, 1) lcd.show()My LCD lights but no picture. My OS is Debian with no desktop, more precise Raspbian lite. My question are : -Can we display pictures in a LCD on gpio without graphical environment ? I probably did a big mistake in my script bu don't see where :) RE: python script for gfx hat (LCD for raspberry) - noisefloor - Jul-03-2019 Hi, Quote: -Can we display pictures in a LCD on gpio without graphical environment ?Yes, you can. Basically what the code of your 1st post is doing is to iterate over an object of an PIL image and set the pixels of the display accordingly. So everything which can be read into a PIL image should be possible to display on your LCD. And this will work on systems with no graphics environment running as well, as long as you try not to display something on the system itself. Regards, noisefloor RE: python script for gfx hat (LCD for raspberry) - domoticity - Jul-03-2019 Hy. Si that's why my script doesn't work, image.show() tries to open thé picture in thé system itself,isn't it? Thank you for your answer RE: python script for gfx hat (LCD for raspberry) - noisefloor - Jul-03-2019 Hi, that's correct. You don't need to call image.show() , as there is no need to display on the graphical output of your system. To display the graphics on your LCD, you need to call the methods to do that. That's completely independent of the graphical output of your Raspi.Regards, noisefloor RE: python script for gfx hat (LCD for raspberry) - domoticity - Jul-03-2019 (Jul-03-2019, 12:48 PM)noisefloor Wrote: Hi, that's correct. You don't need to call So now i try it : #!/usr/bin/env python import time from gfxhat import lcd, backlight, fonts from PIL import Image, ImageFont, ImageDraw print("""Afficher une image""") backlight.set_all(240,240,240) backlight.show() lcd.clear() image =Image.open("/tmp/aa.jpg") x = 00 y = 40 pixel = image.getpixel((x, y)) lcd.set_pixel(120, 30, image) lcd.show()But it doesn't work . :( I turn around like Bonnie tyler's song :) RE: python script for gfx hat (LCD for raspberry) - noisefloor - Jul-04-2019 Hi, it doesn't work because you ignored what I wrote about and / or don't understand the code you posted in the initial post. Again: you have to iterate over the image and need to set _each_ pixel of your LCD, one-by-one. That's what the lines 59-62 do in the code of your 1st post. The Python module for display seems to have no high-level interface, you have to deal low level which each pixel. Regards, noisefloor RE: python script for gfx hat (LCD for raspberry) - domoticity - Jul-04-2019 (Jul-04-2019, 02:09 AM)noisefloor Wrote: Hi, it doesn't work because you ignored what I wrote about and / or don't understand the code you posted in the initial post. Again: you have to iterate over the image and need to set _each_ pixel of your LCD, one-by-one. That's what the lines 59-62 do in the code of your 1st post. The Python module for display seems to have no high-level interface, you have to deal low level which each pixel. Regards, noisefloor Hy thank you to answer. I don't ignore what you wrote. Ii don't understand the whole code in the initial post. I try to find informations about to better understand. I try to modify considering what you have wrote #!/usr/bin/env python import time from gfxhat import lcd, backlight, fonts from PIL import Image, ImageFont, ImageDraw print("""Message de demarrage""") backlight.set_all(240,240,240) backlight.show() lcd.clear() width, height = lcd.dimensions() image = Image.open("/tmp/aa.jpg") draw = ImageDraw.Draw(image) for x in range(50): for y in range(50): pixel = image.getpixel((x, y)) lcd.set_pixel(x, y, pixel) lcd.show()The error whicvh i have when i execut the scripts : root@diagbox:/tmp# python test.py Message de demarrage Traceback (most recent call last): File "test.py", line 21, in <module> lcd.set_pixel(x, y, pixel) File "/usr/local/lib/python2.7/dist-packages/gfxhat/st7567.py", line 137, in set_pixel self.buf[offset] |= (value & 1) << bit TypeError: unsupported operand type(s) for &: 'tuple' and 'int' |