Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A demo project for the 2.7" ePaper HAT from Waveshare, using the display and the buttons
import sys
sys.path.insert(1, "./lib")
import epd2in7b
from PIL import Image, ImageDraw, ImageFont
from gpiozero import Button
btn = Button(5)
epd = epd2in7b.EPD()
epd.init()
print("Clear...")
epd.Clear(0xFF)
def printToDisplay(string):
HBlackImage = Image.new('1', (epd2in7b.EPD_HEIGHT, epd2in7b.EPD_WIDTH), 255)
HRedImage = Image.new('1', (epd2in7b.EPD_HEIGHT, epd2in7b.EPD_WIDTH), 255)
draw = ImageDraw.Draw(HBlackImage) # Create draw object and pass in the image layer we want to work with (HBlackImage)
font = ImageFont.truetype('/usr/share/fonts/truetype/google/Bangers-Regular.ttf', 30) # Create our font, passing in the font file and font size
draw.text((25, 65), string, font = font, fill = 0)
epd.display(epd.getbuffer(HBlackImage), epd.getbuffer(HRedImage))
def handleBtnPress():
printToDisplay("Hello, World!")
btn.when_pressed = handleBtnPress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment