GxEPD2_SD_Example.ino 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. // GxEPD2_SD_Example : Display Library example for SPI e-paper panels from Dalian Good Display and boards from Waveshare.
  2. // Requires HW SPI and Adafruit_GFX. Caution: the e-paper panels 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. // BMP handling code extracts taken from: https://github.com/prenticedavid/MCUFRIEND_kbv/tree/master/examples/showBMP_kbv_Uno
  7. //
  8. // Author: Jean-Marc Zingg
  9. //
  10. // Version: see library.properties
  11. //
  12. // Library: https://github.com/ZinggJM/GxEPD2
  13. //
  14. // note that BMP bitmaps are drawn at physical position in physical orientation of the screen
  15. // Supporting Arduino Forum Topics:
  16. // Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
  17. // Good Display ePaper for Arduino: https://forum.arduino.cc/index.php?topic=436411.0
  18. // mapping suggestion from Waveshare SPI e-Paper to Wemos D1 mini
  19. // BUSY -> D2, RST -> D4, DC -> D3, CS -> D8, CLK -> D5, DIN -> D7, GND -> GND, 3.3V -> 3.3V
  20. // NOTE: connect 3.3k pull-down from D8 to GND if your board or shield has level converters
  21. // NOTE for ESP8266: using SS (GPIO15) for CS may cause boot mode problems, use different pin in case, or 4k7 pull-down
  22. // mapping suggestion from Waveshare SPI e-Paper to generic ESP8266
  23. // BUSY -> GPIO4, RST -> GPIO2, DC -> GPIO0, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
  24. // NOTE: connect 3.3k pull-down from GPIO15 to GND if your board or shield has level converters
  25. // NOTE for ESP8266: using SS (GPIO15) for CS may cause boot mode problems, use different pin in case, or 3.3k pull-down
  26. // mapping of Waveshare e-Paper ESP8266 Driver Board, new version (see GxEPD2_boards_added.h for old version)
  27. // BUSY -> GPIO5, RST -> GPIO2, DC -> GPIO4, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
  28. // NOTE for ESP8266: using SS (GPIO15) for CS may cause boot mode problems, add a 3.3k pull-down in case
  29. // the e-Paper ESP8266 Driver Board should have no boot mode issue, as it doesn't use level converters
  30. // mapping suggestion for ESP32, e.g. LOLIN32, see .../variants/.../pins_arduino.h for your board
  31. // NOTE: there are variants with different pins for SPI ! CHECK SPI PINS OF YOUR BOARD
  32. // BUSY -> 4, RST -> 16, DC -> 17, CS -> SS(5), CLK -> SCK(18), DIN -> MOSI(23), GND -> GND, 3.3V -> 3.3V
  33. // mapping of Waveshare ESP32 Driver Board
  34. // BUSY -> 25, RST -> 26, DC -> 27, CS-> 15, CLK -> 13, DIN -> 14
  35. // NOTE: this board uses "unusual" SPI pins and requires re-mapping of HW SPI to these pins in SPIClass
  36. // see example GxEPD2_WS_ESP32_Driver.ino, it shows how this can be done easily
  37. // new mapping suggestion for STM32F1, e.g. STM32F103C8T6 "BluePill"
  38. // BUSY -> A1, RST -> A2, DC -> A3, CS-> A4, CLK -> A5, DIN -> A7
  39. // mapping suggestion for AVR, UNO, NANO etc.
  40. // BUSY -> 7, RST -> 9, DC -> 8, CS-> 10, CLK -> 13, DIN -> 11
  41. // mapping of Waveshare Universal e-Paper Raw Panel Driver Shield for Arduino / NUCLEO
  42. // BUSY -> 7, RST -> 8, DC -> 9, CS-> 10, CLK -> 13, DIN -> 11
  43. // mapping suggestion for Arduino MEGA
  44. // BUSY -> 7, RST -> 9, DC -> 8, CS-> 53, CLK -> 52, DIN -> 51
  45. // **** NOTE that the mapping suggestion may need modification depending on SD board used! ****
  46. // ********************************************************************************************
  47. //
  48. //#define SD_CS SS // e.g. for RobotDyn Wemos D1 mini SD board
  49. //#define EPD_CS D1 // alternative I use with RobotDyn Wemos D1 mini SD board
  50. // base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
  51. // enable or disable GxEPD2_GFX base class
  52. #define ENABLE_GxEPD2_GFX 0
  53. // uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX
  54. //#include <GFX.h>
  55. // Note: if you use this with ENABLE_GxEPD2_GFX 1:
  56. // uncomment it in GxEPD2_GFX.h too, or add #include <GFX.h> before any #include <GxEPD2_GFX.h>
  57. #include <GxEPD2_BW.h>
  58. #include <GxEPD2_3C.h>
  59. #include <GxEPD2_7C.h>
  60. #include <Fonts/FreeMonoBold9pt7b.h>
  61. #if defined(ESP32)
  62. // has support for FAT32 support with long filenames
  63. #include "FS.h"
  64. #include "SD.h"
  65. #include "SPI.h"
  66. #define SdFile File
  67. #define seekSet seek
  68. #else
  69. // include SdFat for FAT32 support with long filenames; available through Library Manager
  70. #include <SdFat.h>
  71. SdFat SD;
  72. #endif
  73. #if defined (ESP8266)
  74. #define SD_CS SS // e.g. for RobotDyn Wemos D1 mini SD board
  75. #define EPD_CS D1 // alternative I use with RobotDyn Wemos D1 mini SD board
  76. // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
  77. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEP015OC1 no longer available
  78. //GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEH0154D67
  79. //GxEPD2_BW<GxEPD2_154_T8, GxEPD2_154_T8::HEIGHT> display(GxEPD2_154_T8(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW0154T8 152x152
  80. //GxEPD2_BW<GxEPD2_154_M09, GxEPD2_154_M09::HEIGHT> display(GxEPD2_154_M09(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW0154M09 200x200
  81. //GxEPD2_BW<GxEPD2_154_M10, GxEPD2_154_M10::HEIGHT> display(GxEPD2_154_M10(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW0154M10 152x152
  82. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  83. //GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEH0213B72
  84. //GxEPD2_BW<GxEPD2_213_B73, GxEPD2_213_B73::HEIGHT> display(GxEPD2_213_B73(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEH0213B73
  85. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW0213I5F
  86. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  87. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW029T5
  88. //GxEPD2_BW<GxEPD2_260, GxEPD2_260::HEIGHT> display(GxEPD2_260(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  89. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  90. //GxEPD2_BW<GxEPD2_371, GxEPD2_371::HEIGHT> display(GxEPD2_371(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  91. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  92. // can use only half buffer size
  93. //GxEPD2_BW < GxEPD2_583, GxEPD2_583::HEIGHT / 2 > display(GxEPD2_583(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  94. //GxEPD2_BW < GxEPD2_583_T8, GxEPD2_583_T8::HEIGHT / 2 > display(GxEPD2_583_T8(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  95. //GxEPD2_BW < GxEPD2_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  96. //GxEPD2_BW < GxEPD2_750_T7, GxEPD2_750_T7::HEIGHT / 2 > display(GxEPD2_750_T7(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW075T7 800x480
  97. // 3-color e-papers
  98. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW0154Z04 no longer available
  99. //GxEPD2_3C<GxEPD2_154_Z90c, GxEPD2_154_Z90c::HEIGHT> display(GxEPD2_154_Z90c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEH0154Z90
  100. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  101. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  102. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  103. // can use only half buffer size
  104. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT / 2> display(GxEPD2_420c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  105. // can use only quarter buffer size
  106. //GxEPD2_3C<GxEPD2_583c, GxEPD2_583c::HEIGHT / 4> display(GxEPD2_583c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  107. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT / 4> display(GxEPD2_750c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  108. //GxEPD2_3C < GxEPD2_750c_Z08, GxEPD2_750c_Z08::HEIGHT / 4 > display(GxEPD2_750c_Z08(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW075Z08 800x480
  109. //GxEPD2_3C < GxEPD2_750c_Z90, GxEPD2_750c_Z90::HEIGHT / 4 > display(GxEPD2_750c_Z90(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEH075Z90 880x528
  110. // 7-color e-paper
  111. //GxEPD2_3C < GxEPD2_565c, GxEPD2_565c::HEIGHT / 4 > display(GxEPD2_565c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // Waveshare 5.65" 7-color (3C graphics)
  112. //GxEPD2_7C < GxEPD2_565c, GxEPD2_565c::HEIGHT / 4 > display(GxEPD2_565c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // Waveshare 5.65" 7-color
  113. // grey levels parallel IF e-papers on Waveshare e-Paper IT8951 Driver HAT
  114. // HRDY -> 4, RST -> 2, CS -> SS(15), SCK -> SCK(14), MOSI -> MOSI(D7(13)), MISO -> MISO(D6(12)), GND -> GND, 5V -> 5V
  115. // note: 5V supply needs to be exact and strong; 5V pin of USB powered Wemos D1 mini doesn't work!
  116. //GxEPD2_BW<GxEPD2_it60, GxEPD2_it60::HEIGHT / 8> display(GxEPD2_it60(/*CS=5*/ EPD_CS, /*DC=*/ 0, /*RST=*/ 2, /*BUSY=*/ 4));
  117. // ***** for mapping of Waveshare e-Paper ESP8266 Driver Board *****
  118. // select one , can use full buffer size (full HEIGHT)
  119. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEP015OC1 no longer available
  120. //GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEH0154D67
  121. //GxEPD2_BW<GxEPD2_154_T8, GxEPD2_154_T8::HEIGHT> display(GxEPD2_154_T8(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEW0154T8 152x152
  122. //GxEPD2_BW<GxEPD2_154_M09, GxEPD2_154_M09::HEIGHT> display(GxEPD2_154_M09(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEW0154M09 200x200
  123. //GxEPD2_BW<GxEPD2_154_M10, GxEPD2_154_M10::HEIGHT> display(GxEPD2_154_M10(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEW0154M10 152x152
  124. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDE0213B1, phased out
  125. //GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEH0213B72
  126. //GxEPD2_BW<GxEPD2_213_B73, GxEPD2_213_B73::HEIGHT> display(GxEPD2_213_B73(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEH0213B73
  127. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEW0213I5F
  128. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  129. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEW029T5
  130. //GxEPD2_BW<GxEPD2_260, GxEPD2_260::HEIGHT> display(GxEPD2_260(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  131. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  132. //GxEPD2_BW<GxEPD2_371, GxEPD2_371::HEIGHT> display(GxEPD2_371(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  133. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  134. // can use only half buffer size
  135. //GxEPD2_BW < GxEPD2_583, GxEPD2_583::HEIGHT / 2 > display(GxEPD2_583(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  136. //GxEPD2_BW < GxEPD2_583_T8, GxEPD2_583_T8::HEIGHT / 2 > display(GxEPD2_583_T8(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  137. //GxEPD2_BW < GxEPD2_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  138. //GxEPD2_BW < GxEPD2_750_T7, GxEPD2_750_T7::HEIGHT / 2 > display(GxEPD2_750_T7(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEW075T7 800x480
  139. // 3-color e-papers
  140. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEW0154Z04 no longer available
  141. //GxEPD2_3C<GxEPD2_154_Z90c, GxEPD2_154_Z90c::HEIGHT> display(GxEPD2_154_Z90c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEH0154Z90
  142. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  143. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  144. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  145. // can use only half buffer size
  146. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT / 2> display(GxEPD2_420c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  147. // can use only quarter buffer size
  148. //GxEPD2_3C<GxEPD2_583c, GxEPD2_583c::HEIGHT / 4> display(GxEPD2_583c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  149. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT / 4> display(GxEPD2_750c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  150. //GxEPD2_3C<GxEPD2_750c_Z08, GxEPD2_750c_Z08::HEIGHT / 4> display(GxEPD2_750c_Z08(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEW075Z08 800x480
  151. //GxEPD2_3C<GxEPD2_750c_Z90, GxEPD2_750c_Z90::HEIGHT / 4> display(GxEPD2_750c_Z90(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEH075Z90 880x528
  152. // 7-color e-paper
  153. //GxEPD2_7C < GxEPD2_565c, GxEPD2_565c::HEIGHT / 4 > display(GxEPD2_565c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // Waveshare 5.65" 7-color
  154. #endif
  155. #if defined(ESP32)
  156. #define SD_CS 2 // adapt to your wiring
  157. #define EPD_CS SS // adapt to your wiring
  158. // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
  159. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEP015OC1 no longer available
  160. //GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0154D67
  161. //GxEPD2_BW<GxEPD2_154_T8, GxEPD2_154_T8::HEIGHT> display(GxEPD2_154_T8(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW0154T8 152x152
  162. //GxEPD2_BW<GxEPD2_154_M09, GxEPD2_154_M09::HEIGHT> display(GxEPD2_154_M09(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW0154M09 200x200
  163. //GxEPD2_BW<GxEPD2_154_M10, GxEPD2_154_M10::HEIGHT> display(GxEPD2_154_M10(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW0154M10 152x152
  164. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDE0213B1, phased out
  165. //GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0213B72
  166. //GxEPD2_BW<GxEPD2_213_B73, GxEPD2_213_B73::HEIGHT> display(GxEPD2_213_B73(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0213B73
  167. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW0213I5F
  168. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  169. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW029T5
  170. //GxEPD2_BW<GxEPD2_260, GxEPD2_260::HEIGHT> display(GxEPD2_260(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  171. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  172. //GxEPD2_BW<GxEPD2_371, GxEPD2_371::HEIGHT> display(GxEPD2_371(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  173. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  174. //GxEPD2_BW<GxEPD2_583, GxEPD2_583::HEIGHT> display(GxEPD2_583(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  175. //GxEPD2_BW<GxEPD2_583_T8, GxEPD2_583_T8::HEIGHT> display(GxEPD2_583_T8(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  176. //GxEPD2_BW<GxEPD2_750, GxEPD2_750::HEIGHT> display(GxEPD2_750(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  177. //GxEPD2_BW<GxEPD2_750_T7, GxEPD2_750_T7::HEIGHT> display(GxEPD2_750_T7(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW075T7 800x480
  178. // 3-color e-papers
  179. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW0154Z04 no longer available
  180. //GxEPD2_3C<GxEPD2_154_Z90c, GxEPD2_154_Z90c::HEIGHT> display(GxEPD2_154_Z90c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0154Z90
  181. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  182. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  183. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  184. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT> display(GxEPD2_420c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  185. //GxEPD2_3C<GxEPD2_583c, GxEPD2_583c::HEIGHT> display(GxEPD2_583c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  186. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT> display(GxEPD2_750c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  187. //GxEPD2_3C<GxEPD2_750c_Z08, GxEPD2_750c_Z08::HEIGHT> display(GxEPD2_750c_Z08(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW075Z08 800x480
  188. //GxEPD2_3C<GxEPD2_750c_Z90, GxEPD2_750c_Z90::HEIGHT / 2> display(GxEPD2_750c_Z90(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH075Z90 880x528
  189. // 7-color e-paper
  190. //GxEPD2_7C < GxEPD2_565c, GxEPD2_565c::HEIGHT / 2 > display(GxEPD2_565c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // Waveshare 5.65" 7-color
  191. // grey levels parallel IF e-papers on Waveshare e-Paper IT8951 Driver HAT
  192. // HRDY -> 4, RST -> 16, CS -> SS(5), SCK -> SCK(18), MOSI -> MOSI(23), MISO -> MISO(19), GND -> GND, 5V -> 5V
  193. // note: 5V supply needs to be exact and strong; 5V over diode from USB (e.g. Wemos D1 mini) doesn't work!
  194. //GxEPD2_BW<GxEPD2_it60, GxEPD2_it60::HEIGHT> display(GxEPD2_it60(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  195. // Waveshare 12.48 b/w SPI display board and frame or Good Display 12.48 b/w panel GDEW1248T3
  196. // general constructor for use with all parameters, e.g. for Waveshare ESP32 driver board mounted on connection board
  197. //GxEPD2_BW < GxEPD2_1248, GxEPD2_1248::HEIGHT / 4 >
  198. //display(GxEPD2_1248(/*sck=*/ 13, /*miso=*/ 12, /*mosi=*/ 14, /*cs_m1=*/ 23, /*cs_s1=*/ 22, /*cs_m2=*/ 16, /*cs_s2=*/ 19,
  199. // /*dc1=*/ 25, /*dc2=*/ 17, /*rst1=*/ 33, /*rst2=*/ 5, /*busy_m1=*/ 32, /*busy_s1=*/ 26, /*busy_m2=*/ 18, /*busy_s2=*/ 4));
  200. #endif
  201. // can't use package "STMF1 Boards (STM32Duino.com)" (Roger Clark) anymore with Adafruit_GFX, use "STM32 Boards (selected from submenu)" (STMicroelectronics)
  202. #if defined(ARDUINO_ARCH_STM32)
  203. #define SD_CS 0 // adapt to your wiring
  204. #define EPD_CS SS // adapt to your wiring
  205. #define MAX_DISPLAY_BUFFER_SIZE 15000ul // ~15k is a good compromise
  206. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8))
  207. // select one and adapt to your mapping
  208. //GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEP015OC1 no longer available
  209. //GxEPD2_BW<GxEPD2_154_D67, MAX_HEIGHT(GxEPD2_154_D67)> display(GxEPD2_154_D67(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEH0154D67
  210. //GxEPD2_BW<GxEPD2_154_T8, MAX_HEIGHT(GxEPD2_154_T8)> display(GxEPD2_154_T8(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW0154T8 152x152
  211. //GxEPD2_BW<GxEPD2_154_M09, MAX_HEIGHT(GxEPD2_154_M09)> display(GxEPD2_154_M09(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW0154M09 200x200
  212. //GxEPD2_BW<GxEPD2_154_M10, MAX_HEIGHT(GxEPD2_154_M10)> display(GxEPD2_154_M10(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW0154M10 152x152
  213. //GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDE0213B1, phased out
  214. //GxEPD2_BW<GxEPD2_213_B72, MAX_HEIGHT(GxEPD2_213_B72)> display(GxEPD2_213_B72(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEH0213B72
  215. //GxEPD2_BW<GxEPD2_213_B73, MAX_HEIGHT(GxEPD2_213_B73)> display(GxEPD2_213_B73(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEH0213B73
  216. //GxEPD2_BW<GxEPD2_213_flex, MAX_HEIGHT(GxEPD2_213_flex)> display(GxEPD2_213_flex(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW0213I5F
  217. //GxEPD2_BW<GxEPD2_290, MAX_HEIGHT(GxEPD2_290)> display(GxEPD2_290(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  218. //GxEPD2_BW<GxEPD2_290_T5, MAX_HEIGHT(GxEPD2_290_T5)> display(GxEPD2_290_T5(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW029T5
  219. //GxEPD2_BW<GxEPD2_260, MAX_HEIGHT(GxEPD2_260)> display(GxEPD2_260(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  220. //GxEPD2_BW<GxEPD2_270, MAX_HEIGHT(GxEPD2_270)> display(GxEPD2_270(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  221. //GxEPD2_BW<GxEPD2_371, MAX_HEIGHT(GxEPD2_371)> display(GxEPD2_371(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  222. //GxEPD2_BW<GxEPD2_420, MAX_HEIGHT(GxEPD2_420)> display(GxEPD2_420(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  223. //GxEPD2_BW<GxEPD2_583, MAX_HEIGHT(GxEPD2_583)> display(GxEPD2_583(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  224. //GxEPD2_BW <GxEPD2_583_T8, MAX_HEIGHT(GxEPD2_583_T8)> display(GxEPD2_583_T8(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  225. //GxEPD2_BW<GxEPD2_750, MAX_HEIGHT(GxEPD2_750)> display(GxEPD2_750(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  226. //GxEPD2_BW<GxEPD2_750_T7, MAX_HEIGHT(GxEPD2_750_T7)> display(GxEPD2_750_T7(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW075T7 800x480
  227. // 3-color e-papers
  228. #define MAX_HEIGHT_3C(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
  229. //GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT_3C(GxEPD2_154c)> display(GxEPD2_154c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW0154Z04 no longer available
  230. //GxEPD2_3C<GxEPD2_154_Z90c, MAX_HEIGHT_3C(GxEPD2_154_Z90c)> display(GxEPD2_154_Z90c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEH0154Z90
  231. //GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT_3C(GxEPD2_213c)> display(GxEPD2_213c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  232. //GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT_3C(GxEPD2_290c)> display(GxEPD2_290c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  233. //GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT_3C(GxEPD2_270c)> display(GxEPD2_270c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  234. //GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT_3C(GxEPD2_420c)> display(GxEPD2_420c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  235. //GxEPD2_3C<GxEPD2_583c, MAX_HEIGHT_3C(GxEPD2_583c)> display(GxEPD2_583c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  236. //GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT_3C(GxEPD2_750c)> display(GxEPD2_750c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  237. //GxEPD2_3C<GxEPD2_750c_Z08, MAX_HEIGHT_3C(GxEPD2_750c_Z08)> display(GxEPD2_750c_Z08(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW075Z08 800x480
  238. //GxEPD2_3C<GxEPD2_750c_Z90, MAX_HEIGHT_3C(GxEPD2_750c_Z90)> display(GxEPD2_750c_Z90(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEH075Z90 880x528
  239. // 7-color e-paper
  240. #define MAX_HEIGHT_7C(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2)) // 2 pixel per byte
  241. //GxEPD2_7C<GxEPD2_565c, MAX_HEIGHT_7C(GxEPD2_565c)> display(GxEPD2_565c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // Waveshare 5.65" 7-color
  242. #endif
  243. #if defined(__AVR)
  244. #define SD_CS 6 // adapt to your wiring
  245. #define EPD_CS SS // adapt to your wiring
  246. // most AVR Arduinos have not enough RAM for use with SD and buffered graphics
  247. // !!! use GxEPD2_SD_AVR_Example.ino instead !!!
  248. //GxEPD2_154 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7);
  249. #endif
  250. // function declaration with default parameter
  251. // note that BMP bitmaps are drawn at physical position in physical orientation of the screen
  252. void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_color = true);
  253. // bitmap drawing using buffered graphics, e.g. for small bitmaps or for GxEPD2_154c
  254. // draws BMP bitmap according to set orientation
  255. // partial_update selects refresh mode (not effective for GxEPD2_154c)
  256. // overwrite = true does not clear buffer before drawing, use only if buffer is full height
  257. void drawBitmapFromSD_Buffered(const char *filename, int16_t x, int16_t y, bool with_color = true, bool partial_update = false, bool overwrite = false);
  258. void setup()
  259. {
  260. Serial.begin(115200);
  261. Serial.println();
  262. Serial.println("GxEPD2_SD_Example");
  263. display.init(115200);
  264. Serial.print("Initializing SD card...");
  265. if (!SD.begin(SD_CS))
  266. {
  267. Serial.println("SD failed!");
  268. return;
  269. }
  270. Serial.println("SD OK!");
  271. if ((display.epd2.panel == GxEPD2::GDEW0154Z04) || false)
  272. {
  273. drawBitmapsBuffered_200x200();
  274. drawBitmapsBuffered_other();
  275. }
  276. else
  277. {
  278. drawBitmaps_200x200();
  279. drawBitmaps_other();
  280. }
  281. //drawBitmaps_test();
  282. //drawBitmapsBuffered_test();
  283. Serial.println("GxEPD2_SD_Example done");
  284. }
  285. void loop(void)
  286. {
  287. }
  288. void drawBitmaps_200x200()
  289. {
  290. int16_t x = (display.width() - 200) / 2;
  291. int16_t y = (display.height() - 200) / 2;
  292. drawBitmapFromSD("logo200x200.bmp", x, y);
  293. delay(2000);
  294. drawBitmapFromSD("first200x200.bmp", x, y);
  295. delay(2000);
  296. drawBitmapFromSD("second200x200.bmp", x, y);
  297. delay(2000);
  298. drawBitmapFromSD("third200x200.bmp", x, y);
  299. delay(2000);
  300. drawBitmapFromSD("fourth200x200.bmp", x, y);
  301. delay(2000);
  302. drawBitmapFromSD("fifth200x200.bmp", x, y);
  303. delay(2000);
  304. drawBitmapFromSD("sixth200x200.bmp", x, y);
  305. delay(2000);
  306. drawBitmapFromSD("seventh200x200.bmp", x, y);
  307. delay(2000);
  308. drawBitmapFromSD("eighth200x200.bmp", x, y);
  309. delay(2000);
  310. }
  311. void drawBitmaps_other()
  312. {
  313. int16_t w2 = display.width() / 2;
  314. int16_t h2 = display.height() / 2;
  315. drawBitmapFromSD("parrot.bmp", w2 - 64, h2 - 80);
  316. delay(2000);
  317. drawBitmapFromSD("betty_1.bmp", w2 - 100, h2 - 160);
  318. delay(2000);
  319. drawBitmapFromSD("betty_4.bmp", w2 - 102, h2 - 126);
  320. delay(2000);
  321. drawBitmapFromSD("marilyn_240x240x8.bmp", w2 - 120, h2 - 120);
  322. delay(2000);
  323. drawBitmapFromSD("miniwoof.bmp", w2 - 60, h2 - 80);
  324. delay(2000);
  325. drawBitmapFromSD("t200x200.bmp", w2 - 100, h2 - 100);
  326. delay(2000);
  327. drawBitmapFromSD("test.bmp", w2 - 120, h2 - 160);
  328. delay(2000);
  329. drawBitmapFromSD("tiger.bmp", w2 - 160, h2 - 120);
  330. delay(2000);
  331. drawBitmapFromSD("tiger_178x160x4.bmp", w2 - 89, h2 - 80);
  332. delay(2000);
  333. drawBitmapFromSD("tiger_240x317x4.bmp", w2 - 120, h2 - 160);
  334. delay(2000);
  335. drawBitmapFromSD("tiger_320x200x24.bmp", w2 - 160, h2 - 100);
  336. delay(2000);
  337. drawBitmapFromSD("tiger16T.bmp", w2 - 160, h2 - 120);
  338. delay(2000);
  339. drawBitmapFromSD("woof.bmp", w2 - 120, h2 - 160);
  340. delay(2000);
  341. drawBitmapFromSD("bitmap640x384_1.bmp", 0, 0);
  342. delay(2000);
  343. }
  344. void drawBitmaps_test()
  345. {
  346. int16_t w2 = display.width() / 2;
  347. int16_t h2 = display.height() / 2;
  348. drawBitmapFromSD("betty_4.bmp", w2 - 102, h2 - 126);
  349. delay(2000);
  350. drawBitmapFromSD("bb4.bmp", 0, 0);
  351. delay(2000);
  352. drawBitmapFromSD("output5.bmp", 0, 0);
  353. delay(2000);
  354. drawBitmapFromSD("output6.bmp", 0, 0);
  355. delay(2000);
  356. drawBitmapFromSD("tractor_1.bmp", 0, 0);
  357. delay(2000);
  358. drawBitmapFromSD("tractor_4.bmp", 0, 0);
  359. delay(2000);
  360. drawBitmapFromSD("tractor_8.bmp", 0, 0);
  361. delay(2000);
  362. drawBitmapFromSD("tractor_11.bmp", 0, 0);
  363. delay(2000);
  364. drawBitmapFromSD("tractor_44.bmp", 0, 0);
  365. delay(2000);
  366. drawBitmapFromSD("tractor_88.bmp", 0, 0);
  367. delay(2000);
  368. }
  369. void drawBitmapsBuffered_200x200()
  370. {
  371. int16_t x = (display.width() - 200) / 2;
  372. int16_t y = (display.height() - 200) / 2;
  373. drawBitmapFromSD_Buffered("logo200x200.bmp", x, y);
  374. delay(2000);
  375. drawBitmapFromSD_Buffered("first200x200.bmp", x, y);
  376. delay(2000);
  377. drawBitmapFromSD_Buffered("second200x200.bmp", x, y);
  378. delay(2000);
  379. drawBitmapFromSD_Buffered("third200x200.bmp", x, y);
  380. delay(2000);
  381. drawBitmapFromSD_Buffered("fourth200x200.bmp", x, y);
  382. delay(2000);
  383. drawBitmapFromSD_Buffered("fifth200x200.bmp", x, y);
  384. delay(2000);
  385. drawBitmapFromSD_Buffered("sixth200x200.bmp", x, y);
  386. delay(2000);
  387. drawBitmapFromSD_Buffered("seventh200x200.bmp", x, y);
  388. delay(2000);
  389. drawBitmapFromSD_Buffered("eighth200x200.bmp", x, y);
  390. delay(2000);
  391. }
  392. void drawBitmapsBuffered_other()
  393. {
  394. int16_t w2 = display.width() / 2;
  395. int16_t h2 = display.height() / 2;
  396. drawBitmapFromSD_Buffered("parrot.bmp", w2 - 64, h2 - 80);
  397. delay(2000);
  398. drawBitmapFromSD_Buffered("betty_1.bmp", w2 - 100, h2 - 160);
  399. delay(2000);
  400. drawBitmapFromSD_Buffered("betty_4.bmp", w2 - 102, h2 - 126);
  401. delay(2000);
  402. drawBitmapFromSD_Buffered("marilyn_240x240x8.bmp", w2 - 120, h2 - 120);
  403. delay(2000);
  404. drawBitmapFromSD_Buffered("miniwoof.bmp", w2 - 60, h2 - 80);
  405. delay(2000);
  406. drawBitmapFromSD_Buffered("t200x200.bmp", w2 - 100, h2 - 100);
  407. delay(2000);
  408. drawBitmapFromSD_Buffered("test.bmp", w2 - 120, h2 - 160);
  409. delay(2000);
  410. drawBitmapFromSD_Buffered("tiger.bmp", w2 - 160, h2 - 120);
  411. delay(2000);
  412. drawBitmapFromSD_Buffered("tiger_178x160x4.bmp", w2 - 89, h2 - 80);
  413. delay(2000);
  414. drawBitmapFromSD_Buffered("tiger_240x317x4.bmp", w2 - 120, h2 - 160);
  415. delay(2000);
  416. drawBitmapFromSD_Buffered("tiger_320x200x24.bmp", w2 - 160, h2 - 100);
  417. delay(2000);
  418. drawBitmapFromSD_Buffered("tiger16T.bmp", w2 - 160, h2 - 120);
  419. delay(2000);
  420. drawBitmapFromSD_Buffered("woof.bmp", w2 - 120, h2 - 160);
  421. delay(2000);
  422. drawBitmapFromSD_Buffered("bitmap640x384_1.bmp", 0, 0);
  423. delay(2000);
  424. }
  425. void drawBitmapsBuffered_test()
  426. {
  427. int16_t w2 = display.width() / 2;
  428. int16_t h2 = display.height() / 2;
  429. drawBitmapFromSD_Buffered("betty_4.bmp", w2 - 102, h2 - 126);
  430. delay(2000);
  431. drawBitmapFromSD_Buffered("bb4.bmp", 0, 0, false, true, true);
  432. delay(2000);
  433. }
  434. static const uint16_t input_buffer_pixels = 20; // may affect performance
  435. static const uint16_t max_row_width = 800; // for up to 7.5" display 800x480
  436. static const uint16_t max_palette_pixels = 256; // for depth <= 8
  437. uint8_t input_buffer[3 * input_buffer_pixels]; // up to depth 24
  438. uint8_t output_row_mono_buffer[max_row_width / 8]; // buffer for at least one row of b/w bits
  439. uint8_t output_row_color_buffer[max_row_width / 8]; // buffer for at least one row of color bits
  440. uint8_t mono_palette_buffer[max_palette_pixels / 8]; // palette buffer for depth <= 8 b/w
  441. uint8_t color_palette_buffer[max_palette_pixels / 8]; // palette buffer for depth <= 8 c/w
  442. void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_color)
  443. {
  444. SdFile file;
  445. bool valid = false; // valid format to be handled
  446. bool flip = true; // bitmap is stored bottom-to-top
  447. uint32_t startTime = millis();
  448. if ((x >= display.epd2.WIDTH) || (y >= display.epd2.HEIGHT)) return;
  449. Serial.println();
  450. Serial.print("Loading image '");
  451. Serial.print(filename);
  452. Serial.println('\'');
  453. #if defined(ESP32)
  454. file = SD.open(String("/") + filename, FILE_READ);
  455. if (!file)
  456. {
  457. Serial.print("File not found");
  458. return;
  459. }
  460. #else
  461. if (!file.open(filename, FILE_READ))
  462. {
  463. Serial.print("File not found");
  464. return;
  465. }
  466. #endif
  467. // Parse BMP header
  468. if (read16(file) == 0x4D42) // BMP signature
  469. {
  470. uint32_t fileSize = read32(file);
  471. uint32_t creatorBytes = read32(file);
  472. uint32_t imageOffset = read32(file); // Start of image data
  473. uint32_t headerSize = read32(file);
  474. uint32_t width = read32(file);
  475. uint32_t height = read32(file);
  476. uint16_t planes = read16(file);
  477. uint16_t depth = read16(file); // bits per pixel
  478. uint32_t format = read32(file);
  479. if ((planes == 1) && ((format == 0) || (format == 3))) // uncompressed is handled, 565 also
  480. {
  481. Serial.print("File size: "); Serial.println(fileSize);
  482. Serial.print("Image Offset: "); Serial.println(imageOffset);
  483. Serial.print("Header size: "); Serial.println(headerSize);
  484. Serial.print("Bit Depth: "); Serial.println(depth);
  485. Serial.print("Image size: ");
  486. Serial.print(width);
  487. Serial.print('x');
  488. Serial.println(height);
  489. // BMP rows are padded (if needed) to 4-byte boundary
  490. uint32_t rowSize = (width * depth / 8 + 3) & ~3;
  491. if (depth < 8) rowSize = ((width * depth + 8 - depth) / 8 + 3) & ~3;
  492. if (height < 0)
  493. {
  494. height = -height;
  495. flip = false;
  496. }
  497. uint16_t w = width;
  498. uint16_t h = height;
  499. if ((x + w - 1) >= display.epd2.WIDTH) w = display.epd2.WIDTH - x;
  500. if ((y + h - 1) >= display.epd2.HEIGHT) h = display.epd2.HEIGHT - y;
  501. if (w <= max_row_width) // handle with direct drawing
  502. {
  503. valid = true;
  504. uint8_t bitmask = 0xFF;
  505. uint8_t bitshift = 8 - depth;
  506. uint16_t red, green, blue;
  507. bool whitish, colored;
  508. if (depth == 1) with_color = false;
  509. if (depth <= 8)
  510. {
  511. if (depth < 8) bitmask >>= depth;
  512. //file.seekSet(54); //palette is always @ 54
  513. file.seekSet(imageOffset - (4 << depth)); // 54 for regular, diff for colorsimportant
  514. for (uint16_t pn = 0; pn < (1 << depth); pn++)
  515. {
  516. blue = file.read();
  517. green = file.read();
  518. red = file.read();
  519. file.read();
  520. //Serial.print(red); Serial.print(" "); Serial.print(green); Serial.print(" "); Serial.println(blue);
  521. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  522. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  523. if (0 == pn % 8) mono_palette_buffer[pn / 8] = 0;
  524. mono_palette_buffer[pn / 8] |= whitish << pn % 8;
  525. if (0 == pn % 8) color_palette_buffer[pn / 8] = 0;
  526. color_palette_buffer[pn / 8] |= colored << pn % 8;
  527. }
  528. }
  529. display.clearScreen();
  530. uint32_t rowPosition = flip ? imageOffset + (height - h) * rowSize : imageOffset;
  531. for (uint16_t row = 0; row < h; row++, rowPosition += rowSize) // for each line
  532. {
  533. uint32_t in_remain = rowSize;
  534. uint32_t in_idx = 0;
  535. uint32_t in_bytes = 0;
  536. uint8_t in_byte = 0; // for depth <= 8
  537. uint8_t in_bits = 0; // for depth <= 8
  538. uint8_t out_byte = 0xFF; // white (for w%8!=0 border)
  539. uint8_t out_color_byte = 0xFF; // white (for w%8!=0 border)
  540. uint32_t out_idx = 0;
  541. file.seekSet(rowPosition);
  542. for (uint16_t col = 0; col < w; col++) // for each pixel
  543. {
  544. // Time to read more pixel data?
  545. if (in_idx >= in_bytes) // ok, exact match for 24bit also (size IS multiple of 3)
  546. {
  547. in_bytes = file.read(input_buffer, in_remain > sizeof(input_buffer) ? sizeof(input_buffer) : in_remain);
  548. in_remain -= in_bytes;
  549. in_idx = 0;
  550. }
  551. switch (depth)
  552. {
  553. case 24:
  554. blue = input_buffer[in_idx++];
  555. green = input_buffer[in_idx++];
  556. red = input_buffer[in_idx++];
  557. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  558. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  559. break;
  560. case 16:
  561. {
  562. uint8_t lsb = input_buffer[in_idx++];
  563. uint8_t msb = input_buffer[in_idx++];
  564. if (format == 0) // 555
  565. {
  566. blue = (lsb & 0x1F) << 3;
  567. green = ((msb & 0x03) << 6) | ((lsb & 0xE0) >> 2);
  568. red = (msb & 0x7C) << 1;
  569. }
  570. else // 565
  571. {
  572. blue = (lsb & 0x1F) << 3;
  573. green = ((msb & 0x07) << 5) | ((lsb & 0xE0) >> 3);
  574. red = (msb & 0xF8);
  575. }
  576. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  577. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  578. }
  579. break;
  580. case 1:
  581. case 4:
  582. case 8:
  583. {
  584. if (0 == in_bits)
  585. {
  586. in_byte = input_buffer[in_idx++];
  587. in_bits = 8;
  588. }
  589. uint16_t pn = (in_byte >> bitshift) & bitmask;
  590. whitish = mono_palette_buffer[pn / 8] & (0x1 << pn % 8);
  591. colored = color_palette_buffer[pn / 8] & (0x1 << pn % 8);
  592. in_byte <<= depth;
  593. in_bits -= depth;
  594. }
  595. break;
  596. }
  597. if (whitish)
  598. {
  599. // keep white
  600. }
  601. else if (colored && with_color)
  602. {
  603. out_color_byte &= ~(0x80 >> col % 8); // colored
  604. }
  605. else
  606. {
  607. out_byte &= ~(0x80 >> col % 8); // black
  608. }
  609. if ((7 == col % 8) || (col == w - 1)) // write that last byte! (for w%8!=0 border)
  610. {
  611. output_row_color_buffer[out_idx] = out_color_byte;
  612. output_row_mono_buffer[out_idx++] = out_byte;
  613. out_byte = 0xFF; // white (for w%8!=0 border)
  614. out_color_byte = 0xFF; // white (for w%8!=0 border)
  615. }
  616. } // end pixel
  617. uint16_t yrow = y + (flip ? h - row - 1 : row);
  618. display.writeImage(output_row_mono_buffer, output_row_color_buffer, x, yrow, w, 1);
  619. } // end line
  620. Serial.print("loaded in "); Serial.print(millis() - startTime); Serial.println(" ms");
  621. display.refresh();
  622. }
  623. }
  624. }
  625. file.close();
  626. if (!valid)
  627. {
  628. Serial.println("bitmap format not handled.");
  629. }
  630. }
  631. void drawBitmapFromSD_Buffered(const char *filename, int16_t x, int16_t y, bool with_color, bool partial_update, bool overwrite)
  632. {
  633. SdFile file;
  634. bool valid = false; // valid format to be handled
  635. bool flip = true; // bitmap is stored bottom-to-top
  636. uint32_t startTime = millis();
  637. if ((x >= display.width()) || (y >= display.height())) return;
  638. Serial.println();
  639. Serial.print("Loading image '");
  640. Serial.print(filename);
  641. Serial.println('\'');
  642. #if defined(ESP32)
  643. file = SD.open(String("/") + filename, FILE_READ);
  644. if (!file)
  645. {
  646. Serial.print("File not found");
  647. return;
  648. }
  649. #else
  650. if (!file.open(filename, FILE_READ))
  651. {
  652. Serial.print("File not found");
  653. return;
  654. }
  655. #endif
  656. // Parse BMP header
  657. if (read16(file) == 0x4D42) // BMP signature
  658. {
  659. uint32_t fileSize = read32(file);
  660. uint32_t creatorBytes = read32(file);
  661. uint32_t imageOffset = read32(file); // Start of image data
  662. uint32_t headerSize = read32(file);
  663. uint32_t width = read32(file);
  664. uint32_t height = read32(file);
  665. uint16_t planes = read16(file);
  666. uint16_t depth = read16(file); // bits per pixel
  667. uint32_t format = read32(file);
  668. if ((planes == 1) && ((format == 0) || (format == 3))) // uncompressed is handled, 565 also
  669. {
  670. Serial.print("File size: "); Serial.println(fileSize);
  671. Serial.print("Image Offset: "); Serial.println(imageOffset);
  672. Serial.print("Header size: "); Serial.println(headerSize);
  673. Serial.print("Bit Depth: "); Serial.println(depth);
  674. Serial.print("Image size: ");
  675. Serial.print(width);
  676. Serial.print('x');
  677. Serial.println(height);
  678. // BMP rows are padded (if needed) to 4-byte boundary
  679. uint32_t rowSize = (width * depth / 8 + 3) & ~3;
  680. if (depth < 8) rowSize = ((width * depth + 8 - depth) / 8 + 3) & ~3;
  681. if (height < 0)
  682. {
  683. height = -height;
  684. flip = false;
  685. }
  686. uint16_t w = width;
  687. uint16_t h = height;
  688. if ((x + w - 1) >= display.width()) w = display.width() - x;
  689. if ((y + h - 1) >= display.height()) h = display.height() - y;
  690. //if (w <= max_row_width) // handle with direct drawing
  691. {
  692. valid = true;
  693. uint8_t bitmask = 0xFF;
  694. uint8_t bitshift = 8 - depth;
  695. uint16_t red, green, blue;
  696. bool whitish, colored;
  697. if (depth == 1) with_color = false;
  698. if (depth <= 8)
  699. {
  700. if (depth < 8) bitmask >>= depth;
  701. //file.seekSet(54); //palette is always @ 54
  702. file.seekSet(imageOffset - (4 << depth)); //54 for regular, diff for colorsimportant
  703. for (uint16_t pn = 0; pn < (1 << depth); pn++)
  704. {
  705. blue = file.read();
  706. green = file.read();
  707. red = file.read();
  708. file.read();
  709. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  710. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  711. if (0 == pn % 8) mono_palette_buffer[pn / 8] = 0;
  712. mono_palette_buffer[pn / 8] |= whitish << pn % 8;
  713. if (0 == pn % 8) color_palette_buffer[pn / 8] = 0;
  714. color_palette_buffer[pn / 8] |= colored << pn % 8;
  715. }
  716. }
  717. if (partial_update) display.setPartialWindow(x, y, w, h);
  718. else display.setFullWindow();
  719. display.firstPage();
  720. do
  721. {
  722. if (!overwrite) display.fillScreen(GxEPD_WHITE);
  723. uint32_t rowPosition = flip ? imageOffset + (height - h) * rowSize : imageOffset;
  724. for (uint16_t row = 0; row < h; row++, rowPosition += rowSize) // for each line
  725. {
  726. uint32_t in_remain = rowSize;
  727. uint32_t in_idx = 0;
  728. uint32_t in_bytes = 0;
  729. uint8_t in_byte = 0; // for depth <= 8
  730. uint8_t in_bits = 0; // for depth <= 8
  731. uint16_t color = GxEPD_WHITE;
  732. file.seekSet(rowPosition);
  733. for (uint16_t col = 0; col < w; col++) // for each pixel
  734. {
  735. // Time to read more pixel data?
  736. if (in_idx >= in_bytes) // ok, exact match for 24bit also (size IS multiple of 3)
  737. {
  738. in_bytes = file.read(input_buffer, in_remain > sizeof(input_buffer) ? sizeof(input_buffer) : in_remain);
  739. in_remain -= in_bytes;
  740. in_idx = 0;
  741. }
  742. switch (depth)
  743. {
  744. case 24:
  745. blue = input_buffer[in_idx++];
  746. green = input_buffer[in_idx++];
  747. red = input_buffer[in_idx++];
  748. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  749. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  750. break;
  751. case 16:
  752. {
  753. uint8_t lsb = input_buffer[in_idx++];
  754. uint8_t msb = input_buffer[in_idx++];
  755. if (format == 0) // 555
  756. {
  757. blue = (lsb & 0x1F) << 3;
  758. green = ((msb & 0x03) << 6) | ((lsb & 0xE0) >> 2);
  759. red = (msb & 0x7C) << 1;
  760. }
  761. else // 565
  762. {
  763. blue = (lsb & 0x1F) << 3;
  764. green = ((msb & 0x07) << 5) | ((lsb & 0xE0) >> 3);
  765. red = (msb & 0xF8);
  766. }
  767. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  768. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  769. }
  770. break;
  771. case 1:
  772. case 4:
  773. case 8:
  774. {
  775. if (0 == in_bits)
  776. {
  777. in_byte = input_buffer[in_idx++];
  778. in_bits = 8;
  779. }
  780. uint16_t pn = (in_byte >> bitshift) & bitmask;
  781. whitish = mono_palette_buffer[pn / 8] & (0x1 << pn % 8);
  782. colored = color_palette_buffer[pn / 8] & (0x1 << pn % 8);
  783. in_byte <<= depth;
  784. in_bits -= depth;
  785. }
  786. break;
  787. }
  788. if (whitish)
  789. {
  790. color = GxEPD_WHITE;
  791. }
  792. else if (colored && with_color)
  793. {
  794. color = GxEPD_COLORED;
  795. }
  796. else
  797. {
  798. color = GxEPD_BLACK;
  799. }
  800. uint16_t yrow = y + (flip ? h - row - 1 : row);
  801. display.drawPixel(x + col, yrow, color);
  802. } // end pixel
  803. } // end line
  804. }
  805. while (display.nextPage());
  806. Serial.print("loaded in "); Serial.print(millis() - startTime); Serial.println(" ms");
  807. }
  808. }
  809. }
  810. file.close();
  811. if (!valid)
  812. {
  813. Serial.println("bitmap format not handled.");
  814. }
  815. }
  816. uint16_t read16(SdFile& f)
  817. {
  818. // BMP data is stored little-endian, same as Arduino.
  819. uint16_t result;
  820. ((uint8_t *)&result)[0] = f.read(); // LSB
  821. ((uint8_t *)&result)[1] = f.read(); // MSB
  822. return result;
  823. }
  824. uint32_t read32(SdFile& f)
  825. {
  826. // BMP data is stored little-endian, same as Arduino.
  827. uint32_t result;
  828. ((uint8_t *)&result)[0] = f.read(); // LSB
  829. ((uint8_t *)&result)[1] = f.read();
  830. ((uint8_t *)&result)[2] = f.read();
  831. ((uint8_t *)&result)[3] = f.read(); // MSB
  832. return result;
  833. }