fix 2.13inch python

This commit is contained in:
hnwangkg-ezio 2019-03-20 10:36:06 +08:00
commit f8a1f32638
3 changed files with 64 additions and 95 deletions

View file

@ -4,27 +4,10 @@
# * | Function : Electronic paper driver # * | Function : Electronic paper driver
# * | Info : # * | Info :
# *---------------- # *----------------
# * | This version: V3.0 # * | This version: V3.1
# * | Date : 2018-11-01 # * | Date : 2019-03-20
# * | Info : python2 demo # * | Info : python2 demo
# * 1.Remove: # * fix: TurnOnDisplay()
# digital_write(self, pin, value)
# digital_read(self, pin)
# delay_ms(self, delaytime)
# set_lut(self, lut)
# self.lut = self.lut_full_update
# * 2.Change:
# display_frame -> TurnOnDisplay
# set_memory_area -> SetWindow
# set_memory_pointer -> SetCursor
# * 3.How to use
# epd = epd2in13.EPD()
# epd.init(epd.lut_full_update)
# image = Image.new('1', (epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT), 255)
# ...
# drawing ......
# ...
# epd.display(getbuffer(image))
# ******************************************************************************/ # ******************************************************************************/
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal # of this software and associated documnetation files (the "Software"), to deal
@ -98,10 +81,11 @@ class EPD:
epdconfig.delay_ms(100) epdconfig.delay_ms(100)
def TurnOnDisplay(self): def TurnOnDisplay(self):
self.send_command(0xC4) # DISPLAY_UPDATE_CONTROL_2 self.send_command(0x22) # DISPLAY_UPDATE_CONTROL_2
self.send_data(0xC7) self.send_data(0xC4)
self.send_command(0x20) # MASTER_ACTIVATION self.send_command(0x20) # MASTER_ACTIVATION
self.send_command(0xFF) # TERMINATE_FRAME_READ_WRITE self.send_command(0xFF) # TERMINATE_FRAME_READ_WRITE
self.wait_until_idle() self.wait_until_idle()
def init(self, lut): def init(self, lut):
@ -226,7 +210,7 @@ class EPD:
def sleep(self): def sleep(self):
self.send_command(0x10) #enter deep sleep self.send_command(0x10) #enter deep sleep
self.send_data(0x01) # self.send_data(0x01)
epdconfig.delay_ms(100) epdconfig.delay_ms(100)
### END OF FILE ### ### END OF FILE ###

View file

@ -4,27 +4,10 @@
# * | Function : Electronic paper driver # * | Function : Electronic paper driver
# * | Info : # * | Info :
# *---------------- # *----------------
# * | This version: V3.0 # * | This version: V3.1
# * | Date : 2018-11-01 # * | Date : 2019-03-20
# * | Info : python2 demo # * | Info : python3 demo
# * 1.Remove: # * fix: TurnOnDisplay()
# digital_write(self, pin, value)
# digital_read(self, pin)
# delay_ms(self, delaytime)
# set_lut(self, lut)
# self.lut = self.lut_full_update
# * 2.Change:
# display_frame -> TurnOnDisplay
# set_memory_area -> SetWindow
# set_memory_pointer -> SetCursor
# * 3.How to use
# epd = epd2in13.EPD()
# epd.init(epd.lut_full_update)
# image = Image.new('1', (epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT), 255)
# ...
# drawing ......
# ...
# epd.display(getbuffer(image))
# ******************************************************************************// # ******************************************************************************//
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal # of this software and associated documnetation files (the "Software"), to deal
@ -94,12 +77,14 @@ class EPD:
epdconfig.spi_writebyte([data]) epdconfig.spi_writebyte([data])
def wait_until_idle(self): def wait_until_idle(self):
print("busy")
while(epdconfig.digital_read(self.busy_pin) == 1): # 0: idle, 1: busy while(epdconfig.digital_read(self.busy_pin) == 1): # 0: idle, 1: busy
epdconfig.delay_ms(100) epdconfig.delay_ms(100)
print("free busy")
def TurnOnDisplay(self): def TurnOnDisplay(self):
self.send_command(0xC4) # DISPLAY_UPDATE_CONTROL_2 self.send_command(0x22) # DISPLAY_UPDATE_CONTROL_2
self.send_data(0xC7) self.send_data(0xC4)
self.send_command(0x20) # MASTER_ACTIVATION self.send_command(0x20) # MASTER_ACTIVATION
self.send_command(0xFF) # TERMINATE_FRAME_READ_WRITE self.send_command(0xFF) # TERMINATE_FRAME_READ_WRITE
self.wait_until_idle() self.wait_until_idle()
@ -226,7 +211,7 @@ class EPD:
def sleep(self): def sleep(self):
self.send_command(0x10) #enter deep sleep self.send_command(0x10) #enter deep sleep
self.send_data(0x01) # self.send_data(0x01)
epdconfig.delay_ms(100) epdconfig.delay_ms(100)
### END OF FILE ### ### END OF FILE ###

View file

@ -11,57 +11,57 @@ try:
epd.init(epd.lut_full_update) epd.init(epd.lut_full_update)
epd.Clear(0xFF) epd.Clear(0xFF)
# read bmp file on window # # read bmp file on window
print("read bmp file on window") # print("read bmp file on window")
epd.Clear(0xFF) # epd.Clear(0xFF)
image1 = Image.new('1', (epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT), 255) # 255: clear the frame # image1 = Image.new('1', (epd2in13.EPD_WIDTH, epd2in13.EPD_HEIGHT), 255) # 255: clear the frame
bmp = Image.open('100x100.bmp') # bmp = Image.open('100x100.bmp')
image1.paste(bmp, (10,10)) # image1.paste(bmp, (10,10))
epd.display(epd.getbuffer(image1)) # epd.display(epd.getbuffer(image1))
time.sleep(2) # time.sleep(2)
# Drawing on the image # # Drawing on the image
image2 = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255) # 255: clear the frame # image2 = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255) # 255: clear the frame
# read bmp file # # read bmp file
print("read bmp file") # print("read bmp file")
epd.Clear(0xFF) # epd.Clear(0xFF)
image2 = Image.open('2in13.bmp') # image2 = Image.open('2in13.bmp')
epd.display(epd.getbuffer(image2.rotate(180))) # epd.display(epd.getbuffer(image2.rotate(180)))
print("Drawing") # print("Drawing")
epd.Clear(0xFF) # epd.Clear(0xFF)
image = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255) # 255: clear the frame # image = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255) # 255: clear the frame
draw = ImageDraw.Draw(image) # draw = ImageDraw.Draw(image)
draw.rectangle([(0,0),(50,50)],outline = 0) # draw.rectangle([(0,0),(50,50)],outline = 0)
draw.rectangle([(55,0),(100,50)],fill = 0) # draw.rectangle([(55,0),(100,50)],fill = 0)
draw.line([(0,0),(50,50)], fill = 0,width = 1) # draw.line([(0,0),(50,50)], fill = 0,width = 1)
draw.line([(0,50),(50,0)], fill = 0,width = 1) # draw.line([(0,50),(50,0)], fill = 0,width = 1)
draw.chord((10, 60, 50, 100), 0, 360, fill = 0) # draw.chord((10, 60, 50, 100), 0, 360, fill = 0)
draw.ellipse((55, 60, 95, 100), outline = 0) # draw.ellipse((55, 60, 95, 100), outline = 0)
draw.pieslice((55, 60, 95, 100), 90, 180, outline = 0) # draw.pieslice((55, 60, 95, 100), 90, 180, outline = 0)
draw.pieslice((55, 60, 95, 100), 270, 360, fill = 0) # draw.pieslice((55, 60, 95, 100), 270, 360, fill = 0)
draw.polygon([(110,0),(110,50),(150,25)],outline = 0) # draw.polygon([(110,0),(110,50),(150,25)],outline = 0)
draw.polygon([(190,0),(190,50),(150,25)],fill = 0) # draw.polygon([(190,0),(190,50),(150,25)],fill = 0)
font15 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 15) # font15 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 15)
draw.text((120, 60), 'e-Paper demo', font = font15, fill = 0) # draw.text((120, 60), 'e-Paper demo', font = font15, fill = 0)
# draw.text((110, 80), 'Hello world', font = font15, fill = 0) # # draw.text((110, 80), 'Hello world', font = font15, fill = 0)
epd.display(epd.getbuffer(image.rotate(180))) # epd.display(epd.getbuffer(image.rotate(180)))
time.sleep(2) # time.sleep(2)
# partial update # # partial update
print("Show time") # print("Show time")
epd.init(epd.lut_partial_update) # epd.init(epd.lut_partial_update)
font24 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 24) # font24 = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', 24)
# time_image = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255) # # time_image = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255)
draw = ImageDraw.Draw(image) # draw = ImageDraw.Draw(image)
while (True): # while (True):
draw.rectangle((120, 80, 220, 105), fill = 255) # draw.rectangle((120, 80, 220, 105), fill = 255)
draw.text((120, 80), time.strftime('%H:%M:%S'), font = font24, fill = 0) # draw.text((120, 80), time.strftime('%H:%M:%S'), font = font24, fill = 0)
# newimage = time_image.crop([10, 10, 120, 50]) # # newimage = time_image.crop([10, 10, 120, 50])
# time_image.paste(newimage, (10,10)) # # time_image.paste(newimage, (10,10))
epd.display(epd.getbuffer(image.rotate(180))) # epd.display(epd.getbuffer(image.rotate(180)))
epd.sleep() # epd.sleep()
except: except:
print( 'traceback.format_exc():\n%s',traceback.format_exc()) print( 'traceback.format_exc():\n%s',traceback.format_exc())