Skip to content

Instantly share code, notes, and snippets.

@wallentx
Last active December 13, 2025 04:39
Show Gist options
  • Select an option

  • Save wallentx/d03ac6cb784341da9cf53caf94fa700d to your computer and use it in GitHub Desktop.

Select an option

Save wallentx/d03ac6cb784341da9cf53caf94fa700d to your computer and use it in GitHub Desktop.
Change image on button press - for the Inky Impression - 5.7", 7-color eInk display for the RPi
#!/usr/bin/env python3
import signal
import RPi.GPIO as GPIO
import subprocess
# Gpio pins for each button (from top to bottom)
BUTTONS = [5, 6, 16, 24]
# These correspond to buttons A, B, C and D respectively
LABELS = ['A', 'B', 'C', 'D']
# Set up RPi.GPIO with the "BCM" numbering scheme
GPIO.setmode(GPIO.BCM)
# Buttons connect to ground when pressed, so we should set them up
# with a "PULL UP", which weakly pulls the input signal to 3.3V.
GPIO.setup(BUTTONS, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# "handle_button" will be called every time a button is pressed
# It receives one argument: the associated input pin.
def handle_button(pin):
label = LABELS[BUTTONS.index(pin)]
if str(label) == 'A':
subprocess.run(["inkywrite", "/home/pi/Pictures/A.png"])
elif str(label) == 'B':
subprocess.run(["inkywrite", "/home/pi/Pictures/B.png"])
elif str(label) == 'C':
subprocess.run(["inkywrite", "/home/pi/Pictures/C.png"])
elif str(label) == 'D':
subprocess.run(["inkywrite", "/home/pi/Pictures/D.png"])
return
# Loop through out buttons and attach the "handle_button" function to each
# We're watching the "FALLING" edge (transition from 3.3V to Ground) and
# picking a generous bouncetime of 250ms to smooth out button presses.
for pin in BUTTONS:
GPIO.add_event_detect(pin, GPIO.FALLING, handle_button, bouncetime=250)
# Finally, since button handlers don't require a "while True" loop,
# we pause the script to prevent it exiting immediately.
signal.pause()
#!/usr/bin/env python3
import sys
from PIL import Image
from inky.inky_uc8159 import Inky
inky = Inky()
saturation = 0.5
if len(sys.argv) == 1:
print("""
Usage: {file} image-file
""".format(file=sys.argv[0]))
sys.exit(1)
image = Image.open(sys.argv[1])
if len(sys.argv) > 2:
saturation = float(sys.argv[2])
inky.set_image(image, saturation=saturation)
inky.show()
@ecoco6
Copy link
Copy Markdown

ecoco6 commented May 23, 2024

Hello, I am new to this.
COuld you help me understand why is this showing up?:
FileNotFoundError: [Errno 2] No such file or directory: 'inkywrite'

@wallentx
Copy link
Copy Markdown
Author

wallentx commented May 23, 2024

Hello, I am new to this. COuld you help me understand why is this showing up?: FileNotFoundError: [Errno 2] No such file or directory: 'inkywrite'

@ecoco6
https://gist.github.com/wallentx/9a8c983f028c198f3bf1ff9dd4d3ad5f

@wallentx
Copy link
Copy Markdown
Author

wallentx commented May 23, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment