GxEPD2_Example.ino 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139
  1. // Display Library example for SPI e-paper panels from Dalian Good Display and boards from Waveshare.
  2. // Requires HW SPI and Adafruit_GFX. Caution: these e-papers require 3.3V supply AND data lines!
  3. //
  4. // Display Library based on Demo Example from Good Display: http://www.e-paper-display.com/download_list/downloadcategoryid=34&isMode=false.html
  5. //
  6. // Author: Jean-Marc Zingg
  7. //
  8. // Version: see library.properties
  9. //
  10. // Library: https://github.com/ZinggJM/GxEPD2
  11. // Supporting Arduino Forum Topics:
  12. // Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
  13. // Good Dispay ePaper for Arduino: https://forum.arduino.cc/index.php?topic=436411.0
  14. // mapping suggestion from Waveshare SPI e-Paper to Wemos D1 mini
  15. // BUSY -> D2, RST -> D4, DC -> D3, CS -> D8, CLK -> D5, DIN -> D7, GND -> GND, 3.3V -> 3.3V
  16. // mapping suggestion from Waveshare SPI e-Paper to generic ESP8266
  17. // BUSY -> GPIO4, RST -> GPIO2, DC -> GPIO0, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
  18. // mapping of Waveshare e-Paper ESP8266 Driver Board
  19. // BUSY -> GPIO16, RST -> GPIO5, DC -> GPIO4, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
  20. // NOTE for ESP8266: using SS (GPIO15) for CS may cause boot mode problems, use different pin in case
  21. // mapping suggestion for ESP32, e.g. LOLIN32, see .../variants/.../pins_arduino.h for your board
  22. // NOTE: there are variants with different pins for SPI ! CHECK SPI PINS OF YOUR BOARD
  23. // BUSY -> 4, RST -> 16, DC -> 17, CS -> SS(5), CLK -> SCK(18), DIN -> MOSI(23), GND -> GND, 3.3V -> 3.3V
  24. // new mapping suggestion for STM32F1, e.g. STM32F103C8T6 "BluePill"
  25. // BUSY -> A1, RST -> A2, DC -> A3, CS-> A4, CLK -> A5, DIN -> A7
  26. // mapping suggestion for AVR, UNO, NANO etc.
  27. // BUSY -> 7, RST -> 9, DC -> 8, CS-> 10, CLK -> 13, DIN -> 11
  28. // mapping of Waveshare Universal e-Paper Raw Panel Driver Shield for Arduino / NUCLEO
  29. // BUSY -> 7, RST -> 8, DC -> 9, CS-> 10, CLK -> 13, DIN -> 11
  30. // mapping suggestion for Arduino MEGA
  31. // BUSY -> 7, RST -> 9, DC -> 8, CS-> 53, CLK -> 52, DIN -> 51
  32. // base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
  33. // enable or disable GxEPD2_GFX base class
  34. #define ENABLE_GxEPD2_GFX 0
  35. #include <GxEPD2_BW.h>
  36. #include <GxEPD2_3C.h>
  37. #include <Fonts/FreeMonoBold9pt7b.h>
  38. #if defined (ESP8266)
  39. // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
  40. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  41. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  42. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW0213I5F
  43. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  44. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW029T5
  45. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  46. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  47. // can use only half buffer size
  48. //GxEPD2_BW < GxEPD2_583, GxEPD2_583::HEIGHT / 2 > display(GxEPD2_583(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  49. //GxEPD2_BW < GxEPD2_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  50. // 3-color e-papers
  51. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  52. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  53. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  54. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  55. // can use only half buffer size
  56. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT / 2> display(GxEPD2_420c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  57. // can use only quarter buffer size
  58. //GxEPD2_3C < GxEPD2_583c, GxEPD2_583c::HEIGHT / 4 > display(GxEPD2_583c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  59. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT / 4> display(GxEPD2_750c(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  60. // ***** for mapping of Waveshare e-Paper ESP8266 Driver Board *****
  61. // select one , can use full buffer size (full HEIGHT)
  62. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  63. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  64. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEW0213I5F
  65. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  66. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEW029T5
  67. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  68. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  69. // can use only half buffer size
  70. //GxEPD2_BW < GxEPD2_583, GxEPD2_583::HEIGHT / 2 > display(GxEPD2_583(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  71. //GxEPD2_BW < GxEPD2_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  72. // 3-color e-papers
  73. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  74. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  75. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  76. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  77. // can use only half buffer size
  78. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT / 2> display(GxEPD2_420c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  79. // can use only quarter buffer size
  80. //GxEPD2_3C<GxEPD2_583c, GxEPD2_583c::HEIGHT / 4> display(GxEPD2_583c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  81. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT / 4> display(GxEPD2_750c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  82. #endif
  83. #if defined(ESP32)
  84. // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
  85. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  86. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  87. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW0213I5F
  88. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  89. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW029T5
  90. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  91. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  92. //GxEPD2_BW<GxEPD2_750, GxEPD2_750::HEIGHT> display(GxEPD2_750(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  93. // 3-color e-papers
  94. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  95. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  96. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  97. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  98. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT> display(GxEPD2_420c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  99. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT> display(GxEPD2_750c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  100. #endif
  101. #if defined(_BOARD_GENERIC_STM32F103C_H_)
  102. #define MAX_DISPAY_BUFFER_SIZE 15000ul // ~15k is a good compromise
  103. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8))
  104. // select one and adapt to your mapping
  105. //GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  106. //GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  107. //GxEPD2_BW<GxEPD2_213_flex, MAX_HEIGHT(GxEPD2_213_flex)> display(GxEPD2_213_flex(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW0213I5F
  108. //GxEPD2_BW<GxEPD2_290, MAX_HEIGHT(GxEPD2_290)> display(GxEPD2_290(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  109. //GxEPD2_BW<GxEPD2_290_T5, MAX_HEIGHT(GxEPD2_290_T5)> display(GxEPD2_290_T5(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW029T5
  110. //GxEPD2_BW<GxEPD2_270, MAX_HEIGHT(GxEPD2_270)> display(GxEPD2_270(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  111. //GxEPD2_BW<GxEPD2_420, MAX_HEIGHT(GxEPD2_420)> display(GxEPD2_420(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  112. //GxEPD2_BW<GxEPD2_583, MAX_HEIGHT(GxEPD2_583)> display(GxEPD2_583(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  113. //GxEPD2_BW<GxEPD2_750, MAX_HEIGHT(GxEPD2_750)> display(GxEPD2_750(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  114. // 3-color e-papers
  115. #define MAX_HEIGHT_3C(EPD) (EPD::HEIGHT <= (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
  116. //GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT_3C(GxEPD2_154c)> display(GxEPD2_154c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  117. //GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT_3C(GxEPD2_213c)> display(GxEPD2_213c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  118. //GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT_3C(GxEPD2_290c)> display(GxEPD2_290c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  119. //GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT_3C(GxEPD2_270c)> display(GxEPD2_270c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  120. //GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT_3C(GxEPD2_420c)> display(GxEPD2_420c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  121. //GxEPD2_3C<GxEPD2_583c, MAX_HEIGHT_3C(GxEPD2_583c)> display(GxEPD2_583c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  122. //GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT_3C(GxEPD2_750c)> display(GxEPD2_750c(/*CS=4*/ SS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  123. #endif
  124. #if defined(__AVR)
  125. #define MAX_DISPAY_BUFFER_SIZE 800 //
  126. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPAY_BUFFER_SIZE / (EPD::WIDTH / 8))
  127. // select one and adapt to your mapping
  128. //GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  129. //GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  130. //GxEPD2_BW<GxEPD2_213_flex, MAX_HEIGHT(GxEPD2_213_flex)> display(GxEPD2_213_flex(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7)); // GDEW0213I5F
  131. //GxEPD2_BW<GxEPD2_290, MAX_HEIGHT(GxEPD2_290)> display(GxEPD2_290(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  132. //GxEPD2_BW<GxEPD2_290_T5, MAX_HEIGHT(GxEPD2_290_T5)> display(GxEPD2_290_T5(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7)); // GDEW029T5
  133. //GxEPD2_BW<GxEPD2_270, MAX_HEIGHT(GxEPD2_270)> display(GxEPD2_270(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  134. //GxEPD2_BW<GxEPD2_420, MAX_HEIGHT(GxEPD2_420)> display(GxEPD2_420(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  135. //GxEPD2_BW<GxEPD2_583, MAX_HEIGHT(GxEPD2_583)> display(GxEPD2_583(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  136. //GxEPD2_BW<GxEPD2_750, MAX_HEIGHT(GxEPD2_750)> display(GxEPD2_750(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  137. // 3-color e-papers
  138. #define MAX_HEIGHT_3C(EPD) (EPD::HEIGHT <= (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
  139. //GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT_3C(GxEPD2_154c)> display(GxEPD2_154c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  140. //GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT_3C(GxEPD2_213c)> display(GxEPD2_213c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  141. //GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT_3C(GxEPD2_290c)> display(GxEPD2_290c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  142. //GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT_3C(GxEPD2_270c)> display(GxEPD2_270c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  143. //GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT_3C(GxEPD2_420c)> display(GxEPD2_420c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  144. //GxEPD2_3C<GxEPD2_583c, MAX_HEIGHT_3C(GxEPD2_583c)> display(GxEPD2_583c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  145. //GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT_3C(GxEPD2_750c)> display(GxEPD2_750c(/*CS=10*/ SS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  146. // ***** for mapping of Waveshare Universal e-Paper Raw Panel Driver Shield for Arduino / NUCLEO *****
  147. // CAUTION: the RST line is not connected through level converter! This may damage the display and/or cause malfunction. use -1 for RST parameter
  148. // select one and adapt to your mapping
  149. //GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ -1, /*BUSY=*/ 7));
  150. //GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ -1, /*BUSY=*/ 7));
  151. //GxEPD2_BW<GxEPD2_213_flex, MAX_HEIGHT(GxEPD2_213_flex)> display(GxEPD2_213_flex(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ -1, /*BUSY=*/ 7)); // GDEW0213I5F
  152. //GxEPD2_BW<GxEPD2_290, MAX_HEIGHT(GxEPD2_290)> display(GxEPD2_290(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ -1, /*BUSY=*/ 7));
  153. //GxEPD2_BW<GxEPD2_290_T5, MAX_HEIGHT(GxEPD2_290_T5)> display(GxEPD2_290_T5(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ -1, /*BUSY=*/ 7)); // GDEW029T5
  154. //GxEPD2_BW<GxEPD2_270, MAX_HEIGHT(GxEPD2_270)> display(GxEPD2_270(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ -1, /*BUSY=*/ 7));
  155. //GxEPD2_BW<GxEPD2_420, MAX_HEIGHT(GxEPD2_420)> display(GxEPD2_420(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ -1, /*BUSY=*/ 7));
  156. //GxEPD2_BW<GxEPD2_583, MAX_HEIGHT(GxEPD2_583)> display(GxEPD2_583(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ -1, /*BUSY=*/ 7));
  157. //GxEPD2_BW<GxEPD2_750, MAX_HEIGHT(GxEPD2_750)> display(GxEPD2_750(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ -1, /*BUSY=*/ 7));
  158. // 3-color e-papers
  159. #define MAX_HEIGHT_3C(EPD) (EPD::HEIGHT <= (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
  160. //GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT_3C(GxEPD2_154c)> display(GxEPD2_154c(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ -1, /*BUSY=*/ 7));
  161. //GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT_3C(GxEPD2_213c)> display(GxEPD2_213c(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ -1, /*BUSY=*/ 7));
  162. //GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT_3C(GxEPD2_290c)> display(GxEPD2_290c(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ -1, /*BUSY=*/ 7));
  163. //GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT_3C(GxEPD2_270c)> display(GxEPD2_270c(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ -1, /*BUSY=*/ 7));
  164. //GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT_3C(GxEPD2_420c)> display(GxEPD2_420c(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ -1, /*BUSY=*/ 7));
  165. //GxEPD2_3C<GxEPD2_583c, MAX_HEIGHT_3C(GxEPD2_583c)> display(GxEPD2_583c(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ -1, /*BUSY=*/ 7));
  166. //GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT_3C(GxEPD2_750c)> display(GxEPD2_750c(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ -1, /*BUSY=*/ 7));
  167. #endif
  168. #include "GxEPD2_boards_added.h"
  169. //#include "GxEPD2_more_boards_added.h" // private
  170. #if !defined(__AVR) && !defined(_BOARD_GENERIC_STM32F103C_H_)
  171. // comment out unused bitmaps to reduce code space used
  172. #include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
  173. #include "bitmaps/Bitmaps128x250.h" // 2.13" b/w
  174. #include "bitmaps/Bitmaps128x296.h" // 2.9" b/w
  175. #include "bitmaps/Bitmaps176x264.h" // 2.7" b/w
  176. #include "bitmaps/Bitmaps400x300.h" // 4.2" b/w
  177. #include "bitmaps/Bitmaps640x384.h" // 7.5" b/w
  178. // 3-color
  179. #include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
  180. #include "bitmaps/Bitmaps3c104x212.h" // 2.13" b/w/r
  181. #include "bitmaps/Bitmaps3c128x296.h" // 2.9" b/w/r
  182. #include "bitmaps/Bitmaps3c176x264.h" // 2.7" b/w/r
  183. #include "bitmaps/Bitmaps3c400x300.h" // 4.2" b/w/r
  184. #else
  185. // select only one to fit in code space
  186. #include "bitmaps/Bitmaps200x200.h" // 1.54" b/w
  187. //#include "bitmaps/Bitmaps128x250.h" // 2.13" b/w
  188. //#include "bitmaps/Bitmaps128x296.h" // 2.9" b/w
  189. //#include "bitmaps/Bitmaps176x264.h" // 2.7" b/w
  190. ////#include "bitmaps/Bitmaps400x300.h" // 4.2" b/w // not enough code space
  191. ////#include "bitmaps/Bitmaps640x384.h" // 7.5" b/w // not enough code space
  192. // 3-color
  193. //#include "bitmaps/Bitmaps3c200x200.h" // 1.54" b/w/r
  194. //#include "bitmaps/Bitmaps3c104x212.h" // 2.13" b/w/r
  195. //#include "bitmaps/Bitmaps3c128x296.h" // 2.9" b/w/r
  196. //#include "bitmaps/Bitmaps3c176x264.h" // 2.7" b/w/r
  197. ////#include "bitmaps/Bitmaps3c400x300.h" // 4.2" b/w/r // not enough code space
  198. #endif
  199. void setup()
  200. {
  201. Serial.begin(115200);
  202. Serial.println();
  203. Serial.println("setup");
  204. display.init(115200);
  205. // first update should be full refresh
  206. helloWorld();
  207. delay(1000);
  208. // partial refresh mode can be used to full screen,
  209. // effective if display panel hasFastPartialUpdate
  210. helloFullScreenPartialMode();
  211. delay(1000);
  212. helloArduino();
  213. delay(1000);
  214. helloEpaper();
  215. delay(1000);
  216. showFont("FreeMonoBold9pt7b", &FreeMonoBold9pt7b);
  217. delay(1000);
  218. drawBitmaps();
  219. if (display.epd2.hasPartialUpdate)
  220. {
  221. showPartialUpdate();
  222. delay(1000);
  223. } // else // on GDEW0154Z04 only full update available, doesn't look nice
  224. //drawCornerTest();
  225. //showBox(16, 16, 48, 32, false);
  226. //showBox(16, 56, 48, 32, true);
  227. display.powerOff();
  228. deepSleepTest();
  229. Serial.println("setup done");
  230. }
  231. void loop()
  232. {
  233. }
  234. const char HelloWorld[] = "Hello World!";
  235. const char HelloArduino[] = "Hello Arduino!";
  236. const char HelloEpaper[] = "Hello E-Paper!";
  237. void helloWorld()
  238. {
  239. //Serial.println("helloWorld");
  240. display.setRotation(1);
  241. display.setFont(&FreeMonoBold9pt7b);
  242. display.setTextColor(GxEPD_BLACK);
  243. int16_t tbx, tby; uint16_t tbw, tbh;
  244. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  245. uint16_t x = (display.width() - tbw) / 2;
  246. uint16_t y = (display.height() + tbh) / 2; // y is base line!
  247. display.setFullWindow();
  248. display.firstPage();
  249. do
  250. {
  251. display.fillScreen(GxEPD_WHITE);
  252. display.setCursor(x, y);
  253. display.print(HelloWorld);
  254. }
  255. while (display.nextPage());
  256. //Serial.println("helloWorld done");
  257. }
  258. void helloWorldForDummies()
  259. {
  260. //Serial.println("helloWorld");
  261. const char text[] = "Hello World!";
  262. // most e-papers have width < height (portrait) as native orientation, especially the small ones
  263. // in GxEPD2 rotation 0 is used for native orientation (most TFT libraries use 0 fix for portrait orientation)
  264. // set rotation to 1 (rotate right 90 degrees) to have enough space on small displays (landscape)
  265. display.setRotation(1);
  266. // select a suitable font in Adafruit_GFX
  267. display.setFont(&FreeMonoBold9pt7b);
  268. // on e-papers black on white is more pleasant to read
  269. display.setTextColor(GxEPD_BLACK);
  270. // Adafruit_GFX has a handy method getTextBounds() to determine the boundary box for a text for the actual font
  271. int16_t tbx, tby; uint16_t tbw, tbh; // boundary box window
  272. display.getTextBounds(text, 0, 0, &tbx, &tby, &tbw, &tbh); // it works for 0, 0, fortunately (negative tby!)
  273. // center the boundary box of the text
  274. uint16_t x = (display.width() - tbw) / 2;
  275. uint16_t y = (display.height() + tbh) / 2; // y is base line!
  276. // full window mode is the initial mode, set it anyway
  277. display.setFullWindow();
  278. // here we use paged drawing, even if the processor has enough RAM for full buffer
  279. // so this can be used with any supported processor board.
  280. // the cost in code overhead and execution time penalty is marginal
  281. // tell the graphics class to use paged drawing mode
  282. display.firstPage();
  283. do
  284. {
  285. // this part of code is executed multiple times, as many as needed,
  286. // in case of full buffer it is executed once
  287. // IMPORTANT: each iteration needs to draw the same, to avoid strange effects
  288. // use a copy of values that might change, don't read e.g. from analog or pins in the loop!
  289. display.fillScreen(GxEPD_WHITE); // set the background to white (fill the buffer with value for white)
  290. display.setCursor(x, y); // set the postition to start printing text
  291. display.print(text); // print some text
  292. // end of part executed multiple times
  293. }
  294. // tell the graphics class to transfer the buffer content (page) to the controller buffer
  295. // the graphics class will command the controller to refresh to the screen when the last page has been transferred
  296. // returns true if more pages need be drawn and transferred
  297. // returns false if the last page has been transferred and the screen refreshed for panels without fast partial update
  298. // returns false for panels with fast partial update when the controller buffer has been written once more, to make the differential buffers equal
  299. // (for full buffered with fast partial update the (full) buffer is just transferred again, and false returned)
  300. while (display.nextPage());
  301. //Serial.println("helloWorld done");
  302. }
  303. void helloFullScreenPartialMode()
  304. {
  305. //Serial.println("helloFullScreenPartialMode");
  306. const char fullscreen[] = "full screen update";
  307. const char fpm[] = "fast partial mode";
  308. const char spm[] = "slow partial mode";
  309. const char npm[] = "no partial mode";
  310. display.setPartialWindow(0, 0, display.width(), display.height());
  311. display.setRotation(1);
  312. display.setFont(&FreeMonoBold9pt7b);
  313. display.setTextColor(GxEPD_BLACK);
  314. const char* updatemode;
  315. if (display.epd2.hasFastPartialUpdate)
  316. {
  317. updatemode = fpm;
  318. }
  319. else if (display.epd2.hasPartialUpdate)
  320. {
  321. updatemode = spm;
  322. }
  323. else
  324. {
  325. updatemode = npm;
  326. }
  327. // do this outside of the loop
  328. int16_t tbx, tby; uint16_t tbw, tbh;
  329. // center update text
  330. display.getTextBounds(fullscreen, 0, 0, &tbx, &tby, &tbw, &tbh);
  331. uint16_t utx = (display.width() - tbw) / 2;
  332. // center update mode
  333. display.getTextBounds(updatemode, 0, 0, &tbx, &tby, &tbw, &tbh);
  334. uint16_t umx = (display.width() - tbw) / 2;
  335. // center HelloWorld
  336. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  337. uint16_t hwx = (display.width() - tbw) / 2;
  338. uint16_t y;
  339. display.firstPage();
  340. do
  341. {
  342. display.fillScreen(GxEPD_WHITE);
  343. y = (display.height() + tbh) / 2; // y is base line!
  344. display.setCursor(hwx, y);
  345. display.print(HelloWorld);
  346. y = display.height() / 4 + tbh / 2; // y is base line!
  347. display.setCursor(utx, y);
  348. display.print(fullscreen);
  349. y = display.height() * 3 / 4 + tbh / 2; // y is base line!
  350. display.setCursor(umx, y);
  351. display.print(updatemode);
  352. }
  353. while (display.nextPage());
  354. //Serial.println("helloFullScreenPartialMode done");
  355. }
  356. void helloArduino()
  357. {
  358. //Serial.println("helloArduino");
  359. display.setRotation(1);
  360. display.setFont(&FreeMonoBold9pt7b);
  361. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  362. int16_t tbx, tby; uint16_t tbw, tbh;
  363. // align with centered HelloWorld
  364. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  365. uint16_t x = (display.width() - tbw) / 2;
  366. // height might be different
  367. display.getTextBounds(HelloArduino, 0, 0, &tbx, &tby, &tbw, &tbh);
  368. uint16_t y = display.height() / 4 + tbh / 2; // y is base line!
  369. // make the window big enough to cover (overwrite) descenders of previous text
  370. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  371. display.setPartialWindow(0, y - tbh, display.width(), wh);
  372. display.firstPage();
  373. do
  374. {
  375. display.fillScreen(GxEPD_WHITE);
  376. //display.drawRect(x, y - tbh, tbw, tbh, GxEPD_BLACK);
  377. display.setCursor(x, y);
  378. display.print(HelloArduino);
  379. }
  380. while (display.nextPage());
  381. delay(1000);
  382. //Serial.println("helloArduino done");
  383. }
  384. void helloEpaper()
  385. {
  386. //Serial.println("helloEpaper");
  387. display.setRotation(1);
  388. display.setFont(&FreeMonoBold9pt7b);
  389. display.setTextColor(display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK);
  390. int16_t tbx, tby; uint16_t tbw, tbh;
  391. // align with centered HelloWorld
  392. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  393. uint16_t x = (display.width() - tbw) / 2;
  394. // height might be different
  395. display.getTextBounds(HelloEpaper, 0, 0, &tbx, &tby, &tbw, &tbh);
  396. uint16_t y = display.height() * 3 / 4 + tbh / 2; // y is base line!
  397. // make the window big enough to cover (overwrite) descenders of previous text
  398. uint16_t wh = FreeMonoBold9pt7b.yAdvance;
  399. display.setPartialWindow(0, y - tbh, display.width(), wh);
  400. display.firstPage();
  401. do
  402. {
  403. display.fillScreen(GxEPD_WHITE);
  404. display.setCursor(x, y);
  405. display.print(HelloEpaper);
  406. }
  407. while (display.nextPage());
  408. //Serial.println("helloEpaper done");
  409. }
  410. void deepSleepTest()
  411. {
  412. //Serial.println("deepSleepTest");
  413. const char hibernating[] = "hibernating ...";
  414. const char wokeup[] = "woke up from deep sleep";
  415. const char again[] = "hibernating again ...";
  416. display.setRotation(1);
  417. display.setFont(&FreeMonoBold9pt7b);
  418. display.setTextColor(GxEPD_BLACK);
  419. int16_t tbx, tby; uint16_t tbw, tbh;
  420. // center text
  421. display.getTextBounds(hibernating, 0, 0, &tbx, &tby, &tbw, &tbh);
  422. uint16_t x = (display.width() - tbw) / 2;
  423. uint16_t y = (display.height() + tbh) / 2; // y is base line!
  424. display.setFullWindow();
  425. display.firstPage();
  426. do
  427. {
  428. display.fillScreen(GxEPD_WHITE);
  429. display.setCursor(x, y);
  430. display.print(hibernating);
  431. }
  432. while (display.nextPage());
  433. display.hibernate();
  434. delay(5000);
  435. display.getTextBounds(wokeup, 0, 0, &tbx, &tby, &tbw, &tbh);
  436. x = (display.width() - tbw) / 2;
  437. display.firstPage();
  438. do
  439. {
  440. display.fillScreen(GxEPD_WHITE);
  441. display.setCursor(x, y);
  442. display.print(wokeup);
  443. }
  444. while (display.nextPage());
  445. delay(5000);
  446. display.getTextBounds(again, 0, 0, &tbx, &tby, &tbw, &tbh);
  447. x = (display.width() - tbw) / 2;
  448. display.firstPage();
  449. do
  450. {
  451. display.fillScreen(GxEPD_WHITE);
  452. display.setCursor(x, y);
  453. display.print(again);
  454. }
  455. while (display.nextPage());
  456. display.hibernate();
  457. //Serial.println("deepSleepTest done");
  458. }
  459. void showBox(uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool partial)
  460. {
  461. //Serial.println("showBox");
  462. display.setRotation(1);
  463. if (partial)
  464. {
  465. display.setPartialWindow(x, y, w, h);
  466. }
  467. else
  468. {
  469. display.setFullWindow();
  470. }
  471. display.firstPage();
  472. do
  473. {
  474. display.fillScreen(GxEPD_WHITE);
  475. display.fillRect(x, y, w, h, GxEPD_BLACK);
  476. }
  477. while (display.nextPage());
  478. //Serial.println("showBox done");
  479. }
  480. void drawCornerTest()
  481. {
  482. display.setFullWindow();
  483. display.setFont(&FreeMonoBold9pt7b);
  484. display.setTextColor(GxEPD_BLACK);
  485. for (uint16_t r = 0; r <= 4; r++)
  486. {
  487. display.setRotation(r);
  488. display.firstPage();
  489. do
  490. {
  491. display.fillScreen(GxEPD_WHITE);
  492. display.fillRect(0, 0, 8, 8, GxEPD_BLACK);
  493. display.fillRect(display.width() - 18, 0, 16, 16, GxEPD_BLACK);
  494. display.fillRect(display.width() - 25, display.height() - 25, 24, 24, GxEPD_BLACK);
  495. display.fillRect(0, display.height() - 33, 32, 32, GxEPD_BLACK);
  496. display.setCursor(display.width() / 2, display.height() / 2);
  497. display.print(display.getRotation());
  498. }
  499. while (display.nextPage());
  500. delay(2000);
  501. }
  502. }
  503. void showFont(const char name[], const GFXfont* f)
  504. {
  505. display.setFullWindow();
  506. display.setRotation(0);
  507. display.setTextColor(GxEPD_BLACK);
  508. display.firstPage();
  509. do
  510. {
  511. drawFont(name, f);
  512. }
  513. while (display.nextPage());
  514. }
  515. void drawFont(const char name[], const GFXfont* f)
  516. {
  517. //display.setRotation(0);
  518. display.fillScreen(GxEPD_WHITE);
  519. display.setTextColor(GxEPD_BLACK);
  520. display.setFont(f);
  521. display.setCursor(0, 0);
  522. display.println();
  523. display.println(name);
  524. display.println(" !\"#$%&'()*+,-./");
  525. display.println("0123456789:;<=>?");
  526. display.println("@ABCDEFGHIJKLMNO");
  527. display.println("PQRSTUVWXYZ[\\]^_");
  528. if (display.epd2.hasColor)
  529. {
  530. display.setTextColor(GxEPD_RED);
  531. }
  532. display.println("`abcdefghijklmno");
  533. display.println("pqrstuvwxyz{|}~ ");
  534. }
  535. void showPartialUpdate()
  536. {
  537. // some useful background
  538. helloWorld();
  539. // use asymmetric values for test
  540. uint16_t box_x = 10;
  541. uint16_t box_y = 15;
  542. uint16_t box_w = 70;
  543. uint16_t box_h = 20;
  544. uint16_t cursor_y = box_y + box_h - 6;
  545. float value = 13.95;
  546. uint16_t incr = display.epd2.hasFastPartialUpdate ? 1 : 3;
  547. display.setFont(&FreeMonoBold9pt7b);
  548. display.setTextColor(GxEPD_BLACK);
  549. // show where the update box is
  550. for (uint16_t r = 0; r < 4; r++)
  551. {
  552. display.setRotation(r);
  553. display.setPartialWindow(box_x, box_y, box_w, box_h);
  554. display.firstPage();
  555. do
  556. {
  557. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_BLACK);
  558. //display.fillScreen(GxEPD_BLACK);
  559. }
  560. while (display.nextPage());
  561. delay(2000);
  562. display.firstPage();
  563. do
  564. {
  565. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  566. }
  567. while (display.nextPage());
  568. delay(1000);
  569. }
  570. //return;
  571. // show updates in the update box
  572. for (uint16_t r = 0; r < 4; r++)
  573. {
  574. display.setRotation(r);
  575. display.setPartialWindow(box_x, box_y, box_w, box_h);
  576. for (uint16_t i = 1; i <= 10; i += incr)
  577. {
  578. display.firstPage();
  579. do
  580. {
  581. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  582. display.setCursor(box_x, cursor_y);
  583. display.print(value * i, 2);
  584. }
  585. while (display.nextPage());
  586. delay(500);
  587. }
  588. delay(1000);
  589. display.firstPage();
  590. do
  591. {
  592. display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
  593. }
  594. while (display.nextPage());
  595. delay(1000);
  596. }
  597. }
  598. void drawBitmaps()
  599. {
  600. display.setFullWindow();
  601. #ifdef _GxBitmaps128x250_H_
  602. drawBitmaps128x250();
  603. #endif
  604. #ifdef _GxBitmaps128x296_H_
  605. drawBitmaps128x296();
  606. #endif
  607. #ifdef _GxBitmaps176x264_H_
  608. drawBitmaps176x264();
  609. #endif
  610. #ifdef _GxBitmaps400x300_H_
  611. drawBitmaps400x300();
  612. #endif
  613. #ifdef _GxBitmaps640x384_H_
  614. drawBitmaps640x384();
  615. #endif
  616. // 3-color
  617. #ifdef _GxBitmaps3c104x212_H_
  618. drawBitmaps3c104x212();
  619. #endif
  620. #ifdef _GxBitmaps3c128x296_H_
  621. drawBitmaps3c128x296();
  622. #endif
  623. #ifdef _GxBitmaps3c176x264_H_
  624. drawBitmaps3c176x264();
  625. #endif
  626. #ifdef _GxBitmaps3c400x300_H_
  627. drawBitmaps3c400x300();
  628. #endif
  629. // show these after the specific bitmaps
  630. #ifdef _GxBitmaps200x200_H_
  631. drawBitmaps200x200();
  632. #endif
  633. // 3-color
  634. #ifdef _GxBitmaps3c200x200_H_
  635. drawBitmaps3c200x200();
  636. #endif
  637. }
  638. #ifdef _GxBitmaps200x200_H_
  639. void drawBitmaps200x200()
  640. {
  641. #if defined(__AVR)
  642. const unsigned char* bitmaps[] =
  643. {
  644. logo200x200, first200x200 //, second200x200, third200x200, fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
  645. };
  646. #elif defined(_BOARD_GENERIC_STM32F103C_H_)
  647. const unsigned char* bitmaps[] =
  648. {
  649. logo200x200, first200x200, second200x200, third200x200, fourth200x200, fifth200x200 //, sixth200x200, senventh200x200, eighth200x200
  650. };
  651. #else
  652. const unsigned char* bitmaps[] =
  653. {
  654. logo200x200, first200x200, second200x200, third200x200, fourth200x200, fifth200x200, sixth200x200, senventh200x200, eighth200x200
  655. };
  656. #endif
  657. if (display.epd2.panel == GxEPD2::GDEP015OC1)
  658. {
  659. bool m = display.mirror(true);
  660. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  661. {
  662. display.firstPage();
  663. do
  664. {
  665. display.fillScreen(GxEPD_WHITE);
  666. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  667. }
  668. while (display.nextPage());
  669. delay(2000);
  670. }
  671. display.mirror(m);
  672. }
  673. //else
  674. {
  675. bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
  676. display.clearScreen(); // use default for white
  677. int16_t x = (int16_t(display.epd2.WIDTH) - 200) / 2;
  678. int16_t y = (int16_t(display.epd2.HEIGHT) - 200) / 2;
  679. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  680. {
  681. display.drawImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  682. delay(2000);
  683. }
  684. }
  685. bool mirror_y = (display.epd2.panel != GxEPD2::GDE0213B1);
  686. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  687. {
  688. int16_t x = -60;
  689. int16_t y = -60;
  690. for (uint16_t j = 0; j < 10; j++)
  691. {
  692. display.writeScreenBuffer(); // use default for white
  693. display.writeImage(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  694. display.refresh(true);
  695. if ((display.epd2.hasFastPartialUpdate) && (display.epd2.panel == GxEPD2::GDEW027W3))
  696. {
  697. // for differential update: set previous buffer equal to current (IL91874 doesn't switch on refresh)
  698. // display.writeScreenBuffer(); // above is enough for the other controllers
  699. display.epd2.writeImageAgain(bitmaps[i], x, y, 200, 200, false, mirror_y, true);
  700. }
  701. delay(2000);
  702. x += 40;
  703. y += 40;
  704. if ((x >= int16_t(display.epd2.WIDTH)) || (y >= int16_t(display.epd2.HEIGHT))) break;
  705. }
  706. if (!display.epd2.hasFastPartialUpdate) break; // comment out for full show
  707. break; // comment out for full show
  708. }
  709. display.writeScreenBuffer(); // use default for white
  710. display.writeImage(bitmaps[0], int16_t(0), 0, 200, 200, false, mirror_y, true);
  711. display.writeImage(bitmaps[0], int16_t(int16_t(display.epd2.WIDTH) - 200), int16_t(display.epd2.HEIGHT) - 200, 200, 200, false, mirror_y, true);
  712. display.refresh(true);
  713. delay(2000);
  714. }
  715. #endif
  716. #ifdef _GxBitmaps128x250_H_
  717. void drawBitmaps128x250()
  718. {
  719. #if !defined(__AVR)
  720. const unsigned char* bitmaps[] =
  721. {
  722. Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
  723. };
  724. #else
  725. const unsigned char* bitmaps[] =
  726. {
  727. Bitmap128x250_1, logo128x250, first128x250, second128x250, third128x250
  728. };
  729. #endif
  730. if (display.epd2.panel == GxEPD2::GDE0213B1)
  731. {
  732. bool m = display.mirror(true);
  733. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  734. {
  735. display.firstPage();
  736. do
  737. {
  738. display.fillScreen(GxEPD_WHITE);
  739. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  740. }
  741. while (display.nextPage());
  742. delay(2000);
  743. }
  744. display.mirror(m);
  745. }
  746. }
  747. #endif
  748. #ifdef _GxBitmaps128x296_H_
  749. void drawBitmaps128x296()
  750. {
  751. #if !defined(__AVR)
  752. const unsigned char* bitmaps[] =
  753. {
  754. Bitmap128x296_1, logo128x296, first128x296, second128x296, third128x296
  755. };
  756. #else
  757. const unsigned char* bitmaps[] =
  758. {
  759. Bitmap128x296_1, logo128x296 //, first128x296, second128x296, third128x296
  760. };
  761. #endif
  762. if (display.epd2.panel == GxEPD2::GDEH029A1)
  763. {
  764. bool m = display.mirror(true);
  765. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  766. {
  767. display.firstPage();
  768. do
  769. {
  770. display.fillScreen(GxEPD_WHITE);
  771. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  772. }
  773. while (display.nextPage());
  774. delay(2000);
  775. }
  776. display.mirror(m);
  777. }
  778. }
  779. #endif
  780. #ifdef _GxBitmaps176x264_H_
  781. void drawBitmaps176x264()
  782. {
  783. #if !defined(__AVR)
  784. const unsigned char* bitmaps[] =
  785. {
  786. Bitmap176x264_1, Bitmap176x264_2, Bitmap176x264_3, Bitmap176x264_4, Bitmap176x264_5
  787. };
  788. #else
  789. const unsigned char* bitmaps[] =
  790. {
  791. Bitmap176x264_1, Bitmap176x264_2 //, Bitmap176x264_3, Bitmap176x264_4, Bitmap176x264_5
  792. };
  793. #endif
  794. if (display.epd2.panel == GxEPD2::GDEW027W3)
  795. {
  796. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  797. {
  798. display.firstPage();
  799. do
  800. {
  801. display.fillScreen(GxEPD_WHITE);
  802. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  803. }
  804. while (display.nextPage());
  805. delay(2000);
  806. }
  807. }
  808. }
  809. #endif
  810. #ifdef _GxBitmaps400x300_H_
  811. void drawBitmaps400x300()
  812. {
  813. #if !defined(__AVR)
  814. const unsigned char* bitmaps[] =
  815. {
  816. Bitmap400x300_1, Bitmap400x300_2
  817. };
  818. #else
  819. const unsigned char* bitmaps[] = {}; // not enough code space
  820. #endif
  821. if (display.epd2.panel == GxEPD2::GDEW042T2)
  822. {
  823. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  824. {
  825. display.firstPage();
  826. do
  827. {
  828. display.fillScreen(GxEPD_WHITE);
  829. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  830. }
  831. while (display.nextPage());
  832. delay(2000);
  833. }
  834. }
  835. }
  836. #endif
  837. #ifdef _GxBitmaps640x384_H_
  838. void drawBitmaps640x384()
  839. {
  840. #if !defined(__AVR)
  841. const unsigned char* bitmaps[] =
  842. {
  843. Bitmap640x384_1, Bitmap640x384_2
  844. };
  845. #else
  846. const unsigned char* bitmaps[] = {}; // not enough code space
  847. #endif
  848. if ((display.epd2.panel == GxEPD2::GDEW075T8) || (display.epd2.panel == GxEPD2::GDEW075Z09))
  849. {
  850. for (uint16_t i = 0; i < sizeof(bitmaps) / sizeof(char*); i++)
  851. {
  852. display.firstPage();
  853. do
  854. {
  855. display.fillScreen(GxEPD_WHITE);
  856. display.drawInvertedBitmap(0, 0, bitmaps[i], display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  857. }
  858. while (display.nextPage());
  859. delay(2000);
  860. }
  861. }
  862. }
  863. #endif
  864. struct bitmap_pair
  865. {
  866. const unsigned char* black;
  867. const unsigned char* red;
  868. };
  869. #ifdef _GxBitmaps3c200x200_H_
  870. void drawBitmaps3c200x200()
  871. {
  872. bitmap_pair bitmap_pairs[] =
  873. {
  874. //{Bitmap3c200x200_black, Bitmap3c200x200_red},
  875. {WS_Bitmap3c200x200_black, WS_Bitmap3c200x200_red}
  876. };
  877. if (display.epd2.panel == GxEPD2::GDEW0154Z04)
  878. {
  879. display.firstPage();
  880. do
  881. {
  882. display.fillScreen(GxEPD_WHITE);
  883. // Bitmap3c200x200_black has 2 bits per pixel
  884. // taken from Adafruit_GFX.cpp, modified
  885. int16_t byteWidth = (display.epd2.WIDTH + 7) / 8; // Bitmap scanline pad = whole byte
  886. uint8_t byte = 0;
  887. for (int16_t j = 0; j < display.epd2.HEIGHT; j++)
  888. {
  889. for (int16_t i = 0; i < display.epd2.WIDTH; i++)
  890. {
  891. if (i & 3) byte <<= 2;
  892. else
  893. {
  894. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  895. byte = pgm_read_byte(&Bitmap3c200x200_black[j * byteWidth * 2 + i / 4]);
  896. #else
  897. byte = Bitmap3c200x200_black[j * byteWidth * 2 + i / 4];
  898. #endif
  899. }
  900. if (!(byte & 0x80))
  901. {
  902. display.drawPixel(i, j, GxEPD_BLACK);
  903. }
  904. }
  905. }
  906. display.drawInvertedBitmap(0, 0, Bitmap3c200x200_red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  907. }
  908. while (display.nextPage());
  909. delay(2000);
  910. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  911. {
  912. display.firstPage();
  913. do
  914. {
  915. display.fillScreen(GxEPD_WHITE);
  916. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  917. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  918. }
  919. while (display.nextPage());
  920. delay(2000);
  921. }
  922. }
  923. if (display.epd2.hasColor)
  924. {
  925. display.clearScreen(); // use default for white
  926. int16_t x = (int16_t(display.epd2.WIDTH) - 200) / 2;
  927. int16_t y = (int16_t(display.epd2.HEIGHT) - 200) / 2;
  928. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  929. {
  930. display.drawImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
  931. delay(2000);
  932. }
  933. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  934. {
  935. int16_t x = -60;
  936. int16_t y = -60;
  937. for (uint16_t j = 0; j < 10; j++)
  938. {
  939. display.writeScreenBuffer(); // use default for white
  940. display.writeImage(bitmap_pairs[i].black, bitmap_pairs[i].red, x, y, 200, 200, false, false, true);
  941. display.refresh();
  942. delay(2000);
  943. x += 40;
  944. y += 40;
  945. if ((x >= int16_t(display.epd2.WIDTH)) || (y >= int16_t(display.epd2.HEIGHT))) break;
  946. }
  947. }
  948. display.writeScreenBuffer(); // use default for white
  949. display.writeImage(bitmap_pairs[0].black, bitmap_pairs[0].red, 0, 0, 200, 200, false, false, true);
  950. display.writeImage(bitmap_pairs[0].black, bitmap_pairs[0].red, int16_t(display.epd2.WIDTH) - 200, int16_t(display.epd2.HEIGHT) - 200, 200, 200, false, false, true);
  951. display.refresh();
  952. delay(2000);
  953. }
  954. }
  955. #endif
  956. #ifdef _GxBitmaps3c104x212_H_
  957. void drawBitmaps3c104x212()
  958. {
  959. #if !defined(__AVR)
  960. bitmap_pair bitmap_pairs[] =
  961. {
  962. {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
  963. {Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
  964. {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
  965. };
  966. #else
  967. bitmap_pair bitmap_pairs[] =
  968. {
  969. {Bitmap3c104x212_1_black, Bitmap3c104x212_1_red},
  970. //{Bitmap3c104x212_2_black, Bitmap3c104x212_2_red},
  971. {WS_Bitmap3c104x212_black, WS_Bitmap3c104x212_red}
  972. };
  973. #endif
  974. if (display.epd2.panel == GxEPD2::GDEW0213Z16)
  975. {
  976. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  977. {
  978. display.firstPage();
  979. do
  980. {
  981. display.fillScreen(GxEPD_WHITE);
  982. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  983. if (bitmap_pairs[i].red == WS_Bitmap3c104x212_red)
  984. {
  985. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  986. }
  987. else display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  988. }
  989. while (display.nextPage());
  990. delay(2000);
  991. }
  992. }
  993. }
  994. #endif
  995. #ifdef _GxBitmaps3c128x296_H_
  996. void drawBitmaps3c128x296()
  997. {
  998. #if !defined(__AVR)
  999. bitmap_pair bitmap_pairs[] =
  1000. {
  1001. {Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
  1002. {Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
  1003. {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
  1004. };
  1005. #else
  1006. bitmap_pair bitmap_pairs[] =
  1007. {
  1008. //{Bitmap3c128x296_1_black, Bitmap3c128x296_1_red},
  1009. //{Bitmap3c128x296_2_black, Bitmap3c128x296_2_red},
  1010. {WS_Bitmap3c128x296_black, WS_Bitmap3c128x296_red}
  1011. };
  1012. #endif
  1013. if (display.epd2.panel == GxEPD2::GDEW029Z10)
  1014. {
  1015. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1016. {
  1017. display.firstPage();
  1018. do
  1019. {
  1020. display.fillScreen(GxEPD_WHITE);
  1021. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1022. if (bitmap_pairs[i].red == WS_Bitmap3c128x296_red)
  1023. {
  1024. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1025. }
  1026. else display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1027. }
  1028. while (display.nextPage());
  1029. delay(2000);
  1030. }
  1031. }
  1032. }
  1033. #endif
  1034. #ifdef _GxBitmaps3c176x264_H_
  1035. void drawBitmaps3c176x264()
  1036. {
  1037. bitmap_pair bitmap_pairs[] =
  1038. {
  1039. {Bitmap3c176x264_black, Bitmap3c176x264_red}
  1040. };
  1041. if (display.epd2.panel == GxEPD2::GDEW027C44)
  1042. {
  1043. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1044. {
  1045. display.firstPage();
  1046. do
  1047. {
  1048. display.fillScreen(GxEPD_WHITE);
  1049. display.drawBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1050. display.drawBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1051. }
  1052. while (display.nextPage());
  1053. delay(2000);
  1054. }
  1055. }
  1056. }
  1057. #endif
  1058. #ifdef _GxBitmaps3c400x300_H_
  1059. void drawBitmaps3c400x300()
  1060. {
  1061. #if !defined(__AVR)
  1062. bitmap_pair bitmap_pairs[] =
  1063. {
  1064. {Bitmap3c400x300_1_black, Bitmap3c400x300_1_red},
  1065. {Bitmap3c400x300_2_black, Bitmap3c400x300_2_red},
  1066. {WS_Bitmap3c400x300_black, WS_Bitmap3c400x300_red}
  1067. };
  1068. #else
  1069. bitmap_pair bitmap_pairs[] = {}; // not enough code space
  1070. #endif
  1071. if (display.epd2.panel == GxEPD2::GDEW042Z15)
  1072. {
  1073. for (uint16_t i = 0; i < sizeof(bitmap_pairs) / sizeof(bitmap_pair); i++)
  1074. {
  1075. display.firstPage();
  1076. do
  1077. {
  1078. display.fillScreen(GxEPD_WHITE);
  1079. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].black, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_BLACK);
  1080. display.drawInvertedBitmap(0, 0, bitmap_pairs[i].red, display.epd2.WIDTH, display.epd2.HEIGHT, GxEPD_RED);
  1081. }
  1082. while (display.nextPage());
  1083. delay(2000);
  1084. }
  1085. }
  1086. }
  1087. #endif