InkyPhat + Button GPIO issue

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 :)

I’d say you have a pin use conflict.
GPIO 2 is used for i2c and the Inky pHat uses i2c.
Inky pHAT at Raspberry Pi GPIO Pinout

I’d switch the button to different pin that’s not used by the inky.

Thank you for the reply! I’ll do that but I did check this image and the pin appears to be free. Am I looking at the wrong thing?

Where did that image come from? It seems to skip a lot of Inky related pins
edit: ahh, looks like the phat stack thing has some … functionality challenges :)

That’s interesting? The GPIO pinout I linked too says?

  • Uses 8 GPIO pins
  • Communication over SPI
  • Communication over I2C
  • 0x50: Inky ID EEPROM

i2c must be used for the ID EEPROM?
Running `sudo i2cdetect y -1’ will confirm it, you will see a 0x50.

It’s the phat Stack configurator.
pHAT Stack Configurator (pinout.xyz)

Yeah, looks like the phat stack configurator doesn’t pick up the i2c usage. Oops.

Your not supposed to use i2c1 for that anyway. EEPROM ID is suposed to be done via i2c0.

I see, thanks, so GPIO 4 on your link would work it seems. The rest of the conversation is way over my head at the moment. :D
I ordered a breadboard for future projects so I don’t mess this up again.

GPIO 4 should work, or 5 or 6, etc.
If you follow the Pi Foundation Hat spec, GPIO 0 and 1 are supposed to be used for the ID EEPROM. It’s what they use for the Sense Hat etc.
What Pimoroni did isn’t a big deal and works for how they use it. As long as you know its actually using i2c(1) you can make allowances.

Raspberry Pi GPIO Pinout

1 Like

How did you mange it? I’ve been thinking of adding a couple of buttons to my inkyPhat on my pi zero 2 w. It looks pretty fiddly. Any tips or pics would be appreciated.

I’ve been using Proto Zero’s, but it looks like they stopped making it? I can no longer find it on the shop page? It was Pimoroni’s version of this.
Adafruit Perma Proto Bonnet Mini Kit - Pimoroni
I’ve also used the Proto Bonnet, just like Pimoroni’s Black version better. I use a stacking header and put it between the Pi Zero and Hat.

1 Like