Monday, September 15, 2014

Web control to display on Pi connected LCD Module, with Python and bottle

This post show how to build a simple web application on Raspberry Pi using Python + bottle, receive POST from client to display message on connected 2x16 LCD Module.


To install python-bottle on Raspberry Pi, refer to the post "Python + bottle@Raspberry Pi: Web based GPIO control".

The previouse post "2x16 LCD Display on Raspberry Pi" show how to connect and text 2x16 LCD Module on Raspberry Pi. To control the LCD Module with Python, the program Adafruit_CharLCD.py in the post is needed.

weblcd.py
from bottle import route, run
from bottle import post, request

from Adafruit_CharLCD import Adafruit_CharLCD
lcd = Adafruit_CharLCD()

host = '192.168.1.105'

@route('/')
def index():
    return '''
        <form action="/" method="post">
            Hello: <input name="msg" type="text" />
            <input value="post" type="submit" />
        </form>
    '''

@route('/', method='POST')
def do_msg():
    msg = request.forms.get('msg')
    lcd.clear()
    lcd.message(msg)
    return index()

lcd.clear()
lcd.message("Hello:\n Raspberry Pi")

run(host=host, port=80)

Download HERE.

No comments: