Skip to content

Commit c3b02a6

Browse files
authored
V1.1.0 (#6)
* Update * Update README.md * Update * Update * Update * Update * Update * Update * Update * Added ESP8266 support * Update * Update library.properties * Update * Update EEPROM-Util.h * Update * Create invalid-address.ino * Update cloud.ino * Update EEPROM-Storage.h * Update Checksum.h * Update EEPROM-Storage.h * Update EEPROM-Storage.h * Update EEPROM-Storage.h * Update EEPROM-Storage.h * Updated * Update TestLibrary.h * Update tests.ino * Update EEPROM-Var.h * Update TestLibrary.h * Update EEPROM-Storage.h * Update tests.ino
1 parent 9aeb4d9 commit c3b02a6

File tree

25 files changed

+2611
-851
lines changed

25 files changed

+2611
-851
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ Consider the following variable definitions.
3333
EEPROMStorage<uint8_t> v1(0, 0); // 2 bytes (1 + 1 checksum), positions 0 and 1
3434
EEPROMStorage<uint16_t> v2(2, 0); // 3 bytes (2 + 1 checksum), positions 2, 3 and 4
3535
EEPROMStorage<uint32_t> v3(5, 0); // 5 bytes (4 + 1 checksum), positions 5, 6, 6, 8 and 9
36-
EEPROMStorage<float> v4(10, 0.0); // 5 bytes (4 + 1 checksum), positions 10, 11, 12, 13 and 14
37-
EEPROMStorage<bool> v5(15, false); // 2 bytes (1 + 1 checksum), positions 15, 16, 17, 18 and 19
36+
EEPROMStorage<float> v4(10, 0.0); // 5 bytes (4 + 1 checksum), positions 10, 11, 12, 13 and 14
37+
EEPROMStorage<bool> v5(15, false); // 2 bytes (1 + 1 checksum), positions 15, 16, 17, 18 and 19
3838

3939
The best way to think about EEPROM memory is to think about it as a large byte array with a base index of 0. In fact, the Arduino libraries construct access to EEPROM in this manner.
4040

@@ -46,6 +46,14 @@ The next variable, `v2`, is in the position 2, immediately following `v1`, and o
4646
4747
If you need help determining the proper address for your `EEPROMStorage` instances, open the example sketch called **address.ino** and follow the instructions.
4848

49+
Using the nextAddress() method will make it easier to align your variables in memory.
50+
51+
EEPROMStorage<uint8_t> v1(0, 0); // 2 bytes (1 + 1 checksum), positions 0 and 1
52+
EEPROMStorage<uint16_t> v2(v1.nextAddress(), 0); // 3 bytes (2 + 1 checksum), positions 2, 3 and 4
53+
EEPROMStorage<uint32_t> v3(v2.nextAddress(), 0); // 5 bytes (4 + 1 checksum), positions 5, 6, 6, 8 and 9
54+
EEPROMStorage<float> v4(v3.nextAddress(), 0.0); // 5 bytes (4 + 1 checksum), positions 10, 11, 12, 13 and 14
55+
EEPROMStorage<bool> v5(v4.nextAddress(), false); // 2 bytes (1 + 1 checksum), positions 15, 16, 17, 18 and 19
56+
4957
### Determining Data Type Size ###
5058
If you are not sure of the memory requirement for a given data type, you can use the `sizeof` operator. User the Serial port to display the size of any data type.
5159

examples/address/address.ino renamed to examples/address1/address1.ino

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@
1717
// see http://www.gnu.org/licenses/.
1818
//
1919

20-
// ***************************************************************************************
20+
// ---------------------------------------------------------------------------------------
2121
// This example will calculate the address and
2222
// create initialization code for one or more
2323
// EEPROM-Storage variables. Just follow the steps
2424
// outlined below.
25-
// ***************************************************************************************
26-
27-
// ***************************************************************************************
2825
//
2926
// Complete Steps 1 through 3 (below) for your project.
3027
//
31-
// ***************************************************************************************
28+
// ---------------------------------------------------------------------------------------
29+
30+
#include <EEPROM-Storage.h>
3231

3332
#if defined(SPARK)
3433
#define word short
@@ -95,7 +94,20 @@ void setup()
9594
// for native USB port only
9695
//
9796
while (!Serial);
97+
Serial.println();
9898

99+
//
100+
// On ESP8266 platforms EEPROM must be initialized.
101+
//
102+
#if defined(ESP8266)
103+
EEPROM.begin(4096);
104+
#endif
105+
106+
//
107+
// Display the EEPROM size.
108+
//
109+
Serial.print("The total size of EEPROM on this device is "); Serial.print(EEPROM.length()); Serial.println(" bytes.");
110+
99111
//
100112
// STEP 1 of 3:
101113
//
@@ -126,13 +138,13 @@ void setup()
126138
//
127139
bool showComments = true;
128140

129-
//***************************************************************************************
130-
//***************************************************************************************
141+
// ***************************************************************************************
142+
// ***************************************************************************************
131143
//
132144
// This will output declarations through the serial port.
133145
//
134-
//***************************************************************************************
135-
//***************************************************************************************
146+
// ***************************************************************************************
147+
// ***************************************************************************************
136148
int items = sizeof(myDefinitions) / sizeof(definition);
137149
Serial.print("The number of declarations defined is "); Serial.println(items);
138150
Serial.println();
@@ -160,4 +172,4 @@ void loop()
160172
// Delay 2 seconds.
161173
//
162174
delay(2000);
163-
}
175+
}

examples/address2/address2.ino

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright © 2017-2025 Daniel Porrey. All Rights Reserved.
2+
//
3+
// This file is part of the EEPROM-Storage library.
4+
//
5+
// EEPROM-Storage library is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Lesser General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// EEPROM-Storage library is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public License
16+
// along with EEPROM-Storage library. If not,
17+
// see http://www.gnu.org/licenses/.
18+
//
19+
20+
// ---------------------------------------------------------------------------------------
21+
// Displays the placement of EEPROM variables in memory when using nextAddress()
22+
// ---------------------------------------------------------------------------------------
23+
24+
#include <EEPROM-Storage.h>
25+
#include <EEPROM-Display.h>
26+
27+
//
28+
// Define the EEPROM variables.
29+
//
30+
EEPROMStorage<uint8_t> a(0, 0);
31+
EEPROMStorage<uint16_t> b(a.nextAddress(), 0);
32+
EEPROMStorage<uint32_t> c(b.nextAddress(), 0);
33+
EEPROMStorage<uint64_t> d(c.nextAddress(), 0);
34+
EEPROMStorage<float> e(d.nextAddress(), 0);
35+
EEPROMStorage<double> f(e.nextAddress(), 0);
36+
EEPROMStorage<char> g(f.nextAddress(), ' ');
37+
38+
void setup()
39+
{
40+
//
41+
// Initialize the serial port.
42+
//
43+
Serial.begin(115200);
44+
45+
//
46+
// Wait for serial port to connect. Needed
47+
// for native USB port only
48+
//
49+
while (!Serial);
50+
Serial.println();
51+
52+
//
53+
// On ESP8266 platforms EEPROM must be initialized.
54+
//
55+
#if defined(ESP8266)
56+
EEPROM.begin(4096);
57+
#endif
58+
59+
//
60+
// Display the EEPROM size.
61+
//
62+
Serial.print("The total size of EEPROM on this device is "); Serial.print(EEPROM.length()); Serial.println(" bytes.");
63+
64+
//
65+
// Clear EEPROM.
66+
//
67+
EEPROMUtil.clearEEPROM();
68+
69+
//
70+
// Initialize the random number generator.
71+
//
72+
randomSeed(analogRead(0));
73+
74+
//
75+
// Set random values to each EEPROM variable.
76+
//
77+
a = random(1, 255);
78+
b = random(1, 1000);
79+
c = random(1, 10000);
80+
d = random(1, 100000);
81+
e = random(1, 100);
82+
f = random(1, 100);
83+
g = 'y';
84+
85+
//
86+
// Display the EEPROM properties.
87+
//
88+
EEPROMDisplay.displayHeader();
89+
EEPROMDisplay.displayVariable("a", a);
90+
EEPROMDisplay.displayVariable("b", b);
91+
EEPROMDisplay.displayVariable("c", c);
92+
EEPROMDisplay.displayVariable("d", d);
93+
EEPROMDisplay.displayVariable("e", e);
94+
EEPROMDisplay.displayVariable("f", f);
95+
EEPROMDisplay.displayVariable("g", g);
96+
97+
//
98+
// Display the EEPROM contents.
99+
//
100+
Serial.println();
101+
EEPROMDisplay.displayEEPROM();
102+
}
103+
104+
void loop()
105+
{
106+
//
107+
// Delay 2 seconds.
108+
//
109+
delay(2000);
110+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
// Copyright © 2017-2025 Daniel Porrey. All Rights Reserved.
2+
//
3+
// This file is part of the EEPROM-Storage library.
4+
//
5+
// EEPROM-Storage library is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU Lesser General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// EEPROM-Storage library is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public License
16+
// along with EEPROM-Storage library. If not,
17+
// see http://www.gnu.org/licenses/.
18+
//
19+
20+
// ---------------------------------------------------------------------------------------
21+
// Displays the placement of EEPROM variables in memory when using nextAddress()
22+
// ---------------------------------------------------------------------------------------
23+
24+
#include <EEPROM-Storage.h>
25+
#include <EEPROM-Display.h>
26+
27+
//
28+
// Define a complex structure to store in EEPROM.
29+
//
30+
typedef struct {
31+
uint8_t sa;
32+
uint16_t sb;
33+
uint32_t sc;
34+
char sd;
35+
float se;
36+
double sf;
37+
} Matrix, *pmatrix;;
38+
39+
//
40+
// Define the EEPROM variable. Using the initialization
41+
// values of {0, 0, 0, ' ', 0, 0} as th default value.
42+
//
43+
EEPROMStorage<Matrix> a(0, {0, 0, 0, ' ', 0, 0});
44+
45+
void setup()
46+
{
47+
//
48+
// Initialize the serial port.
49+
//
50+
Serial.begin(115200);
51+
52+
//
53+
// Wait for serial port to connect. Needed
54+
// for native USB port only
55+
//
56+
while (!Serial);
57+
Serial.println();
58+
59+
//
60+
// On ESP8266 platforms EEPROM must be initialized.
61+
//
62+
#if defined(ESP8266)
63+
EEPROM.begin(4096);
64+
#endif
65+
66+
//
67+
// Display the EEPROM size.
68+
//
69+
Serial.print("The total size of EEPROM on this device is "); Serial.print(EEPROM.length()); Serial.println(" bytes.");
70+
71+
//
72+
// Clear EEPROM.
73+
//
74+
EEPROMUtil.clearEEPROM();
75+
76+
//
77+
// Initialize the random number generator.
78+
//
79+
randomSeed(analogRead(0));
80+
81+
//
82+
// Display the default values.
83+
//
84+
displayStruct("EEPROM default values:", "a.get()", a.get());
85+
86+
//
87+
// Create a Matrix struct and assign random
88+
// values to the struct properties.
89+
//
90+
a = { random(1, 255), random(1, 1000), random(1, 10000), 'y', random(1, 100), random(1, 100)};
91+
92+
//
93+
// Display the EEPROM properties.
94+
//
95+
Serial.println();
96+
Serial.println("EEPROM<T> Properties:");
97+
Serial.println("--------------------------------------------------------------------------------------------------------------");
98+
EEPROMDisplay.displayVariable("a", a);
99+
100+
//
101+
// Display the struct property values.
102+
//
103+
displayStruct("EEPROM struct values:", "a.get()", a.get());
104+
105+
//
106+
// Read the struct from EEPROM.
107+
//
108+
Matrix x = a;
109+
displayStruct("x struct:", "x", x);
110+
111+
//
112+
// Update the EEPROM struct values.
113+
//
114+
a = {99, 99, 99, 'z', 99.99, 99.99};
115+
displayStruct("Updated EEPROM struct values:", "a.get()", a.get());
116+
117+
//
118+
// Display the EEPROM contents.
119+
//
120+
Serial.println();
121+
EEPROMDisplay.displayEEPROM();
122+
}
123+
124+
void loop()
125+
{
126+
//
127+
// Delay 2 seconds.
128+
//
129+
delay(2000);
130+
}
131+
132+
void displayStruct(String label, String prefix, Matrix m)
133+
{
134+
//
135+
// Display the struct property values.
136+
//
137+
Serial.println();
138+
Serial.println(label);
139+
Serial.println("----------------------------------------");
140+
Serial.print(prefix); Serial.print(".sa = "); Serial.println(m.sa);
141+
Serial.print(prefix); Serial.print(".sb = "); Serial.println(m.sb);
142+
Serial.print(prefix); Serial.print(".sc = "); Serial.println(m.sc);
143+
Serial.print(prefix); Serial.print(".sd = "); Serial.println(m.sd);
144+
Serial.print(prefix); Serial.print(".se = "); Serial.println(m.se);
145+
Serial.print(prefix); Serial.print(".sf = "); Serial.println(m.sf);
146+
}

0 commit comments

Comments
 (0)