Using 2.2″ LCD SPI in Python with Raspberry Pi

LCD IRP102

Using 2.2″ LCD SPI in Python with Raspberry Pi

16 February, 2016 DIY, Raspberry Pi 0

For many projects with Raspberry PI may be necessary to have a small display to show information without the need to connect to a monitor or television screen. There are a variety of modules ready to connect directly to an I2C or SPI bus at low cost.

In this case we are going to focus on a display with SPI interface and ILI9341 controller.

1. Display connections

This display may be connected to a “IRP-102 HAT board” following these 3 simple steps:

LCD Steps

LCD Steps

If you haven’t get yet your IRP-102 you can connect the display to the Raspberry following this diagram:

esquema_conexion_lcd

lcd connection diagram

DISPLAY RASPBERRY PI
1 – VCC 1 – 3,3V
2 – GND 20 – GND
3 – CS 24 – SPI CE0
4 – RESET 22 – GPIO 25
5 – DC-RS 18 – GPIO 24
6 – SDI / MOSI 19 – SPI MOSI
7 – SCK 23 – SPI CLOCK
8 – LED 12 – GPIO18
9 – SDO / MISO 21 – SPI MISO

Once LCD is connected to Raspberry Pi we should follow these steps in order to get it to work. This tutorial has been written assuming  Raspbian as operating system.

2. System update

We must ensure that we have the latest versions of all components of the operating system. To do this you log into the terminal and enter the following commands:

 

3. Enable SPI bus

Set the configuration for which required modules to operate the SPI bus are loaded at startup. To do this access the configuration interface raspi-config.

 

4. Install required packages

Install several packages for operating the display and to handle images.

 

5. Install Adafruit ILI9341 library

To do this we download (clone) the library and install it with the following commands

 

6. Test the display

So we can launch any of the examples that come with the library. For example, the application “image.py” loads an image and displays it on the display. To do this we need to make some small changes to adapt GPIO we have used to connect the display. To do this edit the file …

and we change the values of variables so that it is thus.

We save changes and proceed to launch the script.

example_lcd

Example LCD image

7. Backlight control

To control the backlight use the GPIO 18. Changing this output turn off or turn on the light at will. We can also apply a PWM signal for applying intermediate intensity levels. To do this, first import module GPIO, declare the line used as output, and then change the level as appropriate:

In the display the default image that comes with the example will be shown. The library includes other examples that show how to draw figures or display text on the display.
Studying the examples and with a little of imagination you can show anything that comes to mind in the display. You can see more examples in our post Wheater station with LCD screen

About the author

IngeniApp:

0 Comments

Would you like to share your thoughts?

Your email address will not be published. Required fields are marked *

Leave a Reply

Uso de cookies

Este sitio web utiliza cookies para que usted tenga la mejor experiencia de usuario. Si continúa navegando está dando su consentimiento para la aceptación de las mencionadas cookies y la aceptación de nuestra política de cookies, pinche el enlace para mayor información.plugin cookies

ACEPTAR