Created
November 15, 2019 19:38
-
-
Save rounakdatta/345964a13fe3b3b77fab2a11eaaaa5ab to your computer and use it in GitHub Desktop.
Sample program to demonstrate writing a character array to the EEPROM (flash) of ESP[32/8266]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "EEPROM.h" | |
int addr = 0; | |
#define EEPROM_SIZE 64 | |
// the sample text which we are storing in EEPROM | |
char ssid[64] = "CARNIVAL OF RUST"; | |
void setup() { | |
Serial.begin(115200); | |
Serial.println("starting now..."); | |
if (!EEPROM.begin(EEPROM_SIZE)) { | |
Serial.println("failed to init EEPROM"); | |
delay(1000000); | |
} | |
// writing byte-by-byte to EEPROM | |
for (int i = 0; i < EEPROM_SIZE; i++) { | |
EEPROM.write(addr, ssid[i]); | |
addr += 1; | |
} | |
EEPROM.commit(); | |
// reading byte-by-byte from EEPROM | |
for (int i = 0; i < EEPROM_SIZE; i++) { | |
byte readValue = EEPROM.read(i); | |
if (readValue == 0) { | |
break; | |
} | |
char readValueChar = char(readValue); | |
Serial.print(readValueChar); | |
} | |
} | |
void loop() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment