5662|1

1万

帖子

25

TA的资源

版主

楼主
 

micropython驱动微雪2.13寸墨水屏(电子纸) [复制链接]

 原帖:https://forum.micropython.org/viewtopic.php?t=6319&p=35965

  1. """
  2.         Example for 2.13 inch black & white & red Waveshare 2.13B E-ink screen
  3.         Run on ESP32 Waveshare driver board (software SPI)
  4.         Adapted by me -- April 2019
  5. """

  6. import epaper2in13b
  7. from machine import Pin, SPI

  8. # software SPI on ESP32 Waveshare driver board
  9. sck = Pin(13)
  10. mosi = Pin(14)
  11. cs = Pin(15)
  12. busy = Pin(25)
  13. rst = Pin(26)
  14. dc = Pin(27)
  15. # miso is not used but must be declared. Let's take any unused gpio: 12
  16. miso = Pin(12)
  17. spi = SPI(baudrate=100000, polarity=0, phase=0, sck=sck, mosi=mosi, miso=miso)

  18. e = epaper2in13b.EPD(spi, cs, dc, rst, busy)
  19. e.init()

  20. w = 104
  21. h = 212
  22. x = 0
  23. y = 0

  24. # --------------------

  25. # use a frame buffer
  26. # 212 * 104 / 8 = 2756 - that's some pixels
  27. import framebuf
  28. buf = bytearray(w * h // 8)
  29. fb = framebuf.FrameBuffer(buf, w, h, framebuf.MONO_HLSB)
  30. black = 0
  31. white = 1
  32. fb.fill(white)

  33. # --------------------

  34. # write hello world with black bg and white text

  35. # from toto import hello_world_dark

  36. from image_dark import hello_world_dark
  37. from image_light import hello_world_light
  38. print('Image dark')
  39. bufImage = hello_world_dark
  40. fbImage = framebuf.FrameBuffer(bufImage, 128, 296, framebuf.MONO_HLSB)
  41. fb.blit(fbImage, 20, 2)
  42. bufImage = hello_world_light
  43. fbImage = framebuf.FrameBuffer(bufImage, 128, 296, framebuf.MONO_HLSB)
  44. fb.blit(fbImage, 168, 2)
  45. # e.display_frame(buf)
  46. e.display_frame(buf, buf)

  47. # --------------------

  48. # write hello world with white bg and black text
  49. print('Image light')
  50. #e.display_frame(hello_world_light)

  51. # --------------------


  52. print('Frame buffer things')
  53. fb.fill(white)
  54. fb.text('Hello World',30,0,black)
  55. fb.pixel(30, 10, black)
  56. fb.hline(30, 30, 10, black)
  57. fb.vline(30, 50, 10, black)
  58. fb.line(30, 70, 40, 80, black)
  59. fb.rect(30, 90, 10, 10, black)
  60. fb.fill_rect(30, 110, 10, 10, black)
  61. for row in range(0,36):
  62.         fb.text(str(row),0,row*8,black)
  63. fb.text('Line 36',0,288,black)
  64. #e.display_frame(buf)
  65. e.display_frame(buf, buf)

  66. # --------------------

  67. # wrap text inside a box
  68. black = 0
  69. white = 1
  70. # clear
  71. fb.fill(white)
  72. # display as much as this as fits in the box
  73. str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vel neque in elit tristique vulputate at et dui. Maecenas nec felis lectus. Pellentesque sit amet facilisis dui. Maecenas ac arcu euismod, tempor massa quis, ultricies est.'

  74. # this could be useful as a new method in FrameBuffer
  75. def text_wrap(str,x,y,color,w,h,border=None):
  76.         # optional box border
  77.         if border is not None:
  78.                 fb.rect(x, y, w, h, border)
  79.         cols = w // 8
  80.         # for each row
  81.         j = 0
  82.         for i in range(0, len(str), cols):
  83.                 # draw as many chars fit on the line
  84.                 fb.text(str[i:i+cols], x, y + j, color)
  85.                 j += 8
  86.                 # dont overflow text outside the box
  87.                 if j >= h:
  88.                         break

  89. # clear
  90. fb.fill(white)

  91. # draw text box 1
  92. # box position and dimensions
  93. print('Box 1')
  94. bx = 8
  95. by = 8
  96. bw = 112 #  = 14 cols
  97. bh = 112 #  = 14 rows (196 chars in total)
  98. text_wrap(str,bx,by,black,bw,bh,black)
  99. #e.display_frame(buf)
  100. e.display_frame(buf, buf)

  101. # draw text box 2
  102. print('Box 2 & 3')
  103. bx = 0
  104. by = 128
  105. bw = w # 128 = 16 cols
  106. bh = 6 * 8 # 48 = 6 rows (96 chars in total)
  107. text_wrap(str,bx,by,black,bw,bh,black)

  108. # draw text box 3
  109. bx = 0
  110. by = 184
  111. bw = w//2 # 64 = 8 cols
  112. bh = 8 * 8 # 64 = 8 rows (64 chars in total)
  113. text_wrap(str,bx,by,black,bw,bh,None)
  114. #e.display_frame(buf)
  115. e.display_frame(buf, buf)

  116. # --------------------
复制代码




最新回复

牛xxxxx  详情 回复 发表于 2019-4-23 13:27
点赞 关注(1)
 
 

回复
举报

1903

帖子

0

TA的资源

版主

沙发
 
牛xxxxx
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/8 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表