Register / Login  |  Desktop view  |  Jump to bottom of page

tcMenu Arduinio library » esp8266 does not save in eeprom

Author: thevikas
25/03/2021 08:32:42
Hi,

I started using tcmenu and it works in esp8266. I have marked date and time inputs to be saved in eeprom in the designer. The problem i find is the default does not either save in eeprom or load from it when the next time circuit is powered up. How do I debug this?

The event callback I had thought will send the value of the editor (date or time in my case) as second parameter. but thats not the case.

The alternate I have to use is have a action item called "Save" when date and time is set. So saveSettings callback is called, I actually fetch and save it myself.

Plz suggest how to get the library to save to eeprom automatically.


Author: davetcc
25/03/2021 09:30:32
There is no way that we can automatically save on power down, you would need to detect power loss in your PSU and handle it. Also, don't forget that on ESP boards the EEPROM is a flash emulation, it requires a call to its commit() method after menuMgr.save() has been called.

Event callbacks do not send the value, they send only the ID of the changed item, instead you just get the value directly from the menu item. EG if you have a root level analog item called Volume, you'd do menuVolume.getCurrentValue() to get it's value.

-- copied from an earlier post:

The best place to save is either to provide a save function somewhere on the menu, or to detect the power down state and then save during the power loss detection. See this page.

https://www.thecoderscorner.com/electronics/microcontrollers/psu-control/detecting-power-loss-in-powersupply/

You can also run a timer, once every few minutes and detect if anything has been committed using a commit handler, if it has then save the changes to ROM. See the commit handler docs: https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/menumanager-and-iteration/

However, never attempt to save to EEPROM in a callback, it will destroy your ESP's flash in days with a rotary encoder.

Author: thevikas
25/03/2021 11:24:16
Sorry, I did not ask to saving during power down. I asked when does the save happen? or does it not happen automatically?

Author: davetcc
25/03/2021 17:50:12
Ah I see, apologies there I misunderstood the question.

The best example to look at is simpleU8g2, it is pretty much the minimum code to start a menu and also load and save from eeprom.

https://github.com/davetcc/tcMenuLib/blob/master/examples/simpleU8g2/simpleU8g2.ino

In summary from the above linked sketch:

Function setup() has the calls needed to both initialise the EEPROM and to load the values back. Or for clarity BEFORE calling setupMenu() you should:

EEPROM.begin(512); // prepare ESP rom for 512 bytes
menuMgr.setEepromRef(&arduinoEeprom); // set it on menu manager


After calling setupMenu you would then load values back.

menuMgr.load();



Function onSaveSettings() has the code needed to save to the rom. Or to be clear:

menuMgr.save();
EEPROM.commit();

Author: kitsen13
17/08/2021 20:27:26
Hello Dave,

I have an ESP32 (heltek) , and I tried to integrate your solution to save to eeprom.

But some declarations needed, do you know that I have to include?

C:\Users\martal\Desktop\esp32_oled\test_menu\tcmenu\tcmenu.ino: In function 'void setup()':

tcmenu:72:5: error: 'EEPROM' was not declared in this scope

     EEPROM.begin(512); // prepare ESP rom for 512 bytes

     ^

tcmenu:73:27: error: 'arduinoEeprom' was not declared in this scope

     menuMgr.setEepromRef(&arduinoEeprom); // set it on menu manager

                           ^

C:\Users\martal\Desktop\esp32_oled\test_menu\tcmenu\tcmenu.ino: In function 'void onSaveSettings(int)':

tcmenu:141:5: error: 'EEPROM' was not declared in this scope

     EEPROM.commit();


In the example you have mentionned (https://github.com/davetcc/tcMenuLib/blob/master/e...ples/simpleU8g2/simpleU8g2.ino)
I haven't found any other declaration.

And what about type of &arduinoEeprom?

Thanks

Author: davetcc
17/08/2021 21:01:22
In 2.2 there is about to be a significant change in how EEPROMs are defined, from there on it can be configured within the designer, meaning much of this will be done automatically. Although you can continue to manually define eeproms, there would be little point once 2.2 comes out, as designer can add the base code.

However, for now, I think you'd be best going through the version 2.1 examples for this and working out how we've taken the steps.

https://github.com/davetcc/tcMenuLib/blob/2.1.3/examples/esp32Amplifier/esp32Amplifier_main.cpp

Author: kitsen13
18/08/2021 06:23:26
It works,

Thanks




Register / Login  |  Desktop view  |  Jump to top of page