GxEPD2_Example.ino 44 KB

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