LCD Menu/SubMenu using PROGMEM?

Does anyone know of a library for an LCD menu/sub-menu system that uses PROGMEM?

I have been using this library previously GitHub - jonblack/arduino-menusystem: Arduino library for implementing a menu system which has been working great but the menu I need to add for my project has 700+ submenus/items, plus a handful of menus to hold them and it's smashing the SRAM big time.

I guess the basic functionality would need to be simply:

-Left (scroll menus or items)
-Right (scroll menus or items)
-Select (enter down into a sub-menu, or if it's an item then activate a function)
-Back (go back up to the previous menu)

I've had some success with storing/retrieving strings (const char []'s) in PROGMEM previously but with my very limited knowledge I can't get the menus/items from the library I mentioned above into Progmem too. I suspect it's not even possible.

If anyone knows of a better library to use, or is able to help me get my example code into PROGMEM using the library I've been using that would be even better.

I've attached the code in a zip. It's written with Visual Studio Code and the Platformio extension and includes both the menu library and also the PROGMEM_readAnything library I've also been trying to mess with to achieve this.

I did message a Mr Nick Gammon on PM but have since decided that maybe the forum is a better place so others can be helped too.

Thanks for any help/suggestions!!

Steve. (59.5 KB)

hm 700+ menus that's a lot

consider using an ESP32 nodeMCU 256KB of RAM

or a teensy 4.1: 1024 kB of RAM 8 MB flash SD-Card-socket with fast 4bit SDIO onboard $20

best regards Stefan

I'm on an Arduino Mega 2560 at the minute.

Before I uncomment all the menus I want to add in... (Not in my example code but my main project) I'm currently at:

RAM: [==== ] 43.3% (used 3549 bytes from 8192 bytes)
Flash: [== ] 21.7% (used 55174 bytes from 253952 bytes)

After I add them in I'm at:

RAM: [==========] 113.6% (used 9307 bytes from 8192 bytes)
Flash: [==== ] 42.0% (used 106740 bytes from 253952 bytes)

So I was hoping to be able to push as much as possible over into the Flash side of things if that's doable? Seems like enough space on the Flash side

Yes you can change it to use progmem. But this needs substantial changes to the library you are using.

And I guess this is something you don't want to do.

exception: If this library offers assigning menu-textes in an easy why on runtime (instead of compile-time) which means your code is executing and then you can assign menu-textes you can add functionality that reads in menu-textes from PROGMEM and assign it to the existing menu-system.

This means to examine the possabilities of this menu-library.

If you don't want to invest this time to examine the library - buying a microcontroller with much more RAM will finish the project in a shorter time. If your project does not use very exotic hardware the libraries should work with a teensy 4.1 too

If you would like tp stay with the Arduino Mega 2560 adding a SD-card and read in the menu-textes from there would be a solution too. But this requieres assigning menu-textes on runtime too

best regards Stefan

" But this needs substantial changes to the library you are using."

Yes, it seems it might, and I'm certain I don't have the knowledge yet to do this. I do understand the composite pattern a little bit but it's over my head to be honest!

But... maybe some clever people with hints/suggestions and some relentless googling on my part might be able to get there eventually.

I appreciate the help, and if you have any other ideas/thoughts, I'm all ears and very grateful!

I found a cool library called MD_Menu that seems to do the trick. After some messing, I think I've managed to store everything I need in progmem, but now it seems that the Arudino Mega has a 64k limit on usable progmem?

Because even though my stats are now:

RAM:   [====      ]  39.8% (used 3259 bytes from 8192 bytes)
Flash: [====      ]  43.5% (used 110462 bytes from 253952 bytes)

It causes digitalReads/Writes to now break and my previously working code jumps all over the place.

I found a cool library cal MD_Menu that seems to do the trick. After some messing, I think I've managed to store everything I need in progmem, but now it seems that the Arudino Mega has a 64k limit on usable progmem?

There is not a hard limit of 64K on usable PROGMEM, but accessing data stored above the 64K boundary is a bit more complicated, and most libraries are not written to handle it. The problem is caused by the use of 16-bit pointers, which can only address 64K bytes. When user data stored with PROGMEM nears 64K bytes, it starts to displace other items (such as the array that translates pin numbers to physical pins, text stored with the F() macro, etc) and causes the problems you are seeing. The compiler by default will store all PROGMEM data in the lower section of memory, followed by the sketch code, but there is a way to tell the compiler to store specific PROGMEM date after the code section, allowing use of all the flash memory for storage, but accessing the data has to be done slightly differently, and in your case would likely require modification of the library.

You would be better off using something other than a Mega that does not suffer from this complication.

a Mega2560 has a lot of IO-pins. How about reading in all your menutextes from SD-Card whenever a menu is called?

If you enjoy finding a solution with the Mega 2560 and climb over any hurdle that might come up just go on

IMHO such a BIG menu with more than 700! submenues cries at least for a BIG RAM µC like a teensy 4.1 with 1024 kB of RAM and 8096 KB of flash
or even for a Rasperry Pie at least to do the menu-stuff.

I have a teensy 4.0 and a teensy 4.1 and did some tests with them.
Installing the teensyduino addon was a breeze. Choose the teensy-board in the board-manager load a demo-code compile-upload starts the teenyloader automatically and program runs.

best regards Stefan

The Teensy 4.1 look amazing. Trouble is all my peripherals (my LCD and LEDs mainly) are all 5v and the Teensy is 3.3v. I could probably replace the LCD with a 3.3v version, but I can't find any WS2811 LEDs that are 3.3v.

Is there anything that matches the Teensy4.1 for ram/inputs but has 5v power? Or... a way to power LEDs that require 5v with a 3.3v micro?