Coding A Dynamic Menu For Character LCDs On Arduino

These days, there’s a huge variety of screens on the market for use with microcontrollers. OLEDs and graphic LCDs abound, while e-ink devices tempt the user with their clean look and low energy consumption. However, for many purposes, the humble HD44780 character LCD does the job just fine. If you’re using such a device, you might want to implement a simple menu system, and in that case, [MyHomeThings] has you covered.

The menu code is simple to modify and implement. It allows the user to define a certain number of menu items, along with button labels and functions to be executed with button presses. By default, it’s set up to work with  left and right function buttons, with up and down buttons to toggle through the menu’s various entries. This suits the commonly available Arduino shields which combine a 16×2 character LCD with a set of four tactile buttons in a cross formation. However, modifying the code to use an alternate button scheme would be simple for those eager to tweak things to their liking.

For the absolute beginner to programming, it’s a great way to put together a simple interface for your microcontroller projects. It’s the sort of thing you might use if you’d built a do-everything Arduino handheld device, as we’ve seen built before. If you find text menus too archaic for your purposes, though, be sure to sound off with your favourite solutions in the comments.

17 thoughts on “Coding A Dynamic Menu For Character LCDs On Arduino

  1. *clank* … That was me dropping it in the toolbox. Condemned a set of cordless phones that have 16×3 displays in them that look useful. COG though, not HD44780, so that might take some noodling around. I was thinking of using one in a variable PSU, got some of those cheap buck convertor modules, and another in an ESR meter. With pro-mini clones. Anyway, at least one of those might like a nifty menu.

    1. @GrizzlyAdams said: “Something funky is going on with their website. Chrome cpu usage shoots to 100% and locks up on mobile.”

      I pointed my Android Firefox mobile browser at the web site. Immediately the “Shield” in Firefox went purple and blocked ws.eu.amazon-adsystem.com (my privacy settings were set to high). After accepting the ubiquitous Cookie euro-nag, the rest of the page loaded without drama; no CPU spike. I would not be surprised if an ad via Amazon caused your Chrome to crash. It happens sometimes. I normally do not crank privacy up so high, especially on sites I know where the content creator deserves some ad revenue. Give Firefox mobile a try, there have been a lot of improvements lately.

  2. I wonder how hard it would be to build an embedded equivalent to libdialog where you just have to drop in a back-end for whatever text display system you have and ask for UI elements from the front end of the library.

  3. I wrote my own library to handle menu a long time ago and I have rewritten it a few times. It works from data structure instead of build it procedurally and calls the functions for the printing, inc/dec, next/prev entries etc. Thge data structure tells it the X,Y location, min/max values, increment, type of data, pointer to data etc.

    It might be a bit of code, but it pays off if you need multiple menus and/or sub menus or change it quickly.

    1. “Something funky is going on with their website. Chrome cpu usage shoots to 100% and locks up on mobile.”

      “Don’t open the link. It locks up android phone. The site is bad juju”

      Huh. Nothing out of the ordinary with macOS. Maybe the author just has a shoulder chip for Google.

  4. I did something similar, but I needed to do the menu with as few buttons as possible, for entering the WiFi password on a clock that synchronises with NTP.
    For me, pressing left/right buttons lots of times to get from A to z or back again wasn’t an option, so I used an encoder. That also includes a button (for backspace) and only one other button is needed (short press “add current character”, long press to accept password).

  5. To add to the list of “done it”s — I wrote a pretty functional menu system for a little DSP project, alas it doesn’t have that Arduino blog cred: https://github.com/T3sl4co1l/Reverb
    The trick I guess, is to include function pointers so, if anything needs to /do/ anything, just plop in a pointer and away you go. Probably not real efficient for code space, in terms of a state machine, but it’s easy enough to write in C this way.

Leave a Reply to Chris JCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.