Skip to content

Commit c6ea74e

Browse files
committed
Add setMemoryType() to examples
1 parent f613777 commit c6ea74e

File tree

8 files changed

+147
-29
lines changed

8 files changed

+147
-29
lines changed

examples/Example1_BasicReadWrite/Example1_BasicReadWrite.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ void setup()
4545
// 24xx128 - 131072 bit / 16384 bytes - 2 address bytes, 64 byte page
4646
// 24xx256 - 262144 bit / 32768 bytes - 2 address bytes, 64 byte page
4747
// 24xx512 - 524288 bit / 65536 bytes - 2 address bytes, 128 byte page
48-
// 24xx1024 - 1024000 bit / 128000 byte - 2 address byte, 128 byte page
48+
// 24xx1025 - 1024000 bit / 128000 byte - 2 address byte, 128 byte page
4949
// 24xxM02 - 2097152 bit / 262144 byte - 2 address bytes, 256 byte page
5050

51-
// Valid types: 24xx00, 01, 02, 04, 08, 16, 32, 64, 128, 256, 512, 1024, 2048
51+
// Valid types: 24xx00, 01, 02, 04, 08, 16, 32, 64, 128, 256, 512, 1025, 2048
5252
// myMem.setMemoryType(16);
5353

5454
// Default to the Qwiic 24xx512 EEPROM: https://www.sparkfun.com/products/14764
55-
myMem.setMemoryType(512); // Valid types: 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048
55+
myMem.setMemoryType(512); // Valid types: 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1025, 2048
5656

5757
if (myMem.begin() == false)
5858
{

examples/Example2_AdvancedI2C/Example2_AdvancedI2C.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ void setup()
4242
// Wire1.setClock(400000); //set I2C communication to 400kHz
4343
Wire1.begin();
4444

45+
// Default to the Qwiic 24xx512 EEPROM: https://www.sparkfun.com/products/14764
46+
myMem.setMemoryType(512); // Valid types: 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1025, 2048
47+
4548
#define EEPROM_ADDRESS 0b1010001 //0b1010(A2 A1 A0): A standard I2C EEPROM with the ADR0 bit set to VCC
46-
49+
4750
//Connect to a EEPROM with ADR0 set to VCC and use the Wire1 hardware to talk to the EEPROM
4851
if (myMem.begin(EEPROM_ADDRESS, Wire1) == false) //And Uno will fail to compile here
4952
{

examples/Example3_SettingsStruc/Example3_SettingsStruc.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ void setup()
5050

5151
Wire.begin();
5252

53+
// Default to the Qwiic 24xx512 EEPROM: https://www.sparkfun.com/products/14764
54+
myMem.setMemoryType(512); // Valid types: 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1025, 2048
55+
5356
if (myMem.begin() == false)
5457
{
5558
Serial.println(F("No memory detected. Freezing."));

examples/Example4_DetectSettings/Example4_DetectSettings.ino

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
License: Lemonadeware. Buy me a lemonade (or other) someday.
66
77
This sketch demonstrates how to detect memory size, address bytes,
8-
page size, and write time. You can also pre-assign these specs to avoid
9-
the start up delay caused by the detection routines.
8+
page size, and write time.
109
1110
Known/compatible memory types (basically all I2C EEPROMs):
1211
24xx00 - 128 bit / 16 bytes - 1 address byte, 1 byte page size
@@ -20,7 +19,7 @@
2019
24xx128 - 131072 bit / 16384 bytes - 2 address bytes, 64 byte page size
2120
24xx256 - 262144 bit / 32768 bytes - 2 address bytes, 64 byte page size
2221
24xx512 - 524288 bit / 65536 bytes - 2 address bytes, 128 byte page size
23-
24xx1024 - 1024000 bit / 128000 byte - 2 address bytes, 128 byte page size
22+
24xx1025 - 1024000 bit / 128000 byte - 2 address bytes, 128 byte page size
2423
24xxM02 - 2097152 bit / 262144 byte - 2 address bytes, 256 byte page size
2524
*/
2625

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
Explicitly tell the library the size of the EEPROM, page size, and address bytes
3+
Author: Nathan Seidle
4+
Created: June 23, 2023
5+
License: Lemonadeware. Buy me a lemonade (or other) someday.
6+
7+
This sketch demonstrates how to detect memory size, address bytes,
8+
page size, and write time. You can also pre-assign these specs to avoid
9+
the start up delay caused by the detection routines.
10+
11+
Known/compatible memory types (basically all I2C EEPROMs):
12+
24xx00 - 128 bit / 16 bytes - 1 address byte, 1 byte page size
13+
24xx01 - 1024 bit / 128 bytes - 1 address byte, 8 byte page size
14+
24xx02 - 2048 bit / 256 bytes - 1 address byte, 8 byte page size
15+
24xx04 - 4096 bit / 512 bytes - 1 address byte, 16 byte page size
16+
24xx08 - 8192 bit / 1024 bytes - 1 address byte, 16 byte page size
17+
24xx16 - 16384 bit / 2048 bytes - 1 address byte, 16 byte page size
18+
24xx32 - 32768 bit / 4096 bytes - 2 address bytes, 32 byte page size
19+
24xx64 - 65536 bit / 8192 bytes - 2 address bytes, 32 byte page size
20+
24xx128 - 131072 bit / 16384 bytes - 2 address bytes, 64 byte page size
21+
24xx256 - 262144 bit / 32768 bytes - 2 address bytes, 64 byte page size
22+
24xx512 - 524288 bit / 65536 bytes - 2 address bytes, 128 byte page size
23+
24xx1025 - 1024000 bit / 128000 byte - 2 address bytes, 128 byte page size
24+
24xxM02 - 2097152 bit / 262144 byte - 2 address bytes, 256 byte page size
25+
*/
26+
27+
#include <Wire.h>
28+
29+
#include "SparkFun_External_EEPROM.h" // Click here to get the library: http://librarymanager/All#SparkFun_External_EEPROM
30+
ExternalEEPROM myMem;
31+
32+
void setup()
33+
{
34+
Serial.begin(115200);
35+
Serial.println("Qwiic EEPROM example");
36+
37+
Wire.begin();
38+
39+
//Explicitly set the address bytes, page size, and memory size for this EEPROM
40+
// 24xx512 - 524288 bit / 65536 bytes - 2 address bytes, 128 byte page
41+
myMem.setAddressBytes(2);
42+
myMem.setPageSizeBytes(128);
43+
myMem.setMemorySizeBytes(65536);
44+
45+
if (myMem.begin() == false)
46+
{
47+
Serial.println("No memory detected. Freezing.");
48+
while (1)
49+
;
50+
}
51+
Serial.println("Memory detected!");
52+
53+
Serial.print("Mem size in bytes: ");
54+
Serial.println(myMem.length());
55+
56+
//Yes you can read and write bytes, but you shouldn't!
57+
byte myValue1 = 200;
58+
myMem.write(0, myValue1); //(location, data)
59+
60+
byte myRead1 = myMem.read(0);
61+
Serial.print("I read (should be 200): ");
62+
Serial.println(myRead1);
63+
64+
//You should use gets and puts. This will automatically and correctly arrange
65+
//the bytes for larger variable types.
66+
int myValue2 = -366;
67+
myMem.put(10, myValue2); //(location, data)
68+
int myRead2;
69+
myMem.get(10, myRead2); //location to read, thing to put data into
70+
Serial.print("I read (should be -366): ");
71+
Serial.println(myRead2);
72+
73+
float myValue3 = -7.35;
74+
myMem.put(20, myValue3); //(location, data)
75+
float myRead3;
76+
myMem.get(20, myRead3); //location to read, thing to put data into
77+
Serial.print("I read (should be -7.35): ");
78+
Serial.println(myRead3);
79+
80+
String myString = "Hi, I am just a simple test string";
81+
unsigned long nextEEPROMLocation = myMem.putString(30, myString);
82+
String myRead4 = "";
83+
myMem.getString(30, myRead4);
84+
Serial.print("I read: ");
85+
Serial.println(myRead4);
86+
Serial.print("Next available EEPROM location: ");
87+
Serial.println(nextEEPROMLocation);
88+
}
89+
90+
void loop()
91+
{
92+
}

examples/Example5_UniversalProgrammer/Example5_UniversalProgrammer.ino renamed to examples/Example6_UniversalProgrammer/Example6_UniversalProgrammer.ino

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ void setup()
7171
beginSD();
7272

7373
//Set settings for a 24LC1025
74-
myMem.setMemorySizeBytes(1024 * 1024 / 8); //In bytes. 1024 Kbit = 128 KB
75-
myMem.setPageSizeBytes(128); //In bytes.
76-
myMem.enablePollForWriteComplete();
74+
myMem.setMemoryType(1025); // Valid types: 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1025, 2048
7775
}
7876

7977
void loop()

examples/Example6_AutoDetectionTest/Example6_AutoDetectionTest.ino renamed to examples/Example7_AutoDetectionTest/Example7_AutoDetectionTest.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
24xx128 - 131072 bit / 16384 bytes - 2 address bytes, 64 byte page size
2121
24xx256 - 262144 bit / 32768 bytes - 2 address bytes, 64 byte page size
2222
24xx512 - 524288 bit / 65536 bytes - 2 address bytes, 128 byte page size
23-
24xx1024 - 1024000 bit / 128000 byte - 2 address bytes, 128 byte page size
23+
24xx1025 - 1024000 bit / 128000 byte - 2 address bytes, 128 byte page size
2424
24xxM02 - 2097152 bit / 262144 byte - 2 address bytes, 256 byte page size
2525
*/
2626

examples/Example7_InterfaceTest/Example7_InterfaceTest.ino renamed to examples/Example8_InterfaceTest/Example8_InterfaceTest.ino

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ void setup()
4141
//Wire.setClock(1000000);
4242

4343
//Set the memory specs
44-
//Default to the Qwiic 24xx512 EEPROM: https://www.sparkfun.com/products/14764
45-
myMem.setMemoryType(512); // Valid types: 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048
44+
myMem.setMemoryType(2); // Valid types: 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1025, 2048
4645

4746
if (myMem.begin() == false)
4847
{
@@ -124,8 +123,7 @@ void setup()
124123
Serial.print(myValue1);
125124
Serial.print(": ");
126125
Serial.print(response1);
127-
if(myValue1 != response1)
128-
Serial.print(" - Fail");
126+
if(myValue1 == response1 ? Serial.print(" - Success") : Serial.print(" - Fail"));
129127
Serial.println();
130128

131129
Serial.print("Location ");
@@ -134,8 +132,7 @@ void setup()
134132
Serial.print(myValue2);
135133
Serial.print(": ");
136134
Serial.print(response2);
137-
if(myValue2 != response2)
138-
Serial.print(" - Fail");
135+
if(myValue2 == response2 ? Serial.print(" - Success") : Serial.print(" - Fail"));
139136
Serial.println();
140137

141138
if (myValue1 != response1)
@@ -178,14 +175,18 @@ void setup()
178175
Serial.print(" should be ");
179176
Serial.print(myValue3);
180177
Serial.print(": ");
181-
Serial.println(response3);
178+
Serial.print(response3);
179+
if(myValue3 == response3 ? Serial.print(" - Success") : Serial.print(" - Fail"));
180+
Serial.println();
182181

183182
Serial.print("Location ");
184183
Serial.print(randomLocation + sizeof(int16_t));
185184
Serial.print(" should be ");
186185
Serial.print(myValue4);
187186
Serial.print(": ");
188-
Serial.println(response4);
187+
Serial.print(response4);
188+
if(myValue4 == response4 ? Serial.print(" - Success") : Serial.print(" - Fail"));
189+
Serial.println();
189190

190191
if (myValue3 != response3)
191192
allTestsPassed = false;
@@ -228,14 +229,19 @@ void setup()
228229
Serial.print(" should be ");
229230
Serial.print(myValue5);
230231
Serial.print(": ");
231-
Serial.println(response5);
232+
Serial.print(response5);
233+
if(myValue5 == response5 ? Serial.print(" - Success") : Serial.print(" - Fail"));
234+
Serial.println();
232235

233236
Serial.print("Location ");
234237
Serial.print(randomLocation + sizeof(int));
235238
Serial.print(" should be ");
236239
Serial.print(myValue6);
237240
Serial.print(": ");
238-
Serial.println(response6);
241+
Serial.print(response6);
242+
if(myValue6 == response6 ? Serial.print(" - Success") : Serial.print(" - Fail"));
243+
Serial.println();
244+
239245
if (myValue5 != response5)
240246
allTestsPassed = false;
241247
if (myValue6 != response6)
@@ -270,14 +276,19 @@ void setup()
270276
Serial.print(" should be ");
271277
Serial.print(myValue7);
272278
Serial.print(": ");
273-
Serial.println(response7);
279+
Serial.print(response7);
280+
if(myValue7 == response7 ? Serial.print(" - Success") : Serial.print(" - Fail"));
281+
Serial.println();
274282

275283
Serial.print("Location ");
276284
Serial.print(randomLocation + sizeof(int32_t));
277285
Serial.print(" should be ");
278286
Serial.print(myValue8);
279287
Serial.print(": ");
280-
Serial.println(response8);
288+
Serial.print(response8);
289+
if(myValue8 == response8 ? Serial.print(" - Success") : Serial.print(" - Fail"));
290+
Serial.println();
291+
281292
if (myValue7 != response7)
282293
allTestsPassed = false;
283294
if (myValue8 != response8)
@@ -311,14 +322,18 @@ void setup()
311322
Serial.print(" should be ");
312323
Serial.print(myValue9);
313324
Serial.print(": ");
314-
Serial.println(response9);
325+
Serial.print(response9);
326+
if(myValue9 == response9 ? Serial.print(" - Success") : Serial.print(" - Fail"));
327+
Serial.println();
315328

316329
Serial.print("Location ");
317330
Serial.print(randomLocation + sizeof(float));
318331
Serial.print(" should be ");
319332
Serial.print(myValue10);
320333
Serial.print(": ");
321-
Serial.println(response10);
334+
Serial.print(response10);
335+
if(myValue10 == response10 ? Serial.print(" - Success") : Serial.print(" - Fail"));
336+
Serial.println();
322337

323338
if (myValue9 != response9)
324339
allTestsPassed = false;
@@ -367,21 +382,27 @@ void setup()
367382
Serial.print(" should be ");
368383
Serial.print(myValue11);
369384
Serial.print(": ");
370-
Serial.println(response11);
385+
Serial.print(response11);
386+
if(myValue11 == response11 ? Serial.print(" - Success") : Serial.print(" - Fail"));
387+
Serial.println();
371388

372389
Serial.print("Location ");
373390
Serial.print(randomLocation + sizeof(double));
374391
Serial.print(" should be ");
375392
Serial.print(myValue12);
376393
Serial.print(": ");
377-
Serial.println(response12);
394+
Serial.print(response12);
395+
if(myValue12 == response12 ? Serial.print(" - Success") : Serial.print(" - Fail"));
396+
Serial.println();
378397

379398
Serial.print("Edge of EEPROM ");
380399
Serial.print(myMem.length() - sizeof(double));
381400
Serial.print(" should be ");
382401
Serial.print(myValue13);
383402
Serial.print(": ");
384-
Serial.println(response13);
403+
Serial.print(response13);
404+
if(myValue13 == response13 ? Serial.print(" - Success") : Serial.print(" - Fail"));
405+
Serial.println();
385406

386407
double response14;
387408
myMem.put(myMem.length() - sizeof(double), myValue14); //Test the re-write of a spot
@@ -391,7 +412,9 @@ void setup()
391412
Serial.print(" should be ");
392413
Serial.print(myValue14);
393414
Serial.print(": ");
394-
Serial.println(response14);
415+
Serial.print(response14);
416+
if(myValue14 == response14 ? Serial.print(" - Success") : Serial.print(" - Fail"));
417+
Serial.println();
395418

396419
if (myValue11 != response11)
397420
allTestsPassed = false;

0 commit comments

Comments
 (0)