Dynamic Menu for Arduino and LCD
Craig Hissett wrote 02/12/2017 at 15:15 • 1 pointHas anyone seen/used/wrote any good dynamic menus for arduino using the lcd shield w/buttons or similar?
For two of my projects I am in need of such a menu.
So far I have been able to write a basic menu with one level of submenus, using arrays as a source of the menu items (just the names, no functions attached as of yet)
Eventually I would like the menu information to be loaded from an sd card or passed via serial from a script on a PC, so need to have as little hard coded as possible.
Thanks in advance!
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
Just store the strings for your menu text in the EEPROM. You could even have a completely separate program, whose only purpose is to take input from serial, and write the necessary strings to EEPROM. Each string could be null-terminated, or you could have each string store it's length as a number just before it. Or you could have all the strings fixed-length. Which would waste memory but be a bit easier to program.
Then once the EEPROM is full of your strings, upload your menu program and read them in at the beginning of that. Store them as variables, and use them where you're currently using fixed, coded-in strings.
But do you really need the menu text to be changeable like that? What would be easier, is using #define for each of them. Set a load of #define at the beginning of your code, set the string values there, then when you compile, the compiler will substitute in your strings.
The advantage being it takes no EEPROM, no RAM to store your strings in use. It's also probably easier and requires no extra code. Disadvantage is, you'd only be able to change the menus by recompiling. But since serial is one of your options for being able to change the menus, you may as well go the whole hog and recompile whenever you want to change them. It's still just a matter of plugging in the USB cable.
Using #define like that, rules out using SD cards to change the menu titles. But is that so important? Might be able to save yourself a lot of trouble by just slightly adjusting your requirements.
Are you sure? yes | no
I wroted this one: https://github.com/radiolok/menuosv1
This is not only just a tree-type menu. It has a simple scheduler and can be named RTOS. I already used this one for more than 10 of mine projects. You can look how it works here (Russian sound but Eng menu titles):
PS: Github version has no tabs, so if you need it (I specialy wroted this for one project ) - ask me I'll publish the code (It should be somewhere).
Are you sure? yes | no
Artem, this is amazing.
What microcontroller is this running on in the video?
If it's possibly to run this on an Arduino then you are my favourine person of the day!
Are you sure? yes | no
Atmega1280 with arduino bootloader (Arduino mega).
It's not fully compatible with some arduino libraries - I used low-level programming and there might be some peripherial conflicts between menuos and some libraries if they use timers.
Are you sure? yes | no
Ah, that's brilliant!
I'm currently running my demo setups for my project on arduino megas; one with a 16x2 lcd & button shield, one with a Nokia screen & button shield. If i could get this running on those I'd be one happy chap.
Eventually I'd love to get a menu such as this running on an ATMega328-based microcontroller (Arduino Nano, due to it's small footprint). I may venture into using a different type of board if necessary though.
Thanks again man!
Are you sure? yes | no
It should be enough to set up MTask class to use Timer1 instead of Timer5. May be it will work if you just replace all 5 number in registers names into 1 - Timer1 and timer 5 API are equal.
And of course all hw pin definitions for buttons.
It should already work on text LCD 16x2 - you just need to define TEXT_DISPLAY instead of GRAPH_DISPLAY in hwdef header.
Look through sources in hw folder - You will need to add Nokia shield low-level implementation - look at hw/driver/disp/glcd implementation.
Edited: yeah.. I see a lot of workarounds for my devboard. I will use this menu as pure RTOS for my relay computer project and will do some improvements.
Are you sure? yes | no
This site has a pretty sweet menu set up: http://csabaszilvasi.com/thecode/
Youtube demo of it in action is here:
It uses a menu library to help create the menus.
I could substitute the string values provided to use my array values for names and suchlike. Much to ponder...
Are you sure? yes | no
Hi Craig, I wrote this Instructable on arduino menus for rotary encoders. I tried to keep away from libraries etc and keep it all in the sketch. Hopefully you can take something useful from it. http://www.instructables.com/id/Easy-Arduino-Menus-for-Rotary-Encoders/
Are you sure? yes | no
Thanks matey, will certainly have a look at this!
I can get a main menu loading nicely from an array of strings, and can navigate around that menu beautifully using the up/down buttons of the lcd shield and select the option with the 'right' button. Christ, I can even get it to then load a sub menu of sorts. I can't, however, get this menu to respond to the correct button presses or move back to the main menu.
I will get some of the code I've been worming on up on github tomorrow to give a better idea of what I'm trying to achieve :-)
I'd love to be able to get my menu/sub menus working nicely from arrays as later I would like menus to be called from an sd card or received via serial at a later date. If I get my menus working as planned I would just need to develop the arrays to make this happen.
I hope that makes sense!
Are you sure? yes | no
I think it makes sense to me but I'm not a software person so could be way off! I think the menu/sub menu in my code could work with an array. With more effort (the Instructable was just an example) you can add more sub menu layers and by referring to arrays you could probably reuse the same function again and again.
Are you sure? yes | no
Another tip to myself - after sorting the main menu look to writing a loop into the submenu to keep the code there while looking for button presses; Managing to get to the submenu but not being able to get it to do anything useful.
Also, look to add a 'back' option in the menu. This would remove the need to code a back button (the 'left' button on the lcd shield, most likely the 'B' button in the GBAA project).
Are you sure? yes | no
Just putting this here as a note to self:
http://www.hackshed.co.uk/arduino-lcd-keypad-shield-basic-menu-system/
This one gives demo code to create a really simple menu, using line 1 of the screen to display a title, and line 2 to show the selected menu option.
Changing this to load menu choices from an array rather than hardcoded options would be nice and easy, and would let me get a functional menu working pretty quickly.
Ideally I would like a 3 tier menu (main menu, submenu and sub-submenu) to give me enough options to organise all of my functions.
Are you sure? yes | no