RkBlog

Hardware, programming and astronomy tutorials and reviews.

How to use small displays with microcontrollers and computers

A quick introduction into LCD and TFT mini displays available to amateur makes world wide

There is a lot of small LCD displays that can display few lines of text or basic bitmap graphics. The most common and simple are 2x16 LCD displays that can just display some text and basic pixel-graphics. More advanced TFT displays can show more text as well as display graphics. In case of Arduino there is plenty of proven libraries that support such displays. For other platforms there may be problems.

In this article I'll go through a basic LCD displays introduction and a PyMCU example of using of one of such displays.

LCD displays

Various displays available for makers all around the world

Popular LCD displays like the classical 2x16 (2 lines with 16 characters) can be found in some simple devices, like vending machines. They can be also found in PCs on panels where they display PC temperature and cooling settings. There are also cheap displays from old Nokia phones that use SPI to communicate with a microcontroller. Bigger TFT displays will have a lot of pins and are much more complicated to handle - but their capabilities are bigger (color, can display bitmaps, often have touch sensitive surface). For those there are often special adapters for given microcontroller boards (like for Arduino).

Arduino and some other platforms can use LiquidCrystal library to support many LCDs. On platforms like PyMCU this library can't be used and most LCDs as well if you don't implement the whole communication as a Python library (it may be time consuming and annoying so it's quite important to have libraries out of the box).

There are also simpler ways of using complex displays, even those 2x16 LCDs. For example serial communication (UART) can be used to just send text to be displayed. In such configuration the LCD board has its own microcontroller that handles all the complexity and handles simple serial API for you to use.

There is a lot of USB-UART adapters (like for Arduino programming) that allow controlling a serial LCD from a PC without a microcontroller board. Boards with serial/UART pins can also use such serial LCDs. I'll write more about UART and serial communication in next article, but for now lets us take a look on PyMCU LCD support.

PyMCU and 16 pin LCDs

PyMCU can handle one 16-pin (like 2x16) display that connected directly to 16 female pins on the side. Just connect the display and you are ready to go.

API is very simple. We initialise the LCD support by calling lcd method, and then we can use it to display text on the display. First argument is the line number and the second one is the text to display:

from datetime import datetime
from time import sleep

import pymcu

mb = pymcu.mcuModule()
mb.lcd()

while True:
    day = datetime.now().strftime('%d, %b %Y')
    time = datetime.now().strftime('%H:%M:%S')
    mb.lcd(1, day)
    mb.lcd(2, time)
    sleep(1)
LCD display connected to PyMCU

The LCD works but we just used 16 pins to handle one small display. To reduce amount of used pins such LCDs often use I2C or SPI interface. Then you just need 2 pins for power and 2 for communication. With UART when the LCD doesn't return any data you can use just 3 pins. Common I2C LCDs are supported by LiquidCrystal library (Arduino and alike). There is no such library for PyMCU and you can't use such displays with it - unless you will code the communication process.

I2C adapter reduces the amount of needed pins

See also

RkBlog

Raspberry Pi, mini computers, Android and microcontrollers, 21 April 2014,

Comment article