Store data in EEPROM
What this example shows
Clearing, writing and reading back user data in the EEPROM, which survives resets and power cycles. The sketch starts its user area at address 76, because the example header says addresses 0 to 75 hold the e-paper waveform data.
Example code
Trimmed from the pinned example: only the file header comment is removed, the code is unchanged.
#if !defined(ARDUINO_INKPLATE10) && !defined(ARDUINO_INKPLATE10V2)
#error \
"Wrong board selection for this example, please select e-radionica Inkplate10 or Soldered Inkplate10 in the boards menu."
#endif
#include "EEPROM.h" // Include ESP32 EEPROM library
#include "Inkplate.h" // Include Inkplate library to the sketch
#define EEPROM_START_ADDR 76 // Start EEPROM address for user data. Addresses below address 76 are waveform data!
#define DATA_SIZE 128 // How much data to write to EEPROM in this example
#define EEPROM_SIZE EEPROM_START_ADDR + DATA_SIZE // End address of the EEPROM
Inkplate display(INKPLATE_1BIT); // Create object on Inkplate library and set library to work in monochrome mode
void setup()
{
display.begin(); // Init library (you should call this function ONLY ONCE)
// Init EEPROM library with EEPROM_SIZE size. Do not change this value, it can wipe waveform data!
EEPROM.begin(EEPROM_SIZE);
display.setTextSize(6); // Set text size
display.println("Clearing EEPROM...\n"); // Print message
display.display(); // Full refresh the display
clearEEPROM(); // Clear user EEPROM data
delay(500); // Wait a little bit...
display.println("Writing data to EEPROM...\n"); // Print message
display.partialUpdate(); // Use partial updates for refreshing the display
writeEEPROM(); // Write some data to EEPROM
delay(500); // Wait a little bit...
display.println("Reading data from EEPROM:\n"); // Print message
display.partialUpdate(); // Use partial updates for refreshing the display
display.setTextSize(3); // 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 (it will NOT clear waveform data)
void clearEEPROM()
{
for (int i = 0; i < DATA_SIZE; i++)
{
EEPROM.write(i + EEPROM_START_ADDR,
0); // Start writing from address 76 (anything below that address number is waveform data!)
}
EEPROM.commit();
}
// Function writes data to EEPROM
void writeEEPROM()
{
for (int i = 0; i < DATA_SIZE; i++)
{
EEPROM.write(i + EEPROM_START_ADDR,
i); // Start reading from address 76 (anything below that address number is waveform data!)
}
EEPROM.commit();
}
// Function reads back previously written data and displays it on screen.
void printEEPROM()
{
for (int i = 0; i < DATA_SIZE; i++)
{
display.print(EEPROM.read(i + EEPROM_START_ADDR), DEC);
if (i != DATA_SIZE - 1)
display.print(", ");
}
display.partialUpdate();
}
Functions used
Inkplate(uint8_t mode)returns NoneCreates the display object. `INKPLATE_1BIT` is black and white and supports partial updates. `INKPLATE_3BIT` gives 8 levels of grey but only full updates.
ReturnsConstructor; no return value.
Parameters
| Type | Name | Description |
|---|---|---|
uint8_t | mode | INKPLATE_1BIT or INKPLATE_3BIT. |
display.begin()returns voidInitializes the library and the display. Call it once, at the start of `setup()`.
ReturnsNothing.
EEPROM.begin(size_t size)returns boolStarts the ESP32 EEPROM library with the given size. The example warns not to change this value because it can wipe the waveform data.
ReturnsThe example does not use the return value.
Parameters
| Type | Name | Description |
|---|---|---|
size_t | size | EEPROM size in bytes. The example uses the user data start address plus the data size. |
display.setTextSize(uint8_t s)returns voidScales text by an integer factor. The base font is 5 x 7 pixels.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
uint8_t | s | Scale factor. |
display.println(value)returns size_tSame as `print()`, then moves the cursor to the start of the next line. It comes from the Arduino `Print` class that `Adafruit_GFX` builds on.
ReturnsNumber of bytes printed.
Parameters
| Type | Name | Description |
|---|---|---|
text or number | value | What to print. |
display.display(bool _leaveOn = 0)returns voidDoes a full refresh: sends the frame buffer to the panel. If `_leaveOn` is true, the panel supply stays on after the refresh, which saves time on the next update.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
bool | _leaveOn | Keeps the panel supply on after the update when true. Defaults to 0. |
display.partialUpdate(bool _forced = false, bool leaveOn = false)returns uint32_tRefreshes only the parts of the screen that changed, without a full refresh. It works only in `INKPLATE_1BIT` mode.
ReturnsNumber of pixels that changed from black to white, which can leave blur.
Parameters
| Type | Name | Description |
|---|---|---|
bool | _forced | Forces a partial update in cases the library would otherwise do a full one (advanced use with deep sleep). Defaults to false. |
bool | leaveOn | Keeps the panel supply on after the update when true. Defaults to false. |
delay(unsigned long ms)returns voidArduino function that pauses the sketch.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
unsigned long | ms | Time to wait in milliseconds. |
EEPROM.write(int address, uint8_t value)returns voidWrites one byte to the EEPROM buffer. The data stays in RAM until you call `EEPROM.commit()`.
ReturnsNothing.
Parameters
| Type | Name | Description |
|---|---|---|
int | address | EEPROM address. The example never goes below 76. |
uint8_t | value | Byte to store. |
EEPROM.commit()returns boolSaves the written bytes to flash so they survive resets and power cycles.
ReturnsThe example does not use the return value.
EEPROM.read(int address)returns uint8_tReads one byte from the EEPROM.
ReturnsThe stored byte.
Parameters
| Type | Name | Description |
|---|---|---|
int | address | EEPROM address. |
display.print(value)returns size_tPrints text or a number at the cursor. The `print` functions come from the Arduino `Print` class that `Adafruit_GFX` builds on. For a number, an optional second argument sets the decimal places of a float or the number base of an integer.
ReturnsNumber of bytes printed.
Parameters
| Type | Name | Description |
|---|---|---|
text, number or char | value | What to print. |
int | second argument (optional) | Decimal places for a float, or the base for an integer, for example DEC. |
What to expect
The display shows Clearing EEPROM..., Writing data to EEPROM... and Reading data from EEPROM:, followed by the 128 stored values as decimal numbers separated by commas, which are 0 to 127 in order. The loop() function is empty.
Do not read from or write to EEPROM addresses below 76, and do not change the size passed to EEPROM.begin(). The example header says this can erase the waveform data and affect the display.