EEPROM usage
What this example shows
Clear, write and read back the ESP32's EEPROM emulation, which keeps data when the power is removed. The sketch clears 128 bytes, writes the values 0 to 127 into them, then reads them back and shows them on the screen and in the Serial Monitor. You need only a USB cable.
This example also uses the EEPROM library (EEPROM.h) from arduino-esp32, which is not part of the Inkplate library and comes with the ESP32 board package.
Example code
#include "EEPROM.h" // Include ESP32 EEPROM library
#include "Inkplate.h" // Include Inkplate library to the sketch
#define EEPROM_SIZE 128 // How much data to write to EEPROM in this example
Inkplate inkplate; // Create object on Inkplate library and set library to work in monochrome mode
void setup() {
Serial.begin(115200); // Init serial monitor to display what's happening
inkplate.begin(); // Init library (you should call this function ONLY ONCE)
inkplate.setTextColor(INKPLATE_BLACK); // Set text color to black
// Init EEPROM library with 128 of EEPROM size.
EEPROM.begin(EEPROM_SIZE);
inkplate.setTextSize(3); // Set text size
Serial.println("Cleaning EEPROM..."); // Print message on serial monitor
clearEEPROM(); // Clear user EEPROM data
delay(500); // Wait a little bit...
Serial.println("Writing data to EEPROM..."); // Print message on serial monitor
writeEEPROM(); // Write some data to EEPROM
delay(500); // Wait a little bit...
inkplate.println("Reading data from EEPROM:\n"); // Print message on the screen
inkplate.println("Reding data from EEPROM..."); // Print message on the Sserial Monitor
inkplate.setTextSize(1); // Use smaller text so everything can fit on display
printEEPROM(); // Read data from EEPROM and display it on screen
delay(500); // Wait a little bit...
}
void loop() {
// Empty...
}
// Function for clearing EEPROM data
void clearEEPROM()
{
for(int i=0;i<EEPROM_SIZE;i++){
EEPROM.write(i,0);
}
EEPROM.commit();
}
// Function writes data to EEPROM
void writeEEPROM()
{
for(int i=0;i<EEPROM_SIZE;i++){
EEPROM.write(i,i);
}
EEPROM.commit();
}
// Function reads back previously written data and displays it on serial monitor and screen.
void printEEPROM()
{
for(int i=0;i<EEPROM_SIZE;i++){
inkplate.print(EEPROM.read(i), DEC);
Serial.print(EEPROM.read(i), DEC);
if(i != EEPROM_SIZE -1)
{
inkplate.print(", ");
Serial.print(", ");
}
}
inkplate.display();
}
The comment next to Inkplate inkplate; mentions a monochrome mode; Inkplate 7SPECTRA has only its six-color mode, and the constructor takes no mode. The line commented as a Serial Monitor message is printed on the screen, and its text is spelled "Reding" in the sketch.
Functions used
Inkplate()returns NoneCreates the Inkplate object. Inkplate 7SPECTRA has a single six-color mode, so the constructor takes no mode argument.
ReturnsConstructor; no return value.
inkplate.begin()returns voidInitializes the library, the peripherals and the frame buffer. Call it once in setup().
ReturnsNothing.
inkplate.setTextColor(uint16_t c)returns voidSets the text color, here INKPLATE_BLACK.
ReturnsNothing.
inkplate.setTextSize(uint8_t s)returns voidSets the text magnification: 3 for the two heading lines, then 1 so the 128 values fit.
ReturnsNothing.
inkplate.println(text)returns size_tPrints text into the frame buffer and moves to the next line.
ReturnsNumber of bytes printed.
inkplate.print(value, format)returns size_tPrints text or a number into the frame buffer, like Serial.print(). DEC prints a number in decimal.
ReturnsNumber of bytes printed.
inkplate.display(bool _leaveOn = 0)returns voidSends the whole frame buffer to the panel and refreshes it.
ReturnsNothing.
EEPROM.begin(size_t size)returns boolEEPROM library of the ESP32 board package: reserves the given number of bytes of EEPROM for use, here 128.
Returnstrue on success.
EEPROM.write(int address, uint8_t value)returns voidEEPROM library: writes one byte at the address. The change is kept in memory until you call commit().
ReturnsNothing.
EEPROM.commit()returns boolEEPROM library: stores the written bytes permanently.
Returnstrue on success.
EEPROM.read(int address)returns uint8_tEEPROM library: reads one byte from the address.
ReturnsThe stored byte.
Serial.begin(115200)returns voidArduino core function: starts the serial port at 115200 baud.
ReturnsNothing.
Serial.println(text)returns size_tArduino core function: prints a line to the Serial Monitor.
ReturnsNumber of bytes printed.
Serial.print(value, format)returns size_tArduino core function: prints text or a number to the Serial Monitor without a line break.
ReturnsNumber of bytes printed.
delay(ms)returns voidArduino core function: waits for the given number of milliseconds, here 500.
ReturnsNothing.
What to expect
With the Serial Monitor at 115200 baud, the sketch prints:
Cleaning EEPROM...
Writing data to EEPROM...
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127
The screen shows Reading data from EEPROM: and Reding data from EEPROM... in large black text, followed by the same list of values from 0 to 127 in small text.
🔗Open the complete example
examples/Inkplate7SPECTRA/Advanced/Other/Inkplate7SPECTRA_EEPROM_Usage