E-Paper Display Partial Refresh With Arduino
by CanadianWinters in Circuits > Arduino
19364 Views, 19 Favorites, 0 Comments
E-Paper Display Partial Refresh With Arduino
In this instructable I use a Waveshare 2.9" E-Paper display with an Arduino Nano to create a partial refresh window in order to display updating values without completely refreshing/rebooting the screen.
Update: Check out my new Istructable as well, where I use the Waveshare display, an ADS1115 and Arduino nano to build a precise voltmeter capable of measuring voltages up to 90v DC: https://www.instructables.com/Waveshare-E-ink-Display-Precise-Voltmeter-0-90v-DC/
Supplies
Supplies Used in this instructable:
1 x Arduino Nano - https://amzn.to/2TiPaHY
1 x Waveshare display - https://amzn.to/33N1XrD
Breadboard and wires - https://amzn.to/2z0KmjH
USB Power Bank - https://amzn.to/3cEhk7Q
CanadianWinters is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn fees by linking to Amazon.com and affiliated sites. By using these links, as an Amazon Associate I earn from qualifying purchases, even if you buy something else--and it won't cost you anything.
Wiring the Display
I wired the display to the Arduino Nano as follows:
Display <-> Arduino
BUSY <-> D7
RST <-> D8
DC <-> D9
CS <-> D10
DIN <-> D11
CLK <-> D13
VCC <-> 3.3V
GND <-> GND
Code
To test the display, I used the code provided by Waveshare at this link:
https://github.com/waveshare/e-Paper
Once I verified that the display was working, I created my own Arduino Sketch in order to perform a partial update of some values. In my code I use the input pin A0 as a floating value to be displayed on the screen.
The code uses the following libraries:
- GxEPD2
- U8g2_for_Adafruit_GFX
Here is the code:
#define ENABLE_GxEPD2_GFX 0
#include <GxEPD2_BW.h>
#include <U8g2_for_Adafruit_GFX.h>
#if defined(__AVR)
#define MAX_DISPLAY_BUFFER_SIZE 800
#define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8))
GxEPD2_BW<GxEPD2_290, MAX_HEIGHT(GxEPD2_290)> display(GxEPD2_290(/*CS=10*/ SS, /*DC=*/ 9, /*RST=*/ 8, /*BUSY=*/ 7));
#endif
U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;
void setup()
{
display.init();
u8g2Fonts.begin(display); // connect u8g2 procedures to Adafruit GFX
delay(1000);
}
void loop()
{
display.fillScreen(GxEPD_WHITE);
displayValues();
delay(1000);
}
void displayValues()
{
float number; //A0 Value
float number2; // A0 Value converted to voltage
number = analogRead(A0);
number2 = number/1023 * 5;
display.setRotation(1); // 0--> No rotation , 1--> rotate 90 deg
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
u8g2Fonts.setFont(u8g2_font_logisoso32_tr); //u8g2_font_logisoso32_tn--->numbers only to save memory ; u8g2_font_logisoso32_tr , u8g2_font_logisoso32_tf -->numbers&letters
uint16_t x = 150;
uint16_t y = 50;
display.setPartialWindow(0, 0, display.width(), 296); //this sets a window for the partial update, so the values can update without refreshing the entire screen.
display.firstPage();
do
{
display.fillScreen(bg);
// Display A0 value
u8g2Fonts.setCursor(90, y);
u8g2Fonts.print("A0:");
u8g2Fonts.setCursor(x, y);
u8g2Fonts.println(number,1);
// Display Voltage of A0
u8g2Fonts.setCursor(50, y +40);
u8g2Fonts.print("Volts:");
u8g2Fonts.setCursor(x, y + 40);
u8g2Fonts.println(number2,1);
}
while (display.nextPage());
}
I hope you've found this instructable useful!