Virtual LCD Using Python

[Prashant Mohta] got hold of a Raspberry Pi, a 16×2 LCD display and got down to writing a simple game in Python. Pretty soon, he realized that it was cumbersome to have the Ras-Pi and LCD connected when all he wanted to do was write the code. So he wrote a simple Python module which renders the LCD on his computer display. A simple, quick, useful hack.

[Prashant]’s code relies on the use of Pygame, a set of Python modules designed for writing games. His code uses just two functions – one to define the LCD (characters and number of lines) while the other draws the characters on the screen by looking up an array. The code is just under 20 lines and available from his Github repo. It will be useful to those who are getting started on Python to help them understand some basics. Python is awesome and writing Python code is pretty simple.

This might draw some flak from the naysayers so if you’re commenting below on the merits, or not, of Python, just keep your comments civil and healthy. In the video below, unrelated to this hack, [Raymond Hettinger] talks about “What makes Python so Awesome”!

6 thoughts on “Virtual LCD Using Python

  1. raymond, himself, is awesome! I had the pleasure and honor of attending his class (for 2 weeks) on python. most amazing teacher (not instructor, but actually a teacher) I ever had, college included. if you ever have the chance to attend one of his talks, do it. don’t even think about it, just find a way to do it. he’s amazing and he really cares about educational concepts, so that you leave the class really knowing stuff and not just being passive during the training exercise.

  2. I did something similar to simulate my Adafruit 32×32 LED array for a one-off sprite clock project. Saved me a lot of irritation waiting for the thing to reboot to test out code changes.

    1. Why wasn’t it useful?

      I’m hoping to do a ST756R based pixel-accurate emulator.. with an API that resembles the low-level 4-wire spi interface. Ideally the display would be done using html5, so that it could all be online, but, an offline version using python game would be cool too!

      Something like:

      Have you ever used the ST756R or know how it compares with the SSD1306? At the time I bought the lcd, it seems everyone was using the DOGM (ST756R) ones, but maybe not anymore!

Leave a 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.