| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- // Display Library example for SPI e-paper panels from Dalian Good Display and boards from Waveshare.
- // Requires HW SPI and Adafruit_GFX. Caution: the e-paper panels require 3.3V supply AND data lines!
- //
- // Display Library based on Demo Example from Good Display: http://www.e-paper-display.com/download_list/downloadcategoryid=34&isMode=false.html
- //
- // Author: Jean-Marc Zingg
- //
- // Version: see library.properties
- //
- // Library: https://github.com/ZinggJM/GxEPD2
- // GxEPD2_U8G2_Fonts_Example : show use of U8G2_FOR_ADAFRUIT_GFX with GxEPD2
- //
- // Library: https://github.com/olikraus/U8g2_for_Adafruit_GFX
- // see: https://github.com/olikraus/U8g2_for_Adafruit_GFX/blob/master/README.md
- //
- // NOTE: you need to SAVE the modified example to a saveable location for UTF-8 characters to work
- // e.g. for Umlauts
- // Supporting Arduino Forum Topics:
- // Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
- // Good Display ePaper for Arduino: https://forum.arduino.cc/index.php?topic=436411.0
- // see GxEPD2_wiring_examples.h for wiring suggestions and examples
- // base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
- // enable or disable GxEPD2_GFX base class
- #define ENABLE_GxEPD2_GFX 0
- #include <GxEPD2_BW.h>
- #include <GxEPD2_3C.h>
- #include <GxEPD2_7C.h>
- #include <Fonts/FreeMonoBold9pt7b.h>
- #include <U8g2_for_Adafruit_GFX.h>
- // select the display class and display driver class in the following file (new style):
- #include "GxEPD2_display_selection_new_style.h"
- U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;
- void setup()
- {
- Serial.begin(115200);
- Serial.println();
- Serial.println("setup");
- display.init();
- u8g2Fonts.begin(display); // connect u8g2 procedures to Adafruit GFX
- helloWorld();
- delay(1000);
- helloArduino();
- delay(1000);
- helloEpaper();
- delay(1000);
- showFont("u8g2_font_helvR14_tf", u8g2_font_helvR14_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
- delay(2000);
- showFont("u8g2_font_profont22_mr", u8g2_font_profont22_mr); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
- delay(1000);
- Serial.println("setup done");
- }
- void loop()
- {
- }
- void helloWorld()
- {
- //Serial.println("helloWorld");
- uint16_t bg = GxEPD_WHITE;
- uint16_t fg = GxEPD_BLACK;
- u8g2Fonts.setFontMode(1); // use u8g2 transparent mode (this is default)
- u8g2Fonts.setFontDirection(0); // left to right (this is default)
- u8g2Fonts.setForegroundColor(fg); // apply Adafruit GFX color
- u8g2Fonts.setBackgroundColor(bg); // apply Adafruit GFX color
- u8g2Fonts.setFont(u8g2_font_helvR14_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
- uint16_t x = (display.width() - 160) / 2;
- uint16_t y = display.height() / 2;
- display.firstPage();
- do
- {
- display.fillScreen(bg);
- u8g2Fonts.setCursor(x, y); // start writing at this position
- u8g2Fonts.print("Hello World!");
- }
- while (display.nextPage());
- //Serial.println("helloWorld done");
- }
- void helloArduino()
- {
- //Serial.println("helloArduino");
- uint16_t bg = GxEPD_WHITE;
- uint16_t fg = GxEPD_BLACK;
- u8g2Fonts.setFontMode(1); // use u8g2 transparent mode (this is default)
- u8g2Fonts.setFontDirection(0); // left to right (this is default)
- u8g2Fonts.setForegroundColor(fg); // apply Adafruit GFX color
- u8g2Fonts.setBackgroundColor(bg); // apply Adafruit GFX color
- u8g2Fonts.setFont(u8g2_font_helvR14_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
- uint16_t x = (display.width() - 160) / 2;
- uint16_t y = display.height() / 4;
- display.setPartialWindow(0, y - 14, display.width(), 20);
- display.firstPage();
- do
- {
- display.fillScreen(bg);
- u8g2Fonts.setCursor(x, y);
- u8g2Fonts.println("Hello Arduino!");
- }
- while (display.nextPage());
- //Serial.println("helloArduino done");
- }
- void helloEpaper()
- {
- //Serial.println("helloEpaper");
- uint16_t bg = GxEPD_WHITE;
- uint16_t fg = GxEPD_BLACK;
- u8g2Fonts.setFontMode(1); // use u8g2 transparent mode (this is default)
- u8g2Fonts.setFontDirection(0); // left to right (this is default)
- u8g2Fonts.setForegroundColor(fg); // apply Adafruit GFX color
- u8g2Fonts.setBackgroundColor(bg); // apply Adafruit GFX color
- u8g2Fonts.setFont(u8g2_font_helvR14_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
- uint16_t x = (display.width() - 160) / 2;
- uint16_t y = display.height() * 3 / 4;
- display.setPartialWindow(0, y - 14, display.width(), 20);
- display.firstPage();
- do
- {
- display.fillScreen(bg);
- u8g2Fonts.setCursor(x, y);
- u8g2Fonts.println("Hello E-Paper!");
- }
- while (display.nextPage());
- //Serial.println("helloEpaper done");
- }
- void showFont(const char name[], const uint8_t *font)
- {
- display.setFullWindow();
- display.setRotation(0);
- u8g2Fonts.setFontMode(1); // use u8g2 transparent mode (this is default)
- u8g2Fonts.setFontDirection(0); // left to right (this is default)
- u8g2Fonts.setForegroundColor(GxEPD_BLACK); // apply Adafruit GFX color
- u8g2Fonts.setBackgroundColor(GxEPD_WHITE); // apply Adafruit GFX color
- u8g2Fonts.setFont(font); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
- display.firstPage();
- do
- {
- drawFont(name);
- }
- while (display.nextPage());
- }
- void drawFont(const char name[])
- {
- //display.setRotation(0);
- display.fillScreen(GxEPD_WHITE);
- u8g2Fonts.setCursor(0, 0);
- u8g2Fonts.println();
- u8g2Fonts.println(name);
- u8g2Fonts.println(" !\"#$%&'()*+,-./");
- u8g2Fonts.println("0123456789:;<=>?");
- u8g2Fonts.println("@ABCDEFGHIJKLMNO");
- u8g2Fonts.println("PQRSTUVWXYZ[\\]^_");
- u8g2Fonts.println("`abcdefghijklmno");
- u8g2Fonts.println("pqrstuvwxyz{|}~ ");
- u8g2Fonts.println("Umlaut ÄÖÜäéöü");
- }
|