Skip to content

Instantly share code, notes, and snippets.

@RaneWallin
Created August 30, 2019 18:06
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save RaneWallin/3d8645d06aed9251eed8c9079314807f to your computer and use it in GitHub Desktop.
Save RaneWallin/3d8645d06aed9251eed8c9079314807f to your computer and use it in GitHub Desktop.
First program for the Waveshare 2.7" ePaper HAT
import sys
sys.path.insert(1, "./lib")
import epd2in7b
from PIL import Image, ImageDraw, ImageFont
epd = epd2in7b.EPD() # get the display
epd.init() # initialize the display
print("Clear...") # prints to console, not the display, for debugging
epd.Clear(0xFF) # clear the display
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))
printToDisplay("Hello, World!")
@Ghoelian
Copy link

There are 2 problems I ran into while trying to do this.
The first was that the epd2in7b.py file has this line:

from . import epdconfig

which returned an error. I just removed the

from . 

part, so now I'm left with

import edpconfig

which does work since it's in the same directory.
Second, the

edp.Clear()

function doesn't take any arguments.
So the code I'm now left with is this:

import sys
sys.path.insert(1, "./lib")

import epd2in7b
from PIL import Image, ImageDraw, ImageFont

epd = epd2in7b.EPD() # get the display
epd.init()           # initialize the display
print("Clear...")    # prints to console, not the display, for debugging
epd.Clear()      # clear the display

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))
    
printToDisplay("Hello, World!")

@RaneWallin
Copy link
Author

Oh, good to know. The company must have changed the clear() method to no longer take a color code.

@Ewwwer
Copy link

Ewwwer commented Oct 9, 2020

You should include a try except to be able to handle errors or cut execution ;)

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