Created
August 30, 2019 18:06
-
-
Save RaneWallin/3d8645d06aed9251eed8c9079314807f to your computer and use it in GitHub Desktop.
First program for the Waveshare 2.7" ePaper HAT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!") |
Oh, good to know. The company must have changed the clear() method to no longer take a color code.
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
There are 2 problems I ran into while trying to do this.
The first was that the epd2in7b.py file has this line:
which returned an error. I just removed the
from .
part, so now I'm left with
which does work since it's in the same directory.
Second, the
function doesn't take any arguments.
So the code I'm now left with is this: