epd7in5_HD.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. # *****************************************************************************
  2. # * | File : epd7in5.py
  3. # * | Author : Waveshare team
  4. # * | Function : Electronic paper driver
  5. # * | Info :
  6. # *----------------
  7. # * | This version: V4.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. logger = logging.getLogger(__name__)
  35. class EPD:
  36. def __init__(self):
  37. self.reset_pin = epdconfig.RST_PIN
  38. self.dc_pin = epdconfig.DC_PIN
  39. self.busy_pin = epdconfig.BUSY_PIN
  40. self.cs_pin = epdconfig.CS_PIN
  41. self.width = EPD_WIDTH
  42. self.height = EPD_HEIGHT
  43. # Hardware reset
  44. def reset(self):
  45. epdconfig.digital_write(self.reset_pin, 1)
  46. epdconfig.delay_ms(200)
  47. epdconfig.digital_write(self.reset_pin, 0)
  48. epdconfig.delay_ms(2)
  49. epdconfig.digital_write(self.reset_pin, 1)
  50. epdconfig.delay_ms(200)
  51. def send_command(self, command):
  52. epdconfig.digital_write(self.dc_pin, 0)
  53. epdconfig.digital_write(self.cs_pin, 0)
  54. epdconfig.spi_writebyte([command])
  55. epdconfig.digital_write(self.cs_pin, 1)
  56. def send_data(self, data):
  57. epdconfig.digital_write(self.dc_pin, 1)
  58. epdconfig.digital_write(self.cs_pin, 0)
  59. epdconfig.spi_writebyte([data])
  60. epdconfig.digital_write(self.cs_pin, 1)
  61. def send_data2(self, data):
  62. epdconfig.digital_write(self.dc_pin, 1)
  63. epdconfig.digital_write(self.cs_pin, 0)
  64. epdconfig.spi_writebyte2(data)
  65. epdconfig.digital_write(self.cs_pin, 1)
  66. def ReadBusy(self):
  67. logger.debug("e-Paper busy")
  68. busy = epdconfig.digital_read(self.busy_pin)
  69. while(busy == 1):
  70. busy = epdconfig.digital_read(self.busy_pin)
  71. epdconfig.delay_ms(200)
  72. def init(self):
  73. if (epdconfig.module_init() != 0):
  74. return -1
  75. # EPD hardware init start
  76. self.reset()
  77. self.ReadBusy();
  78. self.send_command(0x12); #SWRESET
  79. self.ReadBusy();
  80. self.send_command(0x46); # Auto Write Red RAM
  81. self.send_data(0xf7);
  82. self.ReadBusy();
  83. self.send_command(0x47); # Auto Write B/W RAM
  84. self.send_data(0xf7);
  85. self.ReadBusy();
  86. self.send_command(0x0C); # Soft start setting
  87. self.send_data2([0xAE, 0xC7, 0xC3, 0xC0, 0x40])
  88. self.send_command(0x01); # Set MUX as 527
  89. self.send_data2([0xAF, 0x02, 0x01])
  90. self.send_command(0x11); # Data entry mode
  91. self.send_data(0x01);
  92. self.send_command(0x44);
  93. self.send_data2([0x00, 0x00, 0x6F, 0x03]) # RAM x address start at 0
  94. self.send_command(0x45);
  95. self.send_data2([0xAF, 0x02, 0x00, 0x00])
  96. self.send_command(0x3C); # VBD
  97. self.send_data(0x05); # LUT1, for white
  98. self.send_command(0x18);
  99. self.send_data(0X80);
  100. self.send_command(0x22);
  101. self.send_data(0XB1); #Load Temperature and waveform setting.
  102. self.send_command(0x20);
  103. self.ReadBusy();
  104. self.send_command(0x4E); # set RAM x address count to 0;
  105. self.send_data2([0x00, 0x00])
  106. self.send_command(0x4F);
  107. self.send_data2([0x00, 0x00])
  108. # EPD hardware init end
  109. return 0
  110. def getbuffer(self, image):
  111. img = image
  112. imwidth, imheight = img.size
  113. if(imwidth == self.width and imheight == self.height):
  114. img = img.convert('1')
  115. elif(imwidth == self.height and imheight == self.width):
  116. img = img.rotate(90, expand=True).convert('1')
  117. else:
  118. logger.warning("Wrong image dimensions: must be " + str(self.width) + "x" + str(self.height))
  119. # return a blank buffer
  120. return [0xff] * int(self.width * self.height / 8)
  121. buf = bytearray(img.tobytes('raw'))
  122. return buf
  123. def display(self, image):
  124. self.send_command(0x4F);
  125. self.send_data2([0x00, 0x00])
  126. self.send_command(0x24);
  127. self.send_data2(image)
  128. self.send_command(0x22);
  129. self.send_data(0xF7);#Load LUT from MCU(0x32)
  130. self.send_command(0x20);
  131. epdconfig.delay_ms(10);
  132. self.ReadBusy();
  133. def Clear(self):
  134. buf = [0xff] * int(self.width * self.height / 8)
  135. self.send_command(0x4F);
  136. self.send_data2([0x00, 0x00])
  137. self.send_command(0x24)
  138. self.send_data2(buf)
  139. self.send_command(0x26)
  140. self.send_data2(buf)
  141. self.send_command(0x22);
  142. self.send_data(0xF7);#Load LUT from MCU(0x32)
  143. self.send_command(0x20);
  144. epdconfig.delay_ms(10);
  145. self.ReadBusy();
  146. def sleep(self):
  147. self.send_command(0x10);
  148. self.send_data(0x01);
  149. epdconfig.delay_ms(2000)
  150. epdconfig.module_exit()
  151. ### END OF FILE ###