Hi! I have a pi zero w, inkyphat attached to it. I soldered a simple button to GPIO pin 2 and ground on the bottom of the pi. My button works if I try it with a separate script. My inkyphat loads my images from a folder with a simple script. However, if I try to add gpio button input to my image script (I want to display a random image from a folder on button press), this totally works, but only after a fresh boot and the first time I run the script. When I stop the script and run it again I always get this error:
Traceback (most recent call last): File "/home/pi/inky/drawimagebutton.py", line 5, in <module> inky_display = auto() File "/usr/local/lib/python3.9/dist-packages/inky/auto.py", line 68, in auto raise RuntimeError("Can't find a driver this display.") RuntimeError: Can't find a driver this display.
My guess is it’s because I add this: from gpiozero import Button, and initialize a button: button = Button(2)
This is my horrible script that works, but just once :P
from gpiozero import Button from inky.auto import auto import os, random, time inky_display = auto() inky_display.set_border(inky_display.WHITE) from PIL import Image, ImageFont, ImageDraw img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT)) draw = ImageDraw.Draw(img) def displayimage(image): img = Image.open("images/" + image) inky_display.set_image(img) inky_display.show() print("Printing image: " + image_selected) time.sleep(30) button = Button(2) old_image = random.choice(os.listdir("images/")) print("Press button to set up new image!") while True: #Find random image from folder, but make sure it's not the same as the previous one while True: image_selected = random.choice(os.listdir("images/")) if old_image != image_selected: #Print the name of the image print("Image selected: " + image_selected) break else: print("Same image selected. Picking new image...") #img = Image.open("images/image1.png") #Display the image button.when_pressed = lambda: displayimage(image_selected)
Thank you so much for any help. I love this so much already. I mean it did what I wanted to do already and I’m brand new to this! Just hope I can fix this issue :)