epd7in5b_HD.py 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. # *****************************************************************************
  2. # * | File : epd7in5bc_HD.py
  3. # * | Author : Waveshare team
  4. # * | Function : Electronic paper driver
  5. # * | Info :
  6. # *----------------
  7. # * | This version: V1.0
  8. # * | Date : 2019-06-20
  9. # # | Info : python demo
  10. # -----------------------------------------------------------------------------
  11. # Permission is hereby granted, free of charge, to any person obtaining a copy
  12. # of this software and associated documnetation files (the "Software"), to deal
  13. # in the Software without restriction, including without limitation the rights
  14. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. # copies of the Software, and to permit persons to whom the Software is
  16. # furished to do so, subject to the following conditions:
  17. #
  18. # The above copyright notice and this permission notice shall be included in
  19. # all copies or substantial portions of the Software.
  20. #
  21. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. # FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. # LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27. # THE SOFTWARE.
  28. #
  29. import logging
  30. from . import epdconfig
  31. # Display resolution
  32. EPD_WIDTH = 880
  33. EPD_HEIGHT = 528
  34. class EPD:
  35. def __init__(self):
  36. self.reset_pin = epdconfig.RST_PIN
  37. self.dc_pin = epdconfig.DC_PIN
  38. self.busy_pin = epdconfig.BUSY_PIN
  39. self.cs_pin = epdconfig.CS_PIN
  40. self.width = EPD_WIDTH
  41. self.height = EPD_HEIGHT
  42. # Hardware reset
  43. def reset(self):
  44. epdconfig.digital_write(self.reset_pin, 1)
  45. epdconfig.delay_ms(200)
  46. epdconfig.digital_write(self.reset_pin, 0)
  47. epdconfig.delay_ms(4)
  48. epdconfig.digital_write(self.reset_pin, 1)
  49. epdconfig.delay_ms(200)
  50. def send_command(self, command):
  51. epdconfig.digital_write(self.dc_pin, 0)
  52. epdconfig.digital_write(self.cs_pin, 0)
  53. epdconfig.spi_writebyte([command])
  54. epdconfig.digital_write(self.cs_pin, 1)
  55. def send_data(self, data):
  56. epdconfig.digital_write(self.dc_pin, 1)
  57. epdconfig.digital_write(self.cs_pin, 0)
  58. epdconfig.spi_writebyte([data])
  59. epdconfig.digital_write(self.cs_pin, 1)
  60. def ReadBusy(self):
  61. logging.debug("e-Paper busy")
  62. busy = epdconfig.digital_read(self.busy_pin)
  63. while(busy == 1):
  64. busy = epdconfig.digital_read(self.busy_pin)
  65. epdconfig.delay_ms(200)
  66. def init(self):
  67. if (epdconfig.module_init() != 0):
  68. return -1
  69. self.reset()
  70. self.send_command(0x12); #SWRESET
  71. self.ReadBusy(); #waiting for the electronic paper IC to release the idle signal
  72. self.send_command(0x46); # Auto Write RAM
  73. self.send_data(0xF7);
  74. self.ReadBusy(); #waiting for the electronic paper IC to release the idle signal
  75. self.send_command(0x47); # Auto Write RAM
  76. self.send_data(0xF7);
  77. self.ReadBusy(); #waiting for the electronic paper IC to release the idle signal
  78. self.send_command(0x0C); # Soft start setting
  79. self.send_data(0xAE);
  80. self.send_data(0xC7);
  81. self.send_data(0xC3);
  82. self.send_data(0xC0);
  83. self.send_data(0x40);
  84. self.send_command(0x01); # Set MUX as 527
  85. self.send_data(0xAF);
  86. self.send_data(0x02);
  87. self.send_data(0x01);
  88. self.send_command(0x11); # Data entry mode
  89. self.send_data(0x01);
  90. self.send_command(0x44);
  91. self.send_data(0x00); # RAM x address start at 0
  92. self.send_data(0x00);
  93. self.send_data(0x6F); # RAM x address end at 36Fh -> 879
  94. self.send_data(0x03);
  95. self.send_command(0x45);
  96. self.send_data(0xAF); # RAM y address start at 20Fh;
  97. self.send_data(0x02);
  98. self.send_data(0x00); # RAM y address end at 00h;
  99. self.send_data(0x00);
  100. self.send_command(0x3C); # VBD
  101. self.send_data(0x01); # LUT1, for white
  102. self.send_command(0x18);
  103. self.send_data(0X80);
  104. self.send_command(0x22);
  105. self.send_data(0XB1); #Load Temperature and waveform setting.
  106. self.send_command(0x20);
  107. self.ReadBusy(); #waiting for the electronic paper IC to release the idle signal
  108. self.send_command(0x4E);
  109. self.send_data(0x00);
  110. self.send_data(0x00);
  111. self.send_command(0x4F);
  112. self.send_data(0xAF);
  113. self.send_data(0x02);
  114. return 0
  115. def getbuffer(self, image):
  116. # logging.debug("bufsiz = ",int(self.width/8) * self.height)
  117. buf = [0xFF] * (int(self.width/8) * self.height)
  118. image_monocolor = image.convert('1')
  119. imwidth, imheight = image_monocolor.size
  120. pixels = image_monocolor.load()
  121. logging.debug('imwidth = %d imheight = %d ',imwidth, imheight)
  122. if(imwidth == self.width and imheight == self.height):
  123. logging.debug("Horizontal")
  124. for y in range(imheight):
  125. for x in range(imwidth):
  126. # Set the bits for the column of pixels at the current position.
  127. if pixels[x, y] == 0:
  128. buf[int((x + y * self.width) / 8)] &= ~(0x80 >> (x % 8))
  129. elif(imwidth == self.height and imheight == self.width):
  130. logging.debug("Vertical")
  131. for y in range(imheight):
  132. for x in range(imwidth):
  133. newx = y
  134. newy = self.height - x - 1
  135. if pixels[x, y] == 0:
  136. buf[int((newx + newy*self.width) / 8)] &= ~(0x80 >> (y % 8))
  137. return buf
  138. def display(self, imageblack, imagered):
  139. self.send_command(0x4F);
  140. self.send_data(0xAf);
  141. self.send_command(0x24)
  142. for i in range(0, int(self.width * self.height / 8)):
  143. self.send_data(imageblack[i]);
  144. self.send_command(0x26)
  145. for i in range(0, int(self.width * self.height / 8)):
  146. self.send_data(~imagered[i]);
  147. self.send_command(0x22);
  148. self.send_data(0xC7); #Load LUT from MCU(0x32)
  149. self.send_command(0x20);
  150. epdconfig.delay_ms(200); #!!!The delay here is necessary, 200uS at least!!!
  151. self.ReadBusy();
  152. def Clear(self):
  153. self.send_command(0x4F);
  154. self.send_data(0xAf);
  155. self.send_command(0x24)
  156. for i in range(0, int(self.width * self.height / 8)):
  157. self.send_data(0xff);
  158. self.send_command(0x26)
  159. for i in range(0, int(self.width * self.height / 8)):
  160. self.send_data(0x00);
  161. self.send_command(0x22);
  162. self.send_data(0xC7); #Load LUT from MCU(0x32)
  163. self.send_command(0x20);
  164. epdconfig.delay_ms(200); #!!!The delay here is necessary, 200uS at least!!!
  165. self.ReadBusy();
  166. def sleep(self):
  167. self.send_command(0x10); #deep sleep
  168. self.send_data(0x01);
  169. def Dev_exit(self):
  170. epdconfig.module_exit()
  171. ### END OF FILE ###