[Logo] TCC discussion forum
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Top Downloads] Top Downloads   [Groups] Back to home page 
[Register] Register /  [Login] Login 


This forum is read only and new users cannot register, please ask all new questions either using GitHub discussions, or in Arduino forum tagging @davetcc.

esp8266 does not save in eeprom RSS feed
Forum Index » tcMenu Arduinio library
Author Message
thevikas


Joined: Mar 16, 2021
Messages: 4
Offline
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.

davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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.
thevikas


Joined: Mar 16, 2021
Messages: 4
Offline
Sorry, I did not ask to saving during power down. I asked when does the save happen? or does it not happen automatically?
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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();
kitsen13


Joined: Jul 29, 2021
Messages: 15
Offline
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
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
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
kitsen13


Joined: Jul 29, 2021
Messages: 15
Offline
It works,

Thanks
 
Forum Index » tcMenu Arduinio library
Go to:   
Mobile view
Powered by JForum 2.7.0 © 2020 JForum Team • Maintained by Andowson Chang and Ulf Dittmer

This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK), and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.