Saving and writing to eeprom
Re: Saving and writing to eeprom
None taken. I'm still learning to code. I understand some of it. Ive been reading tutorials and the Arduino playground page. But esp32 is a lil different. Is this where I need to know the bits for each variable in the slot structure?
or do I need to define two addresses somehow
or do I need to define two addresses somehow
Fear is the mind killer.......
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
-
- Posts: 90
- Joined: Sun Jul 02, 2017 3:38 am
Re: Saving and writing to eeprom
Hint:
EEPROM.put(0, player);
EEPROM.put(sizeof(player), slots);
And something similar for get().
EEPROM.put(0, player);
EEPROM.put(sizeof(player), slots);
And something similar for get().
Re: Saving and writing to eeprom
ok so if Player uses 9 variables in its structure, all use int, that would be 36 for the size of player.
So something like this...
So something like this...
Code: Select all
void save()
{
EEPROM.put(0, player);
EEPROM.put(36, slots);
EEPROM.commit();
Serial.print("saved");
}
void load()
{
EEPROM.get(0, player);
EEPROM.get(36, slots);
}
Fear is the mind killer.......
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
-
- Posts: 90
- Joined: Sun Jul 02, 2017 3:38 am
Re: Saving and writing to eeprom
Yes, but it is bad practice to use a constant like 36. Better to use sizeof(player), let the compiler do the work.
And if it was me, I wouldn’t use EEPROM for data which will be written frequently. The esp32 EEPROM is a fixed region of the flash, and has a finite number of writes before it goes bad. I’d use SPIFFS, which presumably implements a wear-leveling technique.
The EEPROM library is more appropriate for seldom changed configuration data.
And if it was me, I wouldn’t use EEPROM for data which will be written frequently. The esp32 EEPROM is a fixed region of the flash, and has a finite number of writes before it goes bad. I’d use SPIFFS, which presumably implements a wear-leveling technique.
The EEPROM library is more appropriate for seldom changed configuration data.
Re: Saving and writing to eeprom
It didn't work. Could you link me to the correct spiffs library?
Fear is the mind killer.......
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
-
- Posts: 90
- Joined: Sun Jul 02, 2017 3:38 am
Re: Saving and writing to eeprom
Also worth mentioning, in the real world, data saved like this would usually have additional info saved indicating the version of the data. As your program evolves, it’s not unlikely that the data structures will change, and a previous ‘save’ will be incorrectly read by the new version.
As is, you’ll need to be aware of this if your data changes, and manually take steps to clear the incompatible save from EEPROM.
As is, you’ll need to be aware of this if your data changes, and manually take steps to clear the incompatible save from EEPROM.
Re: Saving and writing to eeprom
I'm all for learning something new.... looking at the SPIFFS library and its example but not really understanding it. Theres no notes on the functions.
Why does eeprom only have so many writes?
Where is the data actually being saved in the spiffs example?
Why does eeprom only have so many writes?
Where is the data actually being saved in the spiffs example?
Last edited by Duhjoker on Mon Feb 12, 2018 7:17 am, edited 1 time in total.
Fear is the mind killer.......
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
-
- Posts: 90
- Joined: Sun Jul 02, 2017 3:38 am
Re: Saving and writing to eeprom
SPIFFS should already be installed in you esp32 Arduino installation.
#include <SPIFFS.h>
Note: using SPIFFS involves learning how to use files. It’s much more involved than EEPROM. The are probably examples that can help, but there’s a lot to learn.
Flash memory wears out from writes. Google it. SPIFFS writes to flash, but wear-leveling moves the data around each time it’s written.
#include <SPIFFS.h>
Note: using SPIFFS involves learning how to use files. It’s much more involved than EEPROM. The are probably examples that can help, but there’s a lot to learn.
Flash memory wears out from writes. Google it. SPIFFS writes to flash, but wear-leveling moves the data around each time it’s written.
Re: Saving and writing to eeprom
Sounds like either way is going to burn out something. I honestly thought the esp32's eeprom partition was from flash.
So what would be the best way to store Data for my player and inventory slots?
So what would be the best way to store Data for my player and inventory slots?
Fear is the mind killer.......
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
Re: Saving and writing to eeprom
why not save to SD?
Fear is the mind killer.......
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
GameR the DIY iot gaming device that does more......
https://github.com/Duhjoker/GameR-Iot_ESP
Who is online
Users browsing this forum: No registered users and 37 guests