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 in the post is needed.
from bottle import route, run
from bottle import post, request

from Adafruit_CharLCD import Adafruit_CharLCD
lcd = Adafruit_CharLCD()

host = ''

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

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

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

run(host=host, port=80)

Download HERE.

No comments: