Shelf label on an Arduino Uno
A 2.9 inch SSD1680 e-paper price tag driven with GxEPD2: drawn once with a full refresh, marked down with a partial one, and kept with the power off. The whole build, an Arduino Uno and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Intermediate About 20 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $44. On Mokxi they're free.
Step by step, with the wiring and the common mistakes: Arduino E-Paper Display: GxEPD2 on a 2.9 Inch Panel
What you'll learn
- How e-paper keeps an image with no power
- Full refresh versus partial refresh
- Drawing in pages with GxEPD2 on a small-RAM board
- Wiring an SPI display with CS, DC, RES and BUSY
- Toggling a state with a button
- Difficulty: Intermediate
- Time: About 20 minutes
- Board: Arduino Uno R3
- Parts: 4
How it works
A 2.9 inch e-paper panel shows a shop price tag: FRESH BREAD, Sourdough, 800 g and a big price of $4.99. The sketch draws the whole label once with a full refresh, which takes about three seconds, and then puts the display to sleep.
E-paper keeps its picture with no power. Pressing the button on pin 2 marks the price down to $2.99, and pressing again restores it. That redraws only the price area with a partial refresh, not the whole screen.
Parts list
4 parts, plus the jumper wires. They retail for about $44; on Mokxi they're free.
- 1 × Arduino Uno R3In Starter Kit, Claw Machine Kit, Vending Machine Kit.
- 1 × Half breadboard
- 1 × E-paper display, 2.9 inch
- 1 × PushbuttonIn Starter Kit, Christmas Lights Kit, Logic Lab Kit.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| E-paper display, 2.9 inch pin GND | Arduino Uno R3 pin GND |
| E-paper display, 2.9 inch pin SCL | Arduino Uno R3 pin 13 |
| E-paper display, 2.9 inch pin SDA | Arduino Uno R3 pin 11 |
| E-paper display, 2.9 inch pin CS | Arduino Uno R3 pin 10 |
| E-paper display, 2.9 inch pin DC | Arduino Uno R3 pin 9 |
| E-paper display, 2.9 inch pin RES | Arduino Uno R3 pin 8 |
| E-paper display, 2.9 inch pin BUSY | Arduino Uno R3 pin 7 |
| Pushbutton pin 1a | Arduino Uno R3 pin 2 |
| E-paper display, 2.9 inch pin VCC | Arduino Uno R3 pin 3V3 |
| Pushbutton pin 2a | Arduino Uno R3 pin GND |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Shelf label: a 2.9 inch e-paper panel on an SSD1680, driven with GxEPD2,
// as the price tag on a shop shelf.
//
// e-paper SCL (CLK) -> 13 SDA (DIN) -> 11 CS -> 10 DC -> 9
// RES (RST) -> 8 BUSY -> 7 VCC -> 3.3 V GND -> GND
// button pin 2 to GND (the pin's pull-up holds it high)
//
// The label is drawn with a full refresh, about three seconds with BUSY
// high, and then the controller sleeps: e-paper keeps the picture with no
// power, which is why shelf labels run for years on a coin cell. The button
// marks the item down with a partial refresh of the price alone.
//
// The panel is 296 x 128 pixels; GxEPD2 draws it in pages that fit this
// board's RAM.
#include <GxEPD2_BW.h>
#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_BS, MAX_HEIGHT(GxEPD2_290_BS)>
display(GxEPD2_290_BS(10, 9, 8, 7)); // CS, DC, RES, BUSY
const int BUTTON = 2;
bool sale = false;
void price() {
display.fillRect(150, 40, 146, 60, GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK);
display.setTextSize(4);
display.setCursor(156, 52);
display.print(sale ? "$2.99" : "$4.99");
}
void drawLabel() {
display.setFullWindow();
display.firstPage();
do {
display.fillScreen(GxEPD_WHITE);
display.fillRect(0, 0, 296, 28, GxEPD_BLACK);
display.setTextColor(GxEPD_WHITE);
display.setTextSize(2);
display.setCursor(8, 6);
display.print("FRESH BREAD");
display.setTextColor(GxEPD_BLACK);
display.setTextSize(2);
display.setCursor(8, 52);
display.print("Sourdough");
display.setCursor(8, 76);
display.print("800 g");
display.drawFastHLine(8, 108, 280, GxEPD_BLACK);
price();
} while (display.nextPage());
}
void drawPrice() {
display.setPartialWindow(150, 40, 146, 60);
display.firstPage();
do {
price();
} while (display.nextPage());
}
void setup() {
Serial.begin(9600);
pinMode(BUTTON, INPUT_PULLUP);
display.init(115200);
display.setRotation(1);
drawLabel();
display.hibernate();
Serial.println("label drawn");
}
void loop() {
if (digitalRead(BUTTON) == LOW) {
sale = !sale;
drawPrice();
display.hibernate();
Serial.println(sale ? "marked down" : "full price");
delay(300);
}
}
Code walkthrough
The key functions of the sketch, and what each one does.
drawLabel sketch.ino
Draws the whole tag in a full window: a black header bar with white text, the product name and weight, a line, and the price. The do ... while (display.nextPage()) loop repeats the drawing for each page of the screen buffer.
void drawLabel() {
display.setFullWindow();
display.firstPage();
do {
display.fillScreen(GxEPD_WHITE);
display.fillRect(0, 0, 296, 28, GxEPD_BLACK);
display.setTextColor(GxEPD_WHITE);
display.setTextSize(2);
display.setCursor(8, 6);
display.print("FRESH BREAD");
display.setTextColor(GxEPD_BLACK);
display.setTextSize(2);
display.setCursor(8, 52);
display.print("Sourdough");
display.setCursor(8, 76);
display.print("800 g");
display.drawFastHLine(8, 108, 280, GxEPD_BLACK);
price();
} while (display.nextPage());
}drawPrice sketch.ino
Sets a partial window that covers only the price box, and redraws just that. It is faster and flashes less than a full refresh.
void drawPrice() {
display.setPartialWindow(150, 40, 146, 60);
display.firstPage();
do {
price();
} while (display.nextPage());
}loop sketch.ino
Waits for the button. A press flips sale, calls drawPrice, then hibernate puts the panel back to sleep. A 300 ms delay stops one press from repeating.
void loop() {
if (digitalRead(BUTTON) == LOW) {
sale = !sale;
drawPrice();
display.hibernate();
Serial.println(sale ? "marked down" : "full price");
delay(300);
}
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The screen never updates This project
Check the SPI wires: SCL on pin 13, SDA on pin 11, CS on pin 10, DC on pin 9, RES on pin 8 and BUSY on pin 7. - The panel is unpowered or unreliable This project
The display's VCC goes to the 3.3 V pin, not 5 V. - The display flickers or shows ghost images. E-paper display
Use full refresh now and then to clear ghosting. Do not refresh more often than the maker suggests, since too many refreshes shorten the life of the panel. - Nothing updates or the screen stays blank. E-paper display
Check SPI wiring plus the DC, CS, RST and BUSY pins, and use 3.3 V logic. Wait for BUSY to go idle (about 3 seconds) before sending the next command. - The input reads random HIGH and LOW when the button is not pressed. Pushbutton
A floating pin picks up noise. Add a 10 k pull-down or pull-up resistor, or use INPUT_PULLUP and wire the button between the pin and GND. Then pressed reads LOW. - The button seems always pressed, or never changes. Pushbutton
A 4-leg tactile switch has legs joined in pairs. Place it across the breadboard center gap so the pairs sit on different rows. Wired along one side, the legs are already connected. - Upload fails or nothing runs after wiring pins 0 and 1 to a module. Arduino Uno R3
Pins 0 and 1 are the USB serial port. Move the module to other pins, or unplug it while uploading. Also check the right board is selected. - Pins misbehave or the board resets when you power motors or servos from it. Arduino Uno R3
Each I/O pin gives about 20 mA, 40 mA max. Power motors and servos from their own supply and join its ground to the Uno's GND.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.