Add the 4.37inch e-Paper (G) Python program

This commit is contained in:
SSYYL 2022-08-15 18:57:30 +08:00
parent 023a5759e3
commit 77c499d749
11 changed files with 348 additions and 83 deletions

View file

@ -18,26 +18,22 @@ logging.basicConfig(level=logging.DEBUG)
try:
logging.info("epd1in64g Demo")
BLACK = 0x00
WHITE = 0x55
YELLOW = 0xAA
RED = 0xFF
epd = epd1in64g.EPD()
logging.info("init and Clear")
epd.init()
epd.Clear(WHITE)
epd.Clear()
font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18)
font30 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 40)
font40 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 40)
# # The Sunrise X3 PI is a bit problematic to use
# # Drawing on the image
# logging.info("1.Drawing on the image...")
# Himage = Image.new('RGB', (epd.width, epd.height), 0xffffff)
# Himage = Image.new('RGB', (epd.width, epd.height), epd.WHITE)
# draw = ImageDraw.Draw(Himage)
# draw.text((5, 0), 'hello world', font = font18, fill = epd.RED)
# draw.text((5, 20), '1.64inch e-Paper', font = font18, fill = epd.YELLOW)
# draw.text((5, 40), u'微雪电子', font = font30, fill = epd.BLACK)
# draw.text((5, 40), u'微雪电子', font = font40, fill = epd.BLACK)
# draw.line((5, 90, 45, 160), fill = epd.RED)
# draw.line((45, 90, 5, 160), fill = epd.YELLOW)
@ -60,7 +56,7 @@ try:
time.sleep(3)
logging.info("Clear...")
epd.Clear(WHITE)
epd.Clear()
logging.info("Goto Sleep...")
epd.sleep()

View file

@ -18,18 +18,13 @@ logging.basicConfig(level=logging.DEBUG)
try:
logging.info("epd3in0g Demo")
BLACK = 0x00
WHITE = 0x55
YELLOW = 0xAA
RED = 0xFF
epd = epd3in0g.EPD()
logging.info("init and Clear")
epd.init()
epd.Clear(WHITE)
epd.Clear()
font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18)
font30 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 40)
font40 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 40)
# Drawing on the image
epd.init()
@ -38,9 +33,9 @@ try:
draw = ImageDraw.Draw(Himage)
draw.text((5, 0), 'hello world', font = font18, fill = epd.RED)
draw.text((5, 20), '3inch e-Paper', font = font24, fill = epd.YELLOW)
draw.text((5, 45), u'微雪电子', font = font30, fill = epd.BLACK)
draw.text((5, 85), u'微雪电子', font = font30, fill = epd.YELLOW)
draw.text((5, 125), u'微雪电子', font = font30, fill = epd.RED)
draw.text((5, 45), u'微雪电子', font = font40, fill = epd.BLACK)
draw.text((5, 85), u'微雪电子', font = font40, fill = epd.YELLOW)
draw.text((5, 125), u'微雪电子', font = font40, fill = epd.RED)
draw.line((5, 170, 80, 245), fill = epd.RED)
draw.line((80, 170, 5, 245), fill = epd.YELLOW)
draw.rectangle((5, 170, 80, 245), outline = epd.BLACK)
@ -50,17 +45,16 @@ try:
epd.display(epd.getbuffer(Himage))
time.sleep(3)
# Switch width and height for landscape display
epd.init()
logging.info("1.Drawing on the image...")
Himage = Image.new('RGB', (epd.height, epd.width), 0xffffff)
Himage = Image.new('RGB', (epd.height, epd.width), epd.WHITE)
draw = ImageDraw.Draw(Himage)
draw.text((5, 0), 'hello world', font = font18, fill = epd.RED)
draw.text((5, 20), '3inch e-Paper', font = font24, fill = epd.YELLOW)
draw.text((5, 45), u'微雪电子', font = font30, fill = epd.BLACK)
draw.text((5, 85), u'微雪电子', font = font30, fill = epd.YELLOW)
draw.text((5, 125), u'微雪电子', font = font30, fill = epd.RED)
draw.text((5, 45), u'微雪电子', font = font40, fill = epd.BLACK)
draw.text((5, 85), u'微雪电子', font = font40, fill = epd.YELLOW)
draw.text((5, 125), u'微雪电子', font = font40, fill = epd.RED)
draw.line((205, 5, 295, 65), fill = epd.RED)
draw.line((295, 5, 205, 65), fill = epd.YELLOW)
draw.rectangle((205, 5, 295, 65), outline = epd.BLACK)
@ -91,7 +85,7 @@ try:
epd.init()
logging.info("Clear...")
epd.Clear(WHITE)
epd.Clear()
logging.info("Goto Sleep...")
epd.sleep()

View file

@ -0,0 +1,76 @@
#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
import os
picdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'pic')
libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
if os.path.exists(libdir):
sys.path.append(libdir)
import logging
from waveshare_epd import epd4in37g
import time
from PIL import Image,ImageDraw,ImageFont
import traceback
logging.basicConfig(level=logging.DEBUG)
try:
logging.info("epd4in37g Demo")
epd = epd4in37g.EPD()
logging.info("init and Clear")
epd.init()
epd.Clear()
font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18)
font40 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 40)
# Drawing on the image
logging.info("1.Drawing on the image...")
Himage = Image.new('RGB', (epd.width, epd.height), epd.WHITE) # 255: clear the frame
draw = ImageDraw.Draw(Himage)
draw.text((5, 0), 'hello world', font = font18, fill = epd.RED)
draw.text((5, 20), '7.3inch e-Paper', font = font24, fill = epd.YELLOW)
draw.text((5, 45), u'微雪电子', font = font40, fill = epd.BLACK)
draw.text((5, 85), u'微雪电子', font = font40, fill = epd.YELLOW)
draw.text((5, 125), u'微雪电子', font = font40, fill = epd.RED)
draw.line((5, 170, 80, 245), fill = epd.RED)
draw.line((80, 170, 5, 245), fill = epd.YELLOW)
draw.rectangle((5, 170, 80, 245), outline = epd.BLACK)
draw.rectangle((90, 170, 165, 245), fill = epd.YELLOW)
draw.arc((5, 250, 80, 325), 0, 360, fill = epd.BLACK)
draw.chord((90, 250, 165, 325), 0, 360, fill = epd.RED)
epd.display(epd.getbuffer(Himage))
time.sleep(3)
# read bmp file
logging.info("3.read image file")
Himage = Image.open(os.path.join(picdir, '4in37g0.jpg'))
epd.display(epd.getbuffer(Himage))
time.sleep(3)
logging.info("3.read image file")
Himage = Image.open(os.path.join(picdir, '4in37g1.jpg'))
epd.display(epd.getbuffer(Himage))
time.sleep(3)
logging.info("3.read image file")
Himage = Image.open(os.path.join(picdir, '4in37g2.jpg'))
epd.display(epd.getbuffer(Himage))
time.sleep(3)
logging.info("Clear...")
epd.Clear()
logging.info("Goto Sleep...")
epd.sleep()
except IOError as e:
logging.info(e)
except KeyboardInterrupt:
logging.info("ctrl + c:")
epd4in37g.epdconfig.module_exit()
exit()

View file

@ -18,28 +18,23 @@ logging.basicConfig(level=logging.DEBUG)
try:
logging.info("epd7in3g Demo")
BLACK = 0x00
WHITE = 0x55
YELLOW = 0xAA
RED = 0xFF
epd = epd7in3g.EPD()
logging.info("init and Clear")
epd.init()
epd.Clear(WHITE)
epd.Clear()
font24 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 24)
font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18)
font30 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 40)
font40 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 40)
# Drawing on the image
logging.info("1.Drawing on the image...")
Himage = Image.new('RGB', (epd.width, epd.height), 0xffffff) # 255: clear the frame
Himage = Image.new('RGB', (epd.width, epd.height), epd.WHITE) # 255: clear the frame
draw = ImageDraw.Draw(Himage)
draw.text((5, 0), 'hello world', font = font18, fill = epd.RED)
draw.text((5, 20), '7.3inch e-Paper', font = font24, fill = epd.YELLOW)
draw.text((5, 45), u'微雪电子', font = font30, fill = epd.BLACK)
draw.text((5, 85), u'微雪电子', font = font30, fill = epd.YELLOW)
draw.text((5, 125), u'微雪电子', font = font30, fill = epd.RED)
draw.text((5, 45), u'微雪电子', font = font40, fill = epd.BLACK)
draw.text((5, 85), u'微雪电子', font = font40, fill = epd.YELLOW)
draw.text((5, 125), u'微雪电子', font = font40, fill = epd.RED)
draw.line((5, 170, 80, 245), fill = epd.RED)
draw.line((80, 170, 5, 245), fill = epd.YELLOW)
@ -67,7 +62,7 @@ try:
time.sleep(3)
logging.info("Clear...")
epd.Clear(WHITE)
epd.Clear()
logging.info("Goto Sleep...")
epd.sleep()