-
Notifications
You must be signed in to change notification settings - Fork 7.6k
eeprom can't work #2174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Not sure if it is an issue with the structure you are using? This works for me:
|
Thank you for your answer. EEPROMClass INFO("eeprom0", 0x1000); void setup() { } void loop() { This output is correct. step 2 upload this #include <EEPROM.h> EEPROMClass INFO("eeprom0", 0x1000); void setup() { } void loop() { no output This output is error. |
I had the same problem. 😂 |
Ok, I looked through the code to refresh my memory of how this works. |
EEPROM.begin(EEPROM.length()) 改为固定大小似乎可以, 比如 EEPROM.begin(2048); |
#include <MyConfig.h>
#include <M5Stack.h>
MyConfig myConfig;
MyConfig::WifiInfo info;
void setup()
{
Serial.begin(9600);
Serial.println();
Serial.println("start");
myConfig.saveWifiInfo(info);
delay(100);
MyConfig::WifiInfo temp = myConfig.readWifiInfo();
delay(100);
Serial.println(temp.ssid.c_str());
Serial.println(temp.pwd.c_str());
Serial.println("done");
}
void loop()
{
// put your main code here, to run repeatedly:
}
#ifndef MY_CHONFIG_H
#define MY_CHONFIG_H
#include <WString.h>
class MyConfig
{
public:
struct WifiInfo
{
String ssid;
String pwd;
};
void saveWifiInfo(WifiInfo info);
WifiInfo readWifiInfo();
};
#endif
#include <MyConfig.h>
#include "EEPROM.h"
EEPROMClass INFO("eeprom0", 0x1000);
void MyConfig::saveWifiInfo(MyConfig::WifiInfo info)
{
INFO.put(0, info);
INFO.commit();
}
MyConfig::WifiInfo MyConfig::readWifiInfo()
{
MyConfig::WifiInfo temp;
temp = INFO.get(0, temp);
return temp;
}
output:
start
0
done
The text was updated successfully, but these errors were encountered: