GxEPD2_HelloWorld.ino 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // GxEPD2_HelloWorld.ino by Jean-Marc Zingg
  2. //
  3. // Display Library example for SPI e-paper panels from Dalian Good Display and boards from Waveshare.
  4. // Requires HW SPI and Adafruit_GFX. Caution: the e-paper panels require 3.3V supply AND data lines!
  5. //
  6. // Display Library based on Demo Example from Good Display: https://www.good-display.com/companyfile/32/
  7. //
  8. // Author: Jean-Marc Zingg
  9. //
  10. // Version: see library.properties
  11. //
  12. // Library: https://github.com/ZinggJM/GxEPD2
  13. // Supporting Arduino Forum Topics (closed, read only):
  14. // Good Display ePaper for Arduino: https://forum.arduino.cc/t/good-display-epaper-for-arduino/419657
  15. // Waveshare e-paper displays with SPI: https://forum.arduino.cc/t/waveshare-e-paper-displays-with-spi/467865
  16. //
  17. // Add new topics in https://forum.arduino.cc/c/using-arduino/displays/23 for new questions and issues
  18. // see GxEPD2_wiring_examples.h for wiring suggestions and examples
  19. // if you use a different wiring, you need to adapt the constructor parameters!
  20. // uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX
  21. //#include <GFX.h>
  22. #include <GxEPD2_BW.h>
  23. #include <GxEPD2_3C.h>
  24. #include <GxEPD2_4C.h>
  25. #include <GxEPD2_7C.h>
  26. #include <Fonts/FreeMonoBold9pt7b.h>
  27. // select the display class and display driver class in the following file (new style):
  28. #include "GxEPD2_display_selection_new_style.h"
  29. // or select the display constructor line in one of the following files (old style):
  30. #include "GxEPD2_display_selection.h"
  31. #include "GxEPD2_display_selection_added.h"
  32. // alternately you can copy the constructor from GxEPD2_display_selection.h or GxEPD2_display_selection_added.h to here
  33. // e.g. for Wemos D1 mini:
  34. //GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=D8*/ SS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEH0154D67
  35. // for handling alternative SPI pins (ESP32, RP2040) see example GxEPD2_Example.ino
  36. void setup()
  37. {
  38. //display.init(115200); // default 10ms reset pulse, e.g. for bare panels with DESPI-C02
  39. display.init(115200, true, 2, false); // USE THIS for Waveshare boards with "clever" reset circuit, 2ms reset pulse
  40. helloWorld();
  41. display.hibernate();
  42. }
  43. const char HelloWorld[] = "Hello World!";
  44. void helloWorld()
  45. {
  46. display.setRotation(1);
  47. display.setFont(&FreeMonoBold9pt7b);
  48. display.setTextColor(GxEPD_BLACK);
  49. int16_t tbx, tby; uint16_t tbw, tbh;
  50. display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
  51. // center the bounding box by transposition of the origin:
  52. uint16_t x = ((display.width() - tbw) / 2) - tbx;
  53. uint16_t y = ((display.height() - tbh) / 2) - tby;
  54. display.setFullWindow();
  55. display.firstPage();
  56. do
  57. {
  58. display.fillScreen(GxEPD_WHITE);
  59. display.setCursor(x, y);
  60. display.print(HelloWorld);
  61. }
  62. while (display.nextPage());
  63. }
  64. void loop() {};