Menu system for LCD Plates

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
aufder
 
Posts: 13
Joined: Tue Jan 15, 2013 10:07 pm

Menu system for LCD Plates

Post by aufder »

Hey all,
(shameless plug)
I posted a menu system for the Raspberry Pi that uses an Adafruit LCD Plate (I'm using the 16x2 Positive) as the primary interface to the Pi. It allows you to define your own nested menu structure in an XML file, that then gets rendered as a navigable menu enabling you to create functions to run.
It allows you to get the IP address when it's headless and DHCP. It allows you to shut it down safely, and much much more.
Have fun figuring it out, and using it. It's my first project on git, so hope it all works for you.
https://github.com/aufder/RaspberryPiLcdMenu

Alan

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Menu system for LCD Plates

Post by adafruit_support_rick »

Thanks for posting this! :D

User avatar
bbkiwi
 
Posts: 11
Joined: Thu Jan 31, 2013 10:08 pm

Re: Menu system for LCD Plates

Post by bbkiwi »

Very nice. I ran it using WebIDE. I had to change line 32 of lcdmenu.py to ON to see the display.

User avatar
aufder
 
Posts: 13
Joined: Tue Jan 15, 2013 10:07 pm

Re: Menu system for LCD Plates

Post by aufder »

bbkiwi,
Maybe your contrast dial needs a tweak?
On mine, I can read the text even with the backlight off. Then I can optionally go into the LCD Color menu and pick a color which turns on the backlight.
Enjoy

User avatar
bbkiwi
 
Posts: 11
Joined: Thu Jan 31, 2013 10:08 pm

Re: Menu system for LCD Plates

Post by bbkiwi »

Ive got a Adafruit Blue&White 16x2 LCD+Keypad Kit for Raspberry Pi - ID: 1115. I never noticed that the display showed with
the backlight off. Even with the pot turned to the extreme, the characters are very faint with the backlight off.
I'm new to Python and your code is very instructive. Nice work.

User avatar
aufder
 
Posts: 13
Joined: Tue Jan 15, 2013 10:07 pm

Re: Menu system for LCD Plates

Post by aufder »

To assist bbkiwi, I just added support for some settings in the xml config file. You can set the lcd on and to a color by default on startup if you wish, or leave it off. Note the new settings by pulling the latest.

User avatar
txbobs
 
Posts: 22
Joined: Wed Jan 30, 2013 3:11 pm

Re: Menu system for LCD Plates

Post by txbobs »

Thanks for this. I pieced a simple little menu together last night but was hoping I could find some code that was more versatile. Thanks!

User avatar
wildtang3nt
 
Posts: 35
Joined: Thu Aug 09, 2012 2:31 pm

Re: Menu system for LCD Plates

Post by wildtang3nt »

Hi, I've added a function to show the kernel info, but I'd like to know how to add a second line for additional uname options. I was thinking uname -mo for the top line and uname -r for the lower. I don't have much python experience, I've been fumbling around with this unsuccessfully.

Here's what I have so far:

Code: Select all

def ShowKernel():
    if DEBUG:
        print('in ShowKernel')
    lcd.clear()
    lcd.message(commands.getoutput("/bin/uname -sr"))
    while 1:
         if lcd.buttonPressed(lcd.LEFT):
             break
         sleep(0.25)

User avatar
aufder
 
Posts: 13
Joined: Tue Jan 15, 2013 10:07 pm

Re: Menu system for LCD Plates

Post by aufder »

wildtang,
If you want to get the output of multiple commands, you'd have to join them together with a newline in between. Assuming each command does output only one line:

Code: Select all

    line1 = commands.getoutput("/bin/uname -mo")
    line2 = commands.getoutput("/bin/uname -r")
    lcd.message(line1 + '\n' + line2)
If in fact the command does output multiple lines already and you just want the first line from each, then you can do:

Code: Select all

    line1 = commands.getoutput("/bin/uname -mo").split('\n')
    line2 = commands.getoutput("/bin/uname -r").split('\n')
    lcd.message(line1[0] + '\n' + line2[0])
Hope that helps.

User avatar
wildtang3nt
 
Posts: 35
Joined: Thu Aug 09, 2012 2:31 pm

Re: Menu system for LCD Plates

Post by wildtang3nt »

Thanks! That worked perfectly :D

User avatar
wildtang3nt
 
Posts: 35
Joined: Thu Aug 09, 2012 2:31 pm

Re: Menu system for LCD Plates

Post by wildtang3nt »

I've modified added a couple useful functions to your code and thought it would be the neighbourly thing to do to share :D

http://dl.dropbox.com/u/14023002/lcdmenu.py

The parts I've added or extended:

Code: Select all

def DoReboot():
    lcd.clear()
    lcd.message('Are you sure?\nPress Sel for Y')
    while 1:
        if lcd.buttonPressed(lcd.LEFT):
            break
        if lcd.buttonPressed(lcd.SELECT):
            lcd.clear()
            lcd.backlight(lcd.OFF)
            commands.getoutput("sudo shutdown -r now")
            quit()
        sleep(0.25)
def DoEnableUSB():
    lcd.clear()
    lcd.message('Are you sure?\nPress Sel for Y')
    while 1:
        if lcd.buttonPressed(lcd.LEFT):
            break
        if lcd.buttonPressed(lcd.SELECT):
            lcd.clear()
            commands.getoutput("echo 0x1 > /sys/devices/platform/bcm2708_usb/buspower") 
            break
        sleep(0.25)

def DoDisableUSB():
    lcd.clear()
    lcd.message('Are you sure?\nPress Sel for Y')
    while 1:
        if lcd.buttonPressed(lcd.LEFT):
            break
        if lcd.buttonPressed(lcd.SELECT):
            lcd.clear()
            commands.getoutput("echo 0x0 > /sys/devices/platform/bcm2708_usb/buspower")
            break
        sleep(0.25)

def UpTime():
 
    try:
        f = open( "/proc/uptime" )
        contents = f.read().split()
        f.close()
    except:
       return "Cannot open file"

    total_seconds = float(contents[0])

    MINUTE  = 60
    HOUR    = MINUTE * 60
    DAY     = HOUR * 24
 
    days    = int( total_seconds / DAY )
    hours   = int( ( total_seconds % DAY ) / HOUR )
    minutes = int( ( total_seconds % HOUR ) / MINUTE )
    seconds = int( total_seconds % MINUTE )
 
    string = "Uptime:\n"
    if days > 0:
        string += str(days) + "d "
    if len(string) > 0 or hours > 0:
        string += str(hours) + "h "
    if len(string) > 0 or minutes > 0:
        string += str(minutes) + "m "
    string += str(seconds) + "s"
 
    return string;

def ShowUptime():
    if DEBUG:
        print('in ShowUptime')
    lcd.clear()
    while not(lcd.buttonPressed(lcd.LEFT)):
        sleep(0.25)
        lcd.home()
        lcd.message(UpTime())

def ShowKernel():
    if DEBUG:
        print('in ShowKernel')
    lcd.clear()
    line1 = commands.getoutput("/bin/uname -mo").split('\n')
    line2 = commands.getoutput("/bin/uname -r").split('\n') 
    lcd.message(line1[0] + '\n' + line2[0])
    while 1:
        if lcd.buttonPressed(lcd.LEFT):
            break
        sleep(0.25)

def ShowIPAddress():
    if DEBUG:
        print('in ShowIPAddress')
    lcd.clear()
    line1 = commands.getoutput("/bin/hostname")
    line2 = commands.getoutput("/sbin/ifconfig").split('\n')[1].split()[1][5:]
    lcd.message(line1 + '\n' + line2)
    while 1:
        if lcd.buttonPressed(lcd.LEFT):
            break
        sleep(0.25)

djr
 
Posts: 5
Joined: Sat Feb 16, 2013 9:31 pm

Re: Menu system for LCD Plates

Post by djr »

Very nicely done! Cant wait to start hacking it!! :)

I do, however, seem to be having an issue when pressing the buttons on the plate, it seems to jump rather quickly across certain menus choices. I havent done anything to the code. It starts off at System Info and Sensors but if I press the down button, it jumps all the way down to Quit and Shutdown. If i press the up button, it might jump up to Astronomy and Camera but usually it jumps back to the top. Should the dash follow the choice?

Any thoughts?

azrith
 
Posts: 8
Joined: Fri May 10, 2013 10:28 pm

Re: Menu system for LCD Plates

Post by azrith »

djr

I had the same issue. I found the issue to be the main loop that monitors buttons presses. It's looping so quickly it's catching multiple presses before you release the button. Adding a sleep delay in the loop should correct it.
Thanks for the awesome code everyone. I'll be using this for an automatic sprinkler timer I've put together.

Found in lcdmenu.py

Code: Select all

while 1:
if (lcd.buttonPressed(lcd.LEFT)):
display.update('l')
display.display()

if (lcd.buttonPressed(lcd.UP)):
display.update('u')
display.display()

if (lcd.buttonPressed(lcd.DOWN)):
display.update('d')
display.display()

if (lcd.buttonPressed(lcd.RIGHT)):
display.update('r')
display.display()

if (lcd.buttonPressed(lcd.SELECT)):
display.update('s')
display.display()
# Add the line below
sleep(.25)

User avatar
sub50hz
 
Posts: 2
Joined: Wed May 01, 2013 8:30 pm

Re: Menu system for LCD Plates

Post by sub50hz »

Sorry, this may seem like a noobish question, but where do I place the files so they can import the Adafruit modules?

User avatar
sub50hz
 
Posts: 2
Joined: Wed May 01, 2013 8:30 pm

Re: Menu system for LCD Plates

Post by sub50hz »

Wow, ignore -- feeling stupid today. Might be worth a mention that using the init.d method, I had to add an LSB block to the file header in order for it to run, then set it using insserv, even with proper permissions on the script.

Code: Select all

### BEGIN INIT INFO
# Provides:          scriptname
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”