Using the example sketch in EEPROM library I can run the program (EEPROM, write) which is to load int 1 to ten in locations 1 to ten successfully, it appears. But when I use EEPROM. read for locations 1 to 20 I get 0 in every location. I have tried to write just any integer into a single location and then immediately read the location, I still get 0.
I have absolutely no idea where to go from here for further trouble shooting.
This sounds like a issue in the code. Can you share your sketch?
Here is the sketch. I tried to copy the com print out but it would not work with Window 10 right click copy.
#include <EEPROM.h>
int a = 0;
int value;
void setup()
{
for (int a = 0; a < 10; a++) {
EEPROM.write(a, 16);
delay(10); // waits for a number of millisecond
}
Serial.begin(9600);
value = EEPROM.read(a);
for (int a = 0; a < 20; a++) {
value = EEPROM.read(a);
Serial.print(a);
Serial.print("\t");
Serial.print(value);
Serial.println();
}
}
void loop()
{/*
for (int i = 0; i < 10; i++)
EEPROM.write(i, i);
value = EEPROM.read(a);
Serial.print(a);
Serial.print("\t");
Serial.print(value);
Serial.println();
a = a + 1;
if (a == 20)
a = 0;
delay(500); */
}
It appears that the issue is with your use of the variable ‘a’. You create a global variable ‘a’ under your #include. But when you call your first ‘for’ loop you create a local ‘a’ specific to the ‘for’ loop. Try changing the ‘for’ loop from using ‘a’ with ‘i’ or some other variable.
OK will try. I dii d read about local and clobal variables but never would have thought to apply it here. Whether it works or not I will go back and study this concept again.
Thanks, Rudy
No luck. I will upload how I changed sketch and, I hope, the output.
#include <EEPROM.h>
int a = 0;
int value;
void setup()
{
for (int i = 0; i < 10; i++) {
EEPROM.write(i, i);
delay(10); // waits for a number of millisecond
}
Serial.begin(9600);
value = EEPROM.read(a);
for (int b = 0; b < 20; b++) {
value = EEPROM.read(b);
Serial.print(b);
Serial.print("\t");
Serial.print(value);
Serial.println();
}
}
15:18:09.552 → ⸮⸮
15:18:09.606 → ⸮⸮⸮⸮⸮⸮f9⸮⸮⸮⸮)⸮⸮!
15:18:10.006 → ⸮?#⸮⸮⸮!⸮ұ0 0
15:18:10.206 → 1 0
15:18:10.206 → 2 0
15:18:10.253 → 3 0
15:18:10.253 → 4 0
15:18:10.253 → 5 0
15:18:10.253 → 6 0
15:18:10.253 → 7 0
15:18:10.253 → 8 0
15:18:10.253 → 9 0
15:18:10.253 → 10 0
15:18:10.253 → 11 0
15:18:10.307 → 12 0
15:18:10.307 → 13 0
15:18:10.307 → 14 0
15:18:10.307 → 15 0
15:18:10.307 → 16 0
15:18:10.307 → 17 0
15:18:10.307 → 18 0
15:18:10.307 → 19 0
TS-Brandon:
It appears that the issue is with your use of the variable ‘a’. You create a global variable ‘a’ under your #include. But when you call your first ‘for’ loop you create a local ‘a’ specific to the ‘for’ loop. Try changing the ‘for’ loop from using ‘a’ with ‘i’ or some other variable.
Please jump to this response. I have simplified my sketch to try to eliminate as many variables as possible. I will first submit the sketch showing one memory input and address, then show the output for two different memory input and locations.
My conclusion is that either the board never actually writes to the flash memory or that writing and reading use different addresses.
I did notice somewhere that Char = 0 is null and that must be why both monitor printouts stop after char output is because when I look at the monitor output itself nothing shows up. Also the byte output is also 0 for both outputs
#include <EEPROM.h>
byte valueByte;
char valueChar;
int valueInt;
int addressOfEEPROM = 55;
int Number_sent_to_memory = 40;
void setup() {
EEPROM.write(addressOfEEPROM, Number_sent_to_memory);
Serial.begin(9600);
valueInt = EEPROM.read(addressOfEEPROM);
valueChar = EEPROM.read(addressOfEEPROM);
valueByte = EEPROM.read(addressOfEEPROM);
Serial.print("\t");
Serial.print("Number sent to memory is ");
Serial.print(Number_sent_to_memory);
Serial.print(",\t");
Serial.print("Address is ");
Serial.print(addressOfEEPROM);
Serial.print(",\t");
Serial.print("Int is ");
Serial.print(valueInt);
Serial.print(",\t");
Serial.print("Char is ");
Serial.print(valueChar);
Serial.print(",\t");
Serial.print("Byte is ");
Serial.print(valueByte);
Serial.println();
}
void loop() {
// put your main code here, to run repeatedly:
}
Number is 40, Address is 55, Int is 0, Char is
Number is 15, Address is 28, Int is 0, Char is
This guide might be of better help when it comes to software specifics with ESP32 and EEPROM: https://www.electronics-lab.com/project … a-storage/
Thanks Brandon. This reference does give me a whole new line of exploration for my problem. The additional functions get me closer to a working sketch, but it still does not totally work. I will continue to play with this approach. If I still can’t make the flash drive work, I will initiate a new forum problem.
I must admit my old Fortran and Basic program skills are slowly coming back. Rudy