add 2in13b_V4 code
This commit is contained in:
parent
62605bf8af
commit
dd40a58b19
30 changed files with 11675 additions and 4 deletions
|
@ -67,13 +67,13 @@ try:
|
|||
epd.display(epd.getbuffer(LBlackimage), epd.getbuffer(LRYimage))
|
||||
time.sleep(2)
|
||||
|
||||
# logging.info("3.read bmp file")
|
||||
logging.info("3.read bmp file")
|
||||
Blackimage = Image.open(os.path.join(picdir, '2in13bc-b.bmp'))
|
||||
RYimage = Image.open(os.path.join(picdir, '2in13bc-ry.bmp'))
|
||||
epd.display(epd.getbuffer(Blackimage), epd.getbuffer(RYimage))
|
||||
time.sleep(2)
|
||||
|
||||
# logging.info("4.read bmp file on window")
|
||||
logging.info("4.read bmp file on window")
|
||||
blackimage1 = Image.new('1', (epd.height, epd.width), 255) # 298*126
|
||||
redimage1 = Image.new('1', (epd.height, epd.width), 255) # 298*126
|
||||
newimage = Image.open(os.path.join(picdir, '100x100.bmp'))
|
||||
|
|
96
RaspberryPi_JetsonNano/python/examples/epd_2in13b_V4_test.py
Normal file
96
RaspberryPi_JetsonNano/python/examples/epd_2in13b_V4_test.py
Normal file
|
@ -0,0 +1,96 @@
|
|||
#!/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 epd2in13b_V4
|
||||
import time
|
||||
from PIL import Image,ImageDraw,ImageFont
|
||||
import traceback
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
try:
|
||||
logging.info("epd2in13b_V4 Demo")
|
||||
|
||||
epd = epd2in13b_V4.EPD()
|
||||
logging.info("init and Clear")
|
||||
epd.init()
|
||||
epd.Clear()
|
||||
time.sleep(1)
|
||||
|
||||
# Drawing on the image
|
||||
logging.info("Drawing")
|
||||
font20 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 20)
|
||||
font18 = ImageFont.truetype(os.path.join(picdir, 'Font.ttc'), 18)
|
||||
|
||||
# Drawing on the Horizontal image
|
||||
logging.info("1.Drawing on the Horizontal image...")
|
||||
HBlackimage = Image.new('1', (epd.height, epd.width), 255) # 250*122
|
||||
HRYimage = Image.new('1', (epd.height, epd.width), 255) # 250*122
|
||||
drawblack = ImageDraw.Draw(HBlackimage)
|
||||
drawry = ImageDraw.Draw(HRYimage)
|
||||
drawblack.text((10, 0), 'hello world', font = font20, fill = 0)
|
||||
drawblack.text((10, 20), '2.13inch e-Paper b V4', font = font20, fill = 0)
|
||||
drawblack.text((120, 0), u'微雪电子', font = font20, fill = 0)
|
||||
drawblack.line((20, 50, 70, 100), fill = 0)
|
||||
drawblack.line((70, 50, 20, 100), fill = 0)
|
||||
drawblack.rectangle((20, 50, 70, 100), outline = 0)
|
||||
drawry.line((165, 50, 165, 100), fill = 0)
|
||||
drawry.line((140, 75, 190, 75), fill = 0)
|
||||
drawry.arc((140, 50, 190, 100), 0, 360, fill = 0)
|
||||
drawry.rectangle((80, 50, 130, 100), fill = 0)
|
||||
drawry.chord((85, 55, 125, 95), 0, 360, fill =1)
|
||||
epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRYimage))
|
||||
time.sleep(2)
|
||||
|
||||
# Drawing on the Vertical image
|
||||
logging.info("2.Drawing on the Vertical image...")
|
||||
LBlackimage = Image.new('1', (epd.width, epd.height), 255) # 122*250
|
||||
LRYimage = Image.new('1', (epd.width, epd.height), 255) # 122*250
|
||||
drawblack = ImageDraw.Draw(LBlackimage)
|
||||
drawry = ImageDraw.Draw(LRYimage)
|
||||
drawblack.text((2, 0), 'hello world', font = font18, fill = 0)
|
||||
drawblack.text((2, 20), '2.13 epd b V4', font = font18, fill = 0)
|
||||
drawblack.text((20, 50), u'微雪电子', font = font18, fill = 0)
|
||||
drawblack.line((10, 90, 60, 140), fill = 0)
|
||||
drawblack.line((60, 90, 10, 140), fill = 0)
|
||||
drawblack.rectangle((10, 90, 60, 140), outline = 0)
|
||||
drawry.rectangle((10, 150, 60, 200), fill = 0)
|
||||
drawry.arc((15, 95, 55, 135), 0, 360, fill = 0)
|
||||
drawry.chord((15, 155, 55, 195), 0, 360, fill =1)
|
||||
epd.display(epd.getbuffer(LBlackimage), epd.getbuffer(LRYimage))
|
||||
time.sleep(2)
|
||||
|
||||
logging.info("3.read bmp file")
|
||||
Blackimage = Image.open(os.path.join(picdir, '2in13b_V4b.bmp'))
|
||||
RYimage = Image.open(os.path.join(picdir, '2in13b_V4b.bmp'))
|
||||
epd.display(epd.getbuffer(Blackimage), epd.getbuffer(RYimage))
|
||||
time.sleep(2)
|
||||
|
||||
logging.info("4.read bmp file on window")
|
||||
blackimage1 = Image.new('1', (epd.height, epd.width), 255) # 250*122
|
||||
redimage1 = Image.new('1', (epd.height, epd.width), 255) # 250*122
|
||||
newimage = Image.open(os.path.join(picdir, '100x100.bmp'))
|
||||
blackimage1.paste(newimage, (0,0))
|
||||
epd.display(epd.getbuffer(blackimage1), epd.getbuffer(redimage1))
|
||||
|
||||
logging.info("Clear...")
|
||||
epd.init()
|
||||
epd.clear()
|
||||
|
||||
logging.info("Goto Sleep...")
|
||||
epd.sleep()
|
||||
|
||||
except IOError as e:
|
||||
logging.info(e)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
logging.info("ctrl + c:")
|
||||
epd2in13b_V4.epdconfig.module_exit()
|
||||
exit()
|
208
RaspberryPi_JetsonNano/python/lib/waveshare_epd/epd2in13b_V4.py
Normal file
208
RaspberryPi_JetsonNano/python/lib/waveshare_epd/epd2in13b_V4.py
Normal file
|
@ -0,0 +1,208 @@
|
|||
# *****************************************************************************
|
||||
# * | File : epd2in13b_V4.py
|
||||
# * | Author : Waveshare team
|
||||
# * | Function : Electronic paper driver
|
||||
# * | Info :
|
||||
# *----------------
|
||||
# * | This version: V1.0
|
||||
# * | Date : 2022-04-21
|
||||
# # | Info : python demo
|
||||
# -----------------------------------------------------------------------------
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documnetation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
#
|
||||
|
||||
import logging
|
||||
from . import epdconfig
|
||||
|
||||
# Display resolution
|
||||
EPD_WIDTH = 122
|
||||
EPD_HEIGHT = 250
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class EPD:
|
||||
def __init__(self):
|
||||
self.reset_pin = epdconfig.RST_PIN
|
||||
self.dc_pin = epdconfig.DC_PIN
|
||||
self.busy_pin = epdconfig.BUSY_PIN
|
||||
self.cs_pin = epdconfig.CS_PIN
|
||||
self.width = EPD_WIDTH
|
||||
self.height = EPD_HEIGHT
|
||||
|
||||
# hardware reset
|
||||
def reset(self):
|
||||
epdconfig.digital_write(self.reset_pin, 1)
|
||||
epdconfig.delay_ms(20)
|
||||
epdconfig.digital_write(self.reset_pin, 0)
|
||||
epdconfig.delay_ms(2)
|
||||
epdconfig.digital_write(self.reset_pin, 1)
|
||||
epdconfig.delay_ms(20)
|
||||
|
||||
# send 1 byte command
|
||||
def send_command(self, command):
|
||||
epdconfig.digital_write(self.dc_pin, 0)
|
||||
epdconfig.digital_write(self.cs_pin, 0)
|
||||
epdconfig.spi_writebyte([command])
|
||||
epdconfig.digital_write(self.cs_pin, 1)
|
||||
|
||||
# send 1 byte data
|
||||
def send_data(self, data):
|
||||
epdconfig.digital_write(self.dc_pin, 1)
|
||||
epdconfig.digital_write(self.cs_pin, 0)
|
||||
epdconfig.spi_writebyte([data])
|
||||
epdconfig.digital_write(self.cs_pin, 1)
|
||||
|
||||
# send a lot of data
|
||||
def send_data2(self, data):
|
||||
epdconfig.digital_write(self.dc_pin, 1)
|
||||
epdconfig.digital_write(self.cs_pin, 0)
|
||||
epdconfig.spi_writebyte2(data)
|
||||
epdconfig.digital_write(self.cs_pin, 1)
|
||||
|
||||
# judge e-Paper whether is busy
|
||||
def busy(self):
|
||||
logger.debug("e-Paper busy")
|
||||
while(epdconfig.digital_read(self.busy_pin) != 0):
|
||||
epdconfig.delay_ms(10)
|
||||
logger.debug("e-Paper busy release")
|
||||
|
||||
# set the display window
|
||||
def set_windows(self, xstart, ystart, xend, yend):
|
||||
self.send_command(0x44) # SET_RAM_X_ADDRESS_START_END_POSITION
|
||||
self.send_data((xstart>>3) & 0xff)
|
||||
self.send_data((xend>>3) & 0xff)
|
||||
|
||||
self.send_command(0x45) # SET_RAM_Y_ADDRESS_START_END_POSITION
|
||||
self.send_data(ystart & 0xff)
|
||||
self.send_data((ystart >> 8) & 0xff)
|
||||
self.send_data(yend & 0xff)
|
||||
self.send_data((yend >> 8) & 0xff)
|
||||
|
||||
# set the display cursor(origin)
|
||||
def set_cursor(self, xstart, ystart):
|
||||
self.send_command(0x4E) # SET_RAM_X_ADDRESS_COUNTER
|
||||
self.send_data(xstart & 0xff)
|
||||
|
||||
self.send_command(0x4F) # SET_RAM_Y_ADDRESS_COUNTER
|
||||
self.send_data(ystart & 0xff)
|
||||
self.send_data((ystart >> 8) & 0xff)
|
||||
|
||||
# initialize
|
||||
def init(self):
|
||||
if (epdconfig.module_init() != 0):
|
||||
return -1
|
||||
|
||||
self.reset()
|
||||
|
||||
self.busy()
|
||||
self.send_command(0x12) # SWRESET
|
||||
self.busy()
|
||||
|
||||
self.send_command(0x01) # Driver output control
|
||||
self.send_data(0xf9)
|
||||
self.send_data(0x00)
|
||||
self.send_data(0x00)
|
||||
|
||||
self.send_command(0x11) # data entry mode
|
||||
self.send_data(0x03)
|
||||
|
||||
self.set_windows(0, 0, self.width - 1, self.height - 1)
|
||||
self.set_cursor(0, 0)
|
||||
|
||||
self.send_command(0x3C) # BorderWavefrom
|
||||
self.send_data(0x05)
|
||||
|
||||
self.send_command(0x18) # Read built-in temperature sensor
|
||||
self.send_data(0x80)
|
||||
|
||||
self.send_command(0x21) # Display update control
|
||||
self.send_data(0x80)
|
||||
self.send_data(0x80)
|
||||
|
||||
self.busy()
|
||||
|
||||
return 0
|
||||
|
||||
# turn on display
|
||||
def ondisplay(self):
|
||||
self.send_command(0x20)
|
||||
self.busy()
|
||||
|
||||
# image converted to bytearray
|
||||
def getbuffer(self, image):
|
||||
img = image
|
||||
imwidth, imheight = img.size
|
||||
if(imwidth == self.width and imheight == self.height):
|
||||
img = img.convert('1')
|
||||
elif(imwidth == self.height and imheight == self.width):
|
||||
# image has correct dimensions, but needs to be rotated
|
||||
img = img.rotate(90, expand=True).convert('1')
|
||||
else:
|
||||
logger.warning("Wrong image dimensions: must be " + str(self.width) + "x" + str(self.height))
|
||||
# return a blank buffer
|
||||
return [0x00] * (int(self.width/8) * self.height)
|
||||
|
||||
buf = bytearray(img.tobytes('raw'))
|
||||
return buf
|
||||
|
||||
# display image
|
||||
def display(self, imageblack, imagered):
|
||||
if self.width%8 == 0:
|
||||
linewidth = int(self.width/8)
|
||||
else:
|
||||
linewidth = int(self.width/8) + 1
|
||||
|
||||
self.send_command(0x24)
|
||||
self.send_data2(imageblack)
|
||||
|
||||
self.send_command(0x26)
|
||||
self.send_data2(imagered)
|
||||
|
||||
self.ondisplay()
|
||||
|
||||
# display white image
|
||||
def clear(self):
|
||||
if self.width%8 == 0:
|
||||
linewidth = int(self.width/8)
|
||||
else:
|
||||
linewidth = int(self.width/8) + 1
|
||||
|
||||
buf = [0xff] * (int(linewidth * self.height))
|
||||
|
||||
self.send_command(0x24)
|
||||
self.send_data2(buf)
|
||||
|
||||
self.send_command(0x26)
|
||||
self.send_data2(buf)
|
||||
|
||||
self.ondisplay()
|
||||
|
||||
# Compatible with older version functions
|
||||
def Clear(self):
|
||||
self.clear()
|
||||
|
||||
# sleep
|
||||
def sleep(self):
|
||||
self.send_command(0x10) # DEEP_SLEEP
|
||||
self.send_data(0x01) # check code
|
||||
|
||||
epdconfig.delay_ms(2000)
|
||||
epdconfig.module_exit()
|
||||
### END OF FILE ###
|
||||
|
BIN
RaspberryPi_JetsonNano/python/pic/2in13b_V4b.bmp
Normal file
BIN
RaspberryPi_JetsonNano/python/pic/2in13b_V4b.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 KiB |
BIN
RaspberryPi_JetsonNano/python/pic/2in13b_V4r.bmp
Normal file
BIN
RaspberryPi_JetsonNano/python/pic/2in13b_V4r.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 KiB |
Loading…
Add table
Add a link
Reference in a new issue