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

Menu system for LCD Plates

Postby aufder » Sun Feb 17, 2013 1:30 am

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
aufder
 
Posts: 12
Joined: Tue Jan 15, 2013 9:07 pm


Re: Menu system for LCD Plates

Postby bbkiwi » Sun Feb 17, 2013 11:31 pm

Very nice. I ran it using WebIDE. I had to change line 32 of lcdmenu.py to ON to see the display.
bbkiwi
 
Posts: 9
Joined: Thu Jan 31, 2013 9:08 pm

Re: Menu system for LCD Plates

Postby aufder » Mon Feb 18, 2013 11:03 am

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
aufder
 
Posts: 12
Joined: Tue Jan 15, 2013 9:07 pm

Re: Menu system for LCD Plates

Postby bbkiwi » Mon Feb 18, 2013 9:22 pm

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.
bbkiwi
 
Posts: 9
Joined: Thu Jan 31, 2013 9:08 pm

Re: Menu system for LCD Plates

Postby aufder » Mon Feb 18, 2013 9:38 pm

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.
aufder
 
Posts: 12
Joined: Tue Jan 15, 2013 9:07 pm

Re: Menu system for LCD Plates

Postby TxBobS » Wed Feb 20, 2013 4:11 pm

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!
TxBobS
 
Posts: 7
Joined: Wed Jan 30, 2013 2:11 pm

Re: Menu system for LCD Plates

Postby wildtang3nt » Mon Mar 04, 2013 1:26 am

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)
wildtang3nt
 
Posts: 21
Joined: Thu Aug 09, 2012 1:31 pm
Location: Hamilton, Ontario, Canada

Re: Menu system for LCD Plates

Postby aufder » Mon Mar 04, 2013 10:02 am

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.
aufder
 
Posts: 12
Joined: Tue Jan 15, 2013 9:07 pm

Re: Menu system for LCD Plates

Postby wildtang3nt » Mon Mar 04, 2013 1:48 pm

Thanks! That worked perfectly :D
wildtang3nt
 
Posts: 21
Joined: Thu Aug 09, 2012 1:31 pm
Location: Hamilton, Ontario, Canada

Re: Menu system for LCD Plates

Postby wildtang3nt » Fri Mar 08, 2013 1:41 pm

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)
wildtang3nt
 
Posts: 21
Joined: Thu Aug 09, 2012 1:31 pm
Location: Hamilton, Ontario, Canada

Re: Menu system for LCD Plates

Postby djr » Tue Apr 16, 2013 3:23 pm

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?
djr
 
Posts: 5
Joined: Sat Feb 16, 2013 8:31 pm

Re: Menu system for LCD Plates

Postby azrith » Fri May 10, 2013 9:33 pm

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)
azrith
 
Posts: 1
Joined: Fri May 10, 2013 9:28 pm


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

Who is online

Users browsing this forum: No registered users and 11 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [105]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[108]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[69]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]