Skip to content

Commit 269f287

Browse files
committed
Inkplate 10 EEPROM Waveform, EEPROM example
Wavefrom for Inkplate 10 is now inside ESP32 EEPROM instead of hardcoded in library. Modified VCOM factory programming for Inkplate 10 (added wavefrom EEPROM burning and removed VCOM bug after reset). Added EEPROM example. Added EERPOM Waveform programming example.
1 parent 270858b commit 269f287

File tree

7 files changed

+458
-46
lines changed

7 files changed

+458
-46
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
Inkplate_EEPROM_Usage example for e-radionica.com Inkplate 10
3+
For this example, you will need only USB cable and Inkplate 10.
4+
Select "Inkplate 10(ESP32)" from Tools -> Board menu.
5+
Don't have "Inkplate 10(ESP32)" option? Follow our tutorial and add it:
6+
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
7+
8+
This example will show you how to use EEPROM with Inkplate board.
9+
It shows how to use basic operations with EEPROM like clearing, writing, and reading.
10+
CAUTION! Changing EEPROM size can wipe waveform data.
11+
CAUTION! EEPROM addresses from 0 to 75 are used for waveform. DO NOT WRITE OR MODIFY DATA ON THESE ADDRESSES!
12+
13+
Want to learn more about Inkplate? Visit www.inkplate.io
14+
Looking to get support? Write on our forums: http://forum.e-radionica.com/en/
15+
13 March 2022 by e-radionica.com
16+
*/
17+
18+
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
19+
#ifndef ARDUINO_INKPLATE10
20+
#error "Wrong board selection for this example, please select Inkplate 10 in the boards menu."
21+
#endif
22+
23+
#include "EEPROM.h" // Include ESP32 EEPROM library
24+
#include "Inkplate.h" // Include Inkplate library to the sketch
25+
26+
#define EEPROM_START_ADDR 76 // Start EEPROM address for user data. Addresses below address 76 are waveform data!
27+
#define EEPROM_SIZE 128 // How much data to write to EEPROM in this example
28+
29+
Inkplate display(INKPLATE_1BIT); // Create object on Inkplate library and set library to work in monochrome mode
30+
31+
void setup()
32+
{
33+
display.begin(); // Init library (you should call this function ONLY ONCE)
34+
35+
// Init EEPROM library with 512 of EEPROM size. Do not change this value, it can wipe waveform data!
36+
EEPROM.begin(512);
37+
38+
display.setTextSize(4); // Set text size
39+
display.println("Clearing EEPROM...\n"); // Print message
40+
display.partialUpdate(); // Use partial updates for refreshing the display
41+
clearEEPROM(); // Clear user EEPROM data
42+
delay(500); // Wait a little bit...
43+
44+
display.println("Writing data to EEPROM...\n"); // Print message
45+
display.partialUpdate(); // Use partial updates for refreshing the display
46+
writeEEPROM(); // Write some data to EEPROM
47+
delay(500); // Wait a little bit...
48+
49+
display.println("Reading data from EEPROM:\n"); // Print message
50+
display.partialUpdate(); // Use partial updates for refreshing the display
51+
display.setTextSize(1); // Use smaller text so everything can fit on display
52+
printEEPROM(); // Read data from EEPROM and display it on screen
53+
delay(500); // Wait a little bit...
54+
}
55+
56+
void loop()
57+
{
58+
// Empty...
59+
}
60+
61+
// Function for clearing EEPROM data (it will NOT clear waveform data)
62+
void clearEEPROM()
63+
{
64+
for (int i = 0; i < EEPROM_SIZE; i++)
65+
{
66+
EEPROM.write(i + EEPROM_START_ADDR,
67+
0); // Start writing from address 76 (anything below that address number is waveform data!)
68+
}
69+
EEPROM.commit();
70+
}
71+
72+
// Function writes data to EEPROM
73+
void writeEEPROM()
74+
{
75+
for (int i = 0; i < EEPROM_SIZE; i++)
76+
{
77+
EEPROM.write(i + EEPROM_START_ADDR,
78+
i); // Start reading from address 76 (anything below that address number is waveform data!)
79+
}
80+
EEPROM.commit();
81+
}
82+
83+
// Function reads back previously written data and displays it on screen.
84+
void printEEPROM()
85+
{
86+
for (int i = 0; i < EEPROM_SIZE; i++)
87+
{
88+
display.print(EEPROM.read(i + EEPROM_START_ADDR), DEC);
89+
if (i != EEPROM_SIZE - 1)
90+
display.print(", ");
91+
}
92+
display.partialUpdate();
93+
}

examples/Inkplate10/Others/Inkplate_Factory_Programming_VCOM/Inkplate_Factory_Programming_VCOM.ino

Lines changed: 99 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
Inkplate display(INKPLATE_1BIT);
77

88
double vcomVoltage;
9-
int EEPROMaddress = 0;
9+
10+
// EEPROMOffset must be between 0 and 20
11+
const int EEPROMOffset = 0;
12+
int EEPROMaddress = sizeof(waveformData) + EEPROMOffset;
1013

1114
// Peripheral mode variables and arrays
1215
#define BUFFER_SIZE 1000
@@ -19,36 +22,89 @@ const char *testString = {"This is some test string..."};
1922
// Internal registers of MCP
2023
uint8_t mcpRegsInt[22];
2124

25+
// All waveforms for Inkplate 10 boards
26+
uint8_t waveform1[8][9] = {{0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 2, 2, 2, 1, 1, 0}, {0, 0, 2, 1, 1, 2, 2, 1, 0},
27+
{0, 1, 2, 2, 1, 2, 2, 1, 0}, {0, 0, 2, 1, 2, 2, 2, 1, 0}, {0, 2, 2, 2, 2, 2, 2, 1, 0},
28+
{0, 0, 0, 0, 0, 2, 1, 2, 0}, {0, 0, 0, 2, 2, 2, 2, 2, 0}};
29+
uint8_t waveform2[8][9] = {{0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 2, 1, 2, 1, 1, 0}, {0, 0, 0, 2, 2, 1, 2, 1, 0},
30+
{0, 0, 2, 2, 1, 2, 2, 1, 0}, {0, 0, 0, 2, 1, 1, 1, 2, 0}, {0, 0, 2, 2, 2, 1, 1, 2, 0},
31+
{0, 0, 0, 0, 0, 1, 2, 2, 0}, {0, 0, 0, 0, 2, 2, 2, 2, 0}};
32+
uint8_t waveform3[8][9] = {{0, 3, 3, 3, 3, 3, 3, 3, 0}, {0, 1, 2, 1, 1, 2, 2, 1, 0}, {0, 2, 2, 2, 1, 2, 2, 1, 0},
33+
{0, 0, 2, 2, 2, 2, 2, 1, 0}, {0, 3, 3, 2, 1, 1, 1, 2, 0}, {0, 3, 3, 2, 2, 1, 1, 2, 0},
34+
{0, 2, 1, 2, 1, 2, 1, 2, 0}, {0, 3, 3, 3, 2, 2, 2, 2, 0}};
35+
uint8_t *waveformList[] = {&waveform1[0][0], &waveform2[0][0], &waveform3[0][0]};
36+
37+
// Calculate number of possible waveforms
38+
uint8_t waveformListSize = (sizeof(waveformList) / sizeof(uint8_t *));
39+
40+
// Struct for reading waveform from EEPROM memory of ESP32
41+
struct waveformData waveformEEPROM;
42+
43+
int currentWaveform = 0;
44+
2245
void setup()
2346
{
24-
display.begin();
2547
Serial.begin(115200);
26-
EEPROM.begin(64);
48+
display.begin();
49+
EEPROM.begin(512);
2750

28-
vcomVoltage = -1.19;
51+
vcomVoltage = -1.3;
2952

53+
// Check if VCOM and waveform programming is not already done
3054
if (EEPROM.read(EEPROMaddress) != 170)
3155
{
3256
microSDCardTest();
3357
display.pinModeInternal(MCP23017_INT_ADDR, mcpRegsInt, 6, INPUT_PULLUP);
3458
writeVCOMToEEPROM(vcomVoltage);
3559
EEPROM.write(EEPROMaddress, 170);
3660
EEPROM.commit();
37-
display.selectDisplayMode(INKPLATE_1BIT);
61+
display.selectDisplayMode(INKPLATE_3BIT);
62+
63+
// Display all shades of gray on epaper with first waveform
64+
showGradient(currentWaveform);
65+
66+
// Until "Load" key is not pressed, user can select one of the waveforms
67+
while (!display.readTouchpad(PAD2))
68+
{
69+
// Select and show next waveform
70+
if (display.readTouchpad(PAD3))
71+
{
72+
currentWaveform++;
73+
if (currentWaveform > waveformListSize - 1)
74+
currentWaveform = 0;
75+
showGradient(currentWaveform);
76+
}
77+
78+
// Select and show prev. waveform
79+
if (display.readTouchpad(PAD1))
80+
{
81+
currentWaveform--;
82+
if (currentWaveform < 0)
83+
currentWaveform = waveformListSize - 1;
84+
showGradient(currentWaveform);
85+
}
86+
}
87+
88+
// Load waveform in EEPROM memory of ESP32
89+
waveformEEPROM.waveformId = INKPLATE10_WAVEFORM1 + currentWaveform;
90+
memcpy(&waveformEEPROM.waveform, waveformList[currentWaveform], sizeof(waveformEEPROM.waveform));
91+
waveformEEPROM.checksum = display.calculateChecksum(waveformEEPROM);
92+
display.burnWaveformToEEPROM(waveformEEPROM);
3893
}
3994
else
4095
{
41-
Serial.println("Vcom already set!");
42-
// vcomVoltage = (double)EEPROM.read(EEPROMaddress) / 100;
96+
Serial.println("Vcom and waveform already set!");
97+
display.einkOn();
98+
vcomVoltage = (double)(readReg(0x03) | ((uint16_t)(readReg(0x04 & 1) << 8))) / -100;
99+
display.getWaveformFromEEPROM(&waveformEEPROM) ? waveformEEPROM.waveformId : -1;
43100
}
44101
memset(commandBuffer, 0, BUFFER_SIZE);
45102

46-
showSplashScreen();
103+
showSplashScreen(waveformEEPROM);
47104
}
48105

49106
void loop()
50107
{
51-
52108
if (Serial.available())
53109
{
54110
while (Serial.available())
@@ -396,9 +452,9 @@ uint8_t readReg(uint8_t _reg)
396452
return Wire.read();
397453
}
398454

399-
void showSplashScreen()
455+
void showSplashScreen(struct waveformData _w)
400456
{
401-
display.clean(0, 1);
457+
display.clearDisplay();
402458
display.display();
403459
display.selectDisplayMode(INKPLATE_3BIT);
404460
display.drawBitmap3Bit(0, 0, demo_image, demo_image_w, demo_image_h);
@@ -407,6 +463,9 @@ void showSplashScreen()
407463
display.setCursor(10, 10);
408464
display.print(vcomVoltage, 2);
409465
display.print("V");
466+
display.setCursor(10, 20);
467+
display.print("Waveform");
468+
display.print(_w.waveformId - 20 + 1, DEC);
410469
display.display();
411470
}
412471

@@ -559,7 +618,35 @@ void microSDCardTest()
559618
{
560619
display.print("FAIL!");
561620
display.display();
562-
while(1);
621+
while (1)
622+
;
563623
}
564624
display.clearDisplay();
565625
}
626+
627+
void showGradient(int _selected)
628+
{
629+
int w = display.width() / 8;
630+
int h = display.height() - 100;
631+
632+
display.changeWaveform(waveformList[currentWaveform]);
633+
634+
display.fillRect(0, 725, 1200, 100, 7);
635+
636+
display.setTextSize(4);
637+
display.setTextColor(0);
638+
display.setCursor(420, 743);
639+
display.print("Waveform select");
640+
display.setCursor(432, 792);
641+
display.print("Prev Load Next");
642+
643+
display.setCursor(800, 743);
644+
display.print("1 2 3");
645+
display.drawRect((_selected * 6 * 4 * 2) + 800 - 3, 740, (6 * 4) + 2, (8 * 4) + 2, 0);
646+
647+
for (int i = 0; i < 8; i++)
648+
{
649+
display.fillRect(i * w, 0, w, h, i);
650+
}
651+
display.display();
652+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
Inkplate_Waveform_EEPROM_Programming example for e-radionica.com Inkplate 10
3+
For this example you will need only USB cable and Inkplate 10.
4+
Select "Inkplate 10(ESP32)" from Tools -> Board menu.
5+
Don't have "Inkplate 10(ESP32)" option? Follow our tutorial and add it:
6+
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
7+
8+
This example will program a new waveform in ESP32 EEPROM if the waveform has been accidentally overwritten.
9+
Upload code and with Touchpads 1 and 3 select waveform. It will show gradient lines on the display.
10+
They should go from dark to light. Select the one that looks the best to you.
11+
Select Touchpad 2 to select waveform and burn it into ESP32 EEPROM.
12+
CAUTION! Changing EEPROM size can wipe waveform data.
13+
Waveform data is stored in EEPROM on address range form address 0 to address 75.
14+
15+
Want to learn more about Inkplate? Visit www.inkplate.io
16+
Looking to get support? Write on our forums: http://forum.e-radionica.com/en/
17+
13 March 2022 by e-radionica.com
18+
*/
19+
20+
// Next 3 lines are a precaution, you can ignore those, and the example would also work without them
21+
#ifndef ARDUINO_INKPLATE10
22+
#error "Wrong board selection for this example, please select Inkplate 10 in the boards menu."
23+
#endif
24+
25+
#include "EEPROM.h" // Include ESP32 EEPROM library
26+
#include "Inkplate.h" // Include Inkplate library to the sketch
27+
28+
Inkplate display(INKPLATE_3BIT); // Create object on Inkplate library and set library to work in grayscale mode
29+
30+
// All waveforms for Inkplate 10 board
31+
uint8_t waveform1[8][9] = {{0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 0, 2, 2, 2, 1, 1, 0}, {0, 0, 2, 1, 1, 2, 2, 1, 0},
32+
{0, 1, 2, 2, 1, 2, 2, 1, 0}, {0, 0, 2, 1, 2, 2, 2, 1, 0}, {0, 2, 2, 2, 2, 2, 2, 1, 0},
33+
{0, 0, 0, 0, 0, 2, 1, 2, 0}, {0, 0, 0, 2, 2, 2, 2, 2, 0}};
34+
uint8_t waveform2[8][9] = {{0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 2, 1, 2, 1, 1, 0}, {0, 0, 0, 2, 2, 1, 2, 1, 0},
35+
{0, 0, 2, 2, 1, 2, 2, 1, 0}, {0, 0, 0, 2, 1, 1, 1, 2, 0}, {0, 0, 2, 2, 2, 1, 1, 2, 0},
36+
{0, 0, 0, 0, 0, 1, 2, 2, 0}, {0, 0, 0, 0, 2, 2, 2, 2, 0}};
37+
uint8_t waveform3[8][9] = {{0, 3, 3, 3, 3, 3, 3, 3, 0}, {0, 1, 2, 1, 1, 2, 2, 1, 0}, {0, 2, 2, 2, 1, 2, 2, 1, 0},
38+
{0, 0, 2, 2, 2, 2, 2, 1, 0}, {0, 3, 3, 2, 1, 1, 1, 2, 0}, {0, 3, 3, 2, 2, 1, 1, 2, 0},
39+
{0, 2, 1, 2, 1, 2, 1, 2, 0}, {0, 3, 3, 3, 2, 2, 2, 2, 0}};
40+
uint8_t *waveformList[] = {&waveform1[0][0], &waveform2[0][0], &waveform3[0][0]};
41+
42+
// Calculate number of possible waveforms
43+
uint8_t waveformListSize = (sizeof(waveformList) / sizeof(uint8_t *));
44+
45+
// Struct for reading waveform from EEPROM memory of ESP32
46+
struct waveformData waveformEEPROM;
47+
48+
int currentWaveform = 0;
49+
50+
void setup()
51+
{
52+
display.begin(); // Init library (you should call this function ONLY ONCE)
53+
EEPROM.begin(512); // Init EEPROM library with 512 of EEPROM size.
54+
55+
// Display all shades of gray on epaper with first waveform
56+
showGradient(currentWaveform);
57+
58+
// Until "Load" key is not pressed, user can select one of the waveforms
59+
while (!display.readTouchpad(PAD2))
60+
{
61+
// Select and show next waveform
62+
if (display.readTouchpad(PAD3))
63+
{
64+
currentWaveform++;
65+
if (currentWaveform > waveformListSize - 1)
66+
currentWaveform = 0;
67+
showGradient(currentWaveform);
68+
}
69+
70+
// Select and show prev. waveform
71+
if (display.readTouchpad(PAD1))
72+
{
73+
currentWaveform--;
74+
if (currentWaveform < 0)
75+
currentWaveform = waveformListSize - 1;
76+
showGradient(currentWaveform);
77+
}
78+
}
79+
80+
// Load waveform in EEPROM memory of ESP32
81+
waveformEEPROM.waveformId = INKPLATE10_WAVEFORM1 + currentWaveform;
82+
memcpy(&waveformEEPROM.waveform, waveformList[currentWaveform], sizeof(waveformEEPROM.waveform));
83+
waveformEEPROM.checksum = display.calculateChecksum(waveformEEPROM);
84+
display.burnWaveformToEEPROM(waveformEEPROM);
85+
86+
// Show message on the display
87+
display.clearDisplay();
88+
display.setCursor(10, 100);
89+
display.print("Waveform");
90+
display.print(currentWaveform + 1, DEC);
91+
display.print(" selected & programmed into ESP32 EEPROM");
92+
display.display();
93+
}
94+
95+
void loop()
96+
{
97+
// Empty...
98+
}
99+
100+
// Prints gradient lines and currently selected waveform
101+
void showGradient(int _selected)
102+
{
103+
int w = display.width() / 8;
104+
int h = display.height() - 100;
105+
106+
display.changeWaveform(waveformList[currentWaveform]);
107+
108+
display.fillRect(0, 725, 1200, 100, 7);
109+
110+
display.setTextSize(4);
111+
display.setTextColor(0);
112+
display.setCursor(420, 743);
113+
display.print("Waveform select");
114+
display.setCursor(432, 792);
115+
display.print("Prev Load Next");
116+
117+
display.setCursor(800, 743);
118+
display.print("1 2 3");
119+
display.drawRect((_selected * 6 * 4 * 2) + 800 - 3, 740, (6 * 4) + 2, (8 * 4) + 2, 0);
120+
121+
for (int i = 0; i < 8; i++)
122+
{
123+
display.fillRect(i * w, 0, w, h, i);
124+
}
125+
display.display();
126+
}

0 commit comments

Comments
 (0)