/*
SPI ePaper to generic ESP32:
BUSY = 4
RST = 16
DC = 17
CS = SS (5)
CLK = SCK (18)
DIN = MOSI (23)
GND = GND
3.3V = 3.3V
NOTE: there are variants with different pins for SPI! CHECK SPI PINS OF YOUR BOARD.
Guide for the GFX Library: https://cdn-learn.adafruit.com/downloads/pdf/adafruit-gfx-graphics-library.pdf
List of fonts: https://learn.adafruit.com/adafruit-gfx-graphics-library/using-fonts
*/
// 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 libraries:
#include <GxEPD2_BW.h> // Include GxEPD2 library for black and white displays
#include <GxEPD2_3C.h> // Include GxEPD2 library for 3 color displays
#include <Adafruit_GFX.h> // Include Adafruit_GFX library
// ESP32:
#if defined(ESP32)
// Select one and adapt to your mapping, can use full buffer size (full HEIGHT)
//GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEP015OC1 no longer available
//GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0154D67
GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=5*/ 5, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
//GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=5*/ 5, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW029T5
// 3-color e-papers
#define MAX_DISPLAY_BUFFER_SIZE 15000ul // ~15k is a good compromise
#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))
//GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=5*/ SS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
//GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=5*/ 5, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
#endif
// Include fonts from Adafruit_GFX
#include <Fonts/FreeMono9pt7b.h>
#include <Fonts/FreeMono12pt7b.h>
#include <Fonts/FreeMono18pt7b.h>
#include <Fonts/FreeMono24pt7b.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeMonoBold12pt7b.h>
#include <Fonts/FreeMonoBold18pt7b.h>
#include <Fonts/FreeMonoBold24pt7b.h>
// Include images:
// We can show images using bitmaps, which usually we store in seperate files
// inside the sketch folder. Those "*.h" files contain the image data.
// We need to include them here to be able to use them.
#include "subs.h"
#include "yt1.h"
#include "yt2.h"
int Variable1; // Create a variable to have something dynamic to show on the display
void setup() // Start of setup
{
Serial.begin(115200);
display.init(115200); // Initiate the display
display.setRotation(0); // Set orientation. Goes from 0, 1, 2 or 3
display.setTextWrap(false); // By default, long lines of text are set to automatically “wrap” back to the leftmost column.
// To override this behavior (so text will run off the right side of the display - useful for
// scrolling marquee effects), use setTextWrap(false). The normal wrapping behavior is restored
// with setTextWrap(true).
Serial.println("Start");
} // End of setup
void loop() // Start of loop
{
Serial.println("Loop");
Variable1++; // Increase variable by 1
if (Variable1 > 150) // If Variable1 is greater than 150
{
Variable1 = 0; // Set Variable1 to 0
}
// Convert Variable1 into a string, so we can change the text alignment to the right:
// It can be also used to add or remove decimal numbers.
char string[10]; // Create a character array of 10 characters
// Convert float to a string:
dtostrf(Variable1, 3, 0, string); // (<variable>,<amount of digits we are going to use>,<amount of decimal digits>,<string name>)
// Demo Screen 1: Text, values and shapes
display.setFullWindow(); // Set full window mode, meaning is going to update the entire screen
// Here we use paged drawing, even if the processor has enough RAM for full buffer
// so this can be used with any supported processor board.
// the cost in code overhead and execution time penalty is marginal
display.firstPage(); // Tell the graphics class to use paged drawing mode
Serial.println(1);
do
{
// Put everything you want to print in this screen:
display.fillScreen(GxEPD_WHITE); // Clear previous graphics to start over to print new things.
// Print text - "Hello World!":
display.setTextColor(GxEPD_BLACK); // Set color for text
display.setFont(&FreeMonoBold12pt7b); // Set font
display.setCursor(0, 15); // Set the position to start printing text (x,y)
display.println("Hello World!"); // Print some text
// Draw triangle:
display.drawTriangle(0, 85, 20, 60, 40, 85, GxEPD_BLACK); // Draw triangle. X, Y coordinates for three corner points defining the triangle, followed by a color
// Draw filled triangle:
display.fillTriangle(110, 85, 130, 60, 150, 85, GxEPD_BLACK); // Draw filled triangle. X, Y coordinates for three corner points defining the triangle, followed by a color
// Draw line:
display.drawLine(74, 20, 74, 80, GxEPD_BLACK); // Draw line (x0,y0,x1,y1,color)
// Draw rounded rectangle and fill:
display.fillRoundRect(48, 60, 20, 25, 5, GxEPD_BLACK); // Draw filled rounded rectangle (x,y,width,height,color)
// It draws from the location to down-right
// Draw circle:
display.drawCircle(95, 70, 15, GxEPD_BLACK); // Draw circle (x,y,radius,color). X and Y are the coordinates for the center point
// Draw a filled circle:
display.fillCircle(100, 75, 7, GxEPD_BLACK); // Draw filled circle (x,y,radius,color). X and Y are the coordinates for the center point
// Draw rectangle:
display.drawRect(8, 25, 49, 27, GxEPD_BLACK); // Draw rectangle (x,y,width,height,color)
// It draws from the location to down-right
// Print variable with left alignment:
display.setTextColor(GxEPD_BLACK); // Set color for text
display.setFont(&FreeMonoBold12pt7b); // Set font
display.setCursor(12, 45); // Set the position to start printing text (x,y)
display.println(Variable1); // Print some text
// Draw rounded rectangle:
display.drawRoundRect(91, 25, 49, 27, 8, GxEPD_BLACK); // Draw rounded rectangle (x,y,width,height,radius,color)
// It draws from the location to down-right
// Print variable with right alignment:
display.setTextColor(GxEPD_BLACK); // Set color for text
display.setFont(&FreeMonoBold12pt7b); // Set font
display.setCursor(93, 45); // Set the position to start printing text (x,y)
display.println(string); // Print some text
}
// Tell the graphics class to transfer the buffer content (page) to the controller buffer.
// The graphics class will command the controller to refresh to the screen when the last
// page has been transferred.
// Returns true if more pages need be drawn and transferred.
// Returns false if the last page has been transferred and the screen refreshed for
// panels without fast partial update.
// Returns false for panels with fast partial update when the controller buffer has
// been written once more, to make the differential buffers equal.
// For full buffered with fast partial update the (full) buffer is just transferred
// again, and false returned.
while (display.nextPage()); // Print everything we set previously
// End of screen 1
// // Demo Screen 2: Images and text
// display.setFullWindow(); // Set full window mode, meaning is going to update the entire screen
// display.firstPage(); // Tell the graphics class to use paged drawing mode
// do
// {
// // Put everything you want to print in this screen:
// // Print YouTube image:
// display.fillScreen(GxEPD_WHITE); // Clear previous graphics to start over to print new things.
// // Format: (POSITION_X, POSITION_Y, IMAGE_NAME, IMAGE_WIDTH, IMAGE_HEIGHT, COLOR)
// // Color options are GxEPD_BLACK, GxEPD_WHITE, GxEPD_RED
// display.drawBitmap(0, 0, gImage_yt1, 200, 45, GxEPD_BLACK); // Print YouTube logo - Black part (POSITION_X, POSITION_Y, IMAGE_NAME, IMAGE_WIDTH, IMAGE_HEIGHT, COLOR)
// //display.drawBitmap(0,0, yt2, 200,45, GxEPD_BLACK); // Print YouTube logo - Red part (POSITION_X, POSITION_Y, IMAGE_NAME, IMAGE_WIDTH, IMAGE_HEIGHT, COLOR)
// display.drawBitmap(0, 0, gImage_yt2, 200, 45, display.epd2.hasColor ? GxEPD_RED : GxEPD_BLACK); // Print YouTube logo - Red part (POSITION_X, POSITION_Y, IMAGE_NAME, IMAGE_WIDTH, IMAGE_HEIGHT, COLOR)
// // In the color part we put that if the display supports red color then use it. If not, use black.
// // Print Subscribers image:
// display.drawBitmap(30, 58, gImage_subs, 40, 25, GxEPD_BLACK); // Print Subscribers symbol (POSITION_X, POSITION_Y, IMAGE_NAME, IMAGE_WIDTH, IMAGE_HEIGHT, COLOR)
// // Print text - "3,456" (example number of subscribers):
// display.setTextColor(GxEPD_BLACK); // Set color for text
// display.setFont(&FreeMonoBold12pt7b); // Set font
// display.setCursor(100, 75); // Set the position to start printing text (x,y)
// display.print("3,456"); // Print some text
// }
// while (display.nextPage()); // Print everything we set previously
// // End of screen 2
/*
// The display shows ghosting (burned pixels), meaning that I could
// still see the previous images/text even after several screen updates.
// To help to clear the display, I'll fill the screen in black
// and white a few times.
// Fill the display black to help clear the ghosting
display.firstPage(); // Tell the graphics class to use paged drawing mode
do
{
display.fillScreen(GxEPD_BLACK);
}
while (display.nextPage()); // Print everything we set previously
// Fill the display white to help clear the ghosting
display.firstPage(); // Tell the graphics class to use paged drawing mode
do
{
display.fillScreen(GxEPD_WHITE);
}
while (display.nextPage()); // Print everything we set previously
// Fill the display black to help clear the ghosting
display.firstPage(); // Tell the graphics class to use paged drawing mode
do
{
display.fillScreen(GxEPD_BLACK);
}
while (display.nextPage()); // Print everything we set previously
// Fill the display white to help clear the ghosting
display.firstPage(); // Tell the graphics class to use paged drawing mode
do
{
display.fillScreen(GxEPD_WHITE);
}
while (display.nextPage()); // Print everything we set previously
// Fill the display black to help clear the ghosting
display.firstPage(); // Tell the graphics class to use paged drawing mode
do
{
display.fillScreen(GxEPD_BLACK);
}
while (display.nextPage()); // Print everything we set previously
// Fill the display white to help clear the ghosting
display.firstPage(); // Tell the graphics class to use paged drawing mode
do
{
display.fillScreen(GxEPD_WHITE);
}
while (display.nextPage()); // Print everything we set previously
*/
Serial.println(2);
while(1){}
} // End of loop
Loading
epaper-2in9
epaper-2in9