GxEPD2_U8G2_Fonts_Example.ino 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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: 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. // Author: Jean-Marc Zingg
  7. //
  8. // Version: see library.properties
  9. //
  10. // Library: https://github.com/ZinggJM/GxEPD2
  11. // GxEPD2_U8G2_Fonts_Example : show use of U8G2_FOR_ADAFRUIT_GFX with GxEPD2
  12. //
  13. // Library: https://github.com/olikraus/U8g2_for_Adafruit_GFX
  14. // see: https://github.com/olikraus/U8g2_for_Adafruit_GFX/blob/master/README.md
  15. //
  16. // NOTE: you need to SAVE the modified example to a saveable location for UTF-8 characters to work
  17. // e.g. for Umlauts
  18. // Supporting Arduino Forum Topics:
  19. // Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
  20. // Good Display ePaper for Arduino: https://forum.arduino.cc/index.php?topic=436411.0
  21. // see GxEPD2_wiring_examples.h for wiring suggestions and examples
  22. // base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
  23. // enable or disable GxEPD2_GFX base class
  24. #define ENABLE_GxEPD2_GFX 0
  25. #include <GxEPD2_BW.h>
  26. #include <GxEPD2_3C.h>
  27. #include <GxEPD2_7C.h>
  28. #include <Fonts/FreeMonoBold9pt7b.h>
  29. #include <U8g2_for_Adafruit_GFX.h>
  30. // select the display class and display driver class in the following file (new style):
  31. #include "GxEPD2_display_selection_new_style.h"
  32. U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;
  33. void setup()
  34. {
  35. Serial.begin(115200);
  36. Serial.println();
  37. Serial.println("setup");
  38. display.init();
  39. u8g2Fonts.begin(display); // connect u8g2 procedures to Adafruit GFX
  40. helloWorld();
  41. delay(1000);
  42. helloArduino();
  43. delay(1000);
  44. helloEpaper();
  45. delay(1000);
  46. showFont("u8g2_font_helvR14_tf", u8g2_font_helvR14_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  47. delay(2000);
  48. showFont("u8g2_font_profont22_mr", u8g2_font_profont22_mr); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  49. delay(1000);
  50. Serial.println("setup done");
  51. }
  52. void loop()
  53. {
  54. }
  55. void helloWorld()
  56. {
  57. //Serial.println("helloWorld");
  58. uint16_t bg = GxEPD_WHITE;
  59. uint16_t fg = GxEPD_BLACK;
  60. u8g2Fonts.setFontMode(1); // use u8g2 transparent mode (this is default)
  61. u8g2Fonts.setFontDirection(0); // left to right (this is default)
  62. u8g2Fonts.setForegroundColor(fg); // apply Adafruit GFX color
  63. u8g2Fonts.setBackgroundColor(bg); // apply Adafruit GFX color
  64. u8g2Fonts.setFont(u8g2_font_helvR14_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  65. uint16_t x = (display.width() - 160) / 2;
  66. uint16_t y = display.height() / 2;
  67. display.firstPage();
  68. do
  69. {
  70. display.fillScreen(bg);
  71. u8g2Fonts.setCursor(x, y); // start writing at this position
  72. u8g2Fonts.print("Hello World!");
  73. }
  74. while (display.nextPage());
  75. //Serial.println("helloWorld done");
  76. }
  77. void helloArduino()
  78. {
  79. //Serial.println("helloArduino");
  80. uint16_t bg = GxEPD_WHITE;
  81. uint16_t fg = GxEPD_BLACK;
  82. u8g2Fonts.setFontMode(1); // use u8g2 transparent mode (this is default)
  83. u8g2Fonts.setFontDirection(0); // left to right (this is default)
  84. u8g2Fonts.setForegroundColor(fg); // apply Adafruit GFX color
  85. u8g2Fonts.setBackgroundColor(bg); // apply Adafruit GFX color
  86. u8g2Fonts.setFont(u8g2_font_helvR14_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  87. uint16_t x = (display.width() - 160) / 2;
  88. uint16_t y = display.height() / 4;
  89. display.setPartialWindow(0, y - 14, display.width(), 20);
  90. display.firstPage();
  91. do
  92. {
  93. display.fillScreen(bg);
  94. u8g2Fonts.setCursor(x, y);
  95. u8g2Fonts.println("Hello Arduino!");
  96. }
  97. while (display.nextPage());
  98. //Serial.println("helloArduino done");
  99. }
  100. void helloEpaper()
  101. {
  102. //Serial.println("helloEpaper");
  103. uint16_t bg = GxEPD_WHITE;
  104. uint16_t fg = GxEPD_BLACK;
  105. u8g2Fonts.setFontMode(1); // use u8g2 transparent mode (this is default)
  106. u8g2Fonts.setFontDirection(0); // left to right (this is default)
  107. u8g2Fonts.setForegroundColor(fg); // apply Adafruit GFX color
  108. u8g2Fonts.setBackgroundColor(bg); // apply Adafruit GFX color
  109. u8g2Fonts.setFont(u8g2_font_helvR14_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  110. uint16_t x = (display.width() - 160) / 2;
  111. uint16_t y = display.height() * 3 / 4;
  112. display.setPartialWindow(0, y - 14, display.width(), 20);
  113. display.firstPage();
  114. do
  115. {
  116. display.fillScreen(bg);
  117. u8g2Fonts.setCursor(x, y);
  118. u8g2Fonts.println("Hello E-Paper!");
  119. }
  120. while (display.nextPage());
  121. //Serial.println("helloEpaper done");
  122. }
  123. void showFont(const char name[], const uint8_t *font)
  124. {
  125. display.setFullWindow();
  126. display.setRotation(0);
  127. u8g2Fonts.setFontMode(1); // use u8g2 transparent mode (this is default)
  128. u8g2Fonts.setFontDirection(0); // left to right (this is default)
  129. u8g2Fonts.setForegroundColor(GxEPD_BLACK); // apply Adafruit GFX color
  130. u8g2Fonts.setBackgroundColor(GxEPD_WHITE); // apply Adafruit GFX color
  131. u8g2Fonts.setFont(font); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  132. display.firstPage();
  133. do
  134. {
  135. drawFont(name);
  136. }
  137. while (display.nextPage());
  138. }
  139. void drawFont(const char name[])
  140. {
  141. //display.setRotation(0);
  142. display.fillScreen(GxEPD_WHITE);
  143. u8g2Fonts.setCursor(0, 0);
  144. u8g2Fonts.println();
  145. u8g2Fonts.println(name);
  146. u8g2Fonts.println(" !\"#$%&'()*+,-./");
  147. u8g2Fonts.println("0123456789:;<=>?");
  148. u8g2Fonts.println("@ABCDEFGHIJKLMNO");
  149. u8g2Fonts.println("PQRSTUVWXYZ[\\]^_");
  150. u8g2Fonts.println("`abcdefghijklmno");
  151. u8g2Fonts.println("pqrstuvwxyz{|}~ ");
  152. u8g2Fonts.println("Umlaut ÄÖÜäéöü");
  153. }