Closed goedzo closed 1 month ago
Here is also a simple helloworld sketch (that you can use completely), which also shows nothing on the screen:
#include <GxEPD2_BW.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Wire.h>
#include <SPI.h>
// Define the display class and the display size
#define GxEPD2_DRIVER_CLASS GxEPD2_150_BN
GxEPD2_BW<GxEPD2_DRIVER_CLASS, GxEPD2_150_BN::HEIGHT> display(GxEPD2_150_BN(
/*CS=*/ 30, // ePaper_Cs
/*DC=*/ 28, // ePaper_Dc
/*RST=*/ 2, // ePaper_Rst
/*BUSY=*/ 3 // ePaper_Busy
));
void setup() {
// Wait for Serial Monitor to be connected
Serial.begin(115200);
while (!Serial) {
; // Wait for the serial connection
}
Serial.println("Serial initialized...");
// Start SPI communication and initialize the display
Serial.println("Initializing display...");
display.init();
delay(1000); // Give time for display to initialize
Serial.println("Display initialized.");
// Clear the display buffer
display.setRotation(1); // Rotate display if needed (0-3)
Serial.println("Display rotation set.");
display.setTextColor(GxEPD_BLACK);
Serial.println("Text color set to black.");
// Print "Hello world" on the screen
Serial.println("Starting display update...");
display.firstPage();
do {
Serial.println("Clearing the display...");
display.fillScreen(GxEPD_WHITE); // Clear the display
Serial.println("Setting font...");
display.setFont(&FreeMonoBold9pt7b); // Use a built-in font
Serial.println("Setting cursor position...");
display.setCursor(10, 40); // Position for the text
Serial.println("Printing 'Hello world'...");
display.print("Hello world");
} while (display.nextPage());
// Refresh the display after drawing
Serial.println("Refreshing the display...");
display.refresh(); // This will ensure the content is rendered on the display
Serial.println("Display refresh finished.");
// Add delay to allow e-paper to finish update
delay(5000);
}
void loop() {
// Nothing to do here
}
Ok I seem to have found the solution :).
The init of the display needs to get custom SPI variable in order to work:
// Create SPI settings with speed, data order, and mode
SPISettings spiSettings(4000000, MSBFIRST, SPI_MODE0); // 4 MHz speed, MSB first, SPI mode 0
//Now let's see if GxEPD2 works aswell
display = new GxEPD2_BW<GxEPD2_150_BN, GxEPD2_150_BN::HEIGHT>(GxEPD2_150_BN(ePaper_Cs, ePaper_Dc, ePaper_Rst, ePaper_Busy));
And in case you need a full example, here is the working "hello world" code completely
#include <GxEPD2_BW.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Wire.h>
#include <SPI.h>
// Declare the display class and custom SPI settings
SPISettings spiSettings(4000000, MSBFIRST, SPI_MODE0); // 4 MHz speed, MSB first, SPI mode 0
GxEPD2_BW<GxEPD2_150_BN, GxEPD2_150_BN::HEIGHT>* display; // Pointer for dynamic allocation
SPIClass* dispPort;
// Pin definitions for the e-paper display
const int ePaper_Miso = 6; // Define these based on your hardware setup
const int ePaper_Mosi = 29;
const int ePaper_Sclk = 31;
const int ePaper_Cs = 30;
const int ePaper_Dc = 28;
const int ePaper_Rst = 2;
const int ePaper_Busy = 3;
void setup() {
// Start Serial Monitor
Serial.begin(115200);
while (!Serial) {
; // Wait for serial to be ready
}
Serial.println("Serial initialized...");
// Create a new SPIClass instance for the e-paper display
dispPort = new SPIClass(NRF_SPIM2, ePaper_Miso, ePaper_Sclk, ePaper_Mosi);
// Initialize the SPI port
dispPort->begin();
// Dynamically allocate memory for the GxEPD2 display object
display = new GxEPD2_BW<GxEPD2_150_BN, GxEPD2_150_BN::HEIGHT>(GxEPD2_150_BN(ePaper_Cs, ePaper_Dc, ePaper_Rst, ePaper_Busy));
// Initialize the display with custom SPI class and settings
display->init(115200, true, 20, false, *dispPort, spiSettings);
Serial.println("Display initialized with custom SPI.");
// Set display rotation, fill screen, and set text properties
display->setRotation(3);
display->fillScreen(GxEPD_WHITE);
display->setTextColor(GxEPD_BLACK);
display->setFont(&FreeMonoBold9pt7b);
// Draw "Hello World" on the display
display->firstPage();
do {
display->setCursor(10, 40);
display->print("Hello world!");
} while (display->nextPage());
// Refresh the display to show the content
display->refresh();
Serial.println("Display update complete.");
}
void loop() {
// Nothing to do here
}
In all the examples GxDEPG0150BN.h is used to display something on the screen. This works partially, because display->updateWindow() makes the screen flicker completely white, even when I only update a small region.
So I want to upgrade to GxEPD2 to avoid flickering and have better control with paging. However I cannot get it to display anything. I use the following code, but not sure why this is not working:
Note that display_v1 is working for the normal GxEPD v1, but the code with display-> does nothing.