WaveShare 2" IPS LCD Display for Raspberry Pi Pico (320x240) Workout

by tonygo2 in Circuits > Microcontrollers

7915 Views, 8 Favorites, 0 Comments

WaveShare 2" IPS LCD Display for Raspberry Pi Pico (320x240) Workout

WS320x240-9.jpg

In this Instructable I'm going to show you how simple it is to attach this bright and colourful display screen to your Pi Pico and program it to display text and graphics using MicroPython.

Supplies

You will need the following:

The display screen - widely available - I bought mine from thepihut.com, in UK, for £12.50

A Raspberry Pi Pico

A Micro USB cable to connect the Pico to your computer for programming

The Thonney Editor installed on your computer.

Getting Started

WS320x240-20.jpg

This is a new Pi Pico display from Waveshare with many more pixels. It is a 2inch LCD display module, designed for Raspberry Pi Pico, with an embedded ST7789VW driver, 65K RGB colours, 320x240 pixels and an SPI interface. A Pi Pico can be plugged into the rear of the screen for very easy connection without any soldering. It sports 4 simple button switches for user input. It is bright, colourful and easy to program. The makers supply an example program (see below), which includes the display driver, making it very easy to get started. The manufacturer's wiki can be found at:

https://waveshare.com/wiki/Pico-LCD-2

It provides full features, specifications and pinout information. The example program is compressed as a .7z file.

If you run the program it produces the display shown in the picture.

A Minor Problem

WS-Screens.jpg

I own three other WaveShare Pico screens, all with fewer pixels. I usually add code to include a re-sizeable font. This is quite a large chunk of code and data, but very useful. (You can see it in use in some of my other Instructables.) If you look at the table you will notice that the display buffer needed to drive this display uses 153600 bytes. This uses so much of the available RAM that there is not enough room for the Font system. We are limited to text appearing in the single, rather small size. There is also much less room for our own code either. It means that we need to be careful not to be wasteful in our coding and to carry out garbage collection regularly, to save us from running out space.

What We Can Do

Using WaveShare Pi Pico TFT LCD 2" Display 320x240 pixels

My program demonstrates drawing text, lines, rings, rectangles, both outlines and filled, and the use of the four buttons, situated near the corner at the top and bottom edges of the screen. A dynamic bar graph simulating the throwing of 1000 pairs of dice is also produced. You can look at the video or run the program provided below.

Available Memory Changes As the Program Executes

Garbage collection values.jpg

I included to code to report on the changes to the memory available at different stages as the program is executed. Garbage collection takes place at the single dotted line points. We need to avoid the free value falling below that needed or the program will crash.

Screen Shots

WS320x240-3.jpg
WS320x240-7.jpg
WS320x240-4.jpg

Final Thoughts

WS320x240-5.jpg

Which display do I find most useful? I think the 1.8" has been the most useful. It is large enough to read easily, supports re-sizeable fonts and has enough pixels to support interesting graphics, does not waste GPIO pins and is very inexpensive. I would start with that one if you do not yet have a coloured display.

Have fun with your coding!

Mathematics Contest - an After Thought

Maths2.jpg

I wrote this Instructable as a tutorial in programming graphics to help people, who have less experience of colour display screens, to improve their skills. When I uploaded it, I noticed the Mathematics Contest and decided to enter.

===== Without mathematics this project would be impossible ====

Apart from the basic arithmetic used for counting and simple calculations, each element on the screen, such as a line, rectangle or text string, has to be positioned using coordinate geometry. The origin (0, 0) is at the top left corner. The other corners are at (0, 239), (319, 0) and (319, 239). The bar graph is made up from 1000 individually positioned short horizontal lines!

Different number bases are used all the time; denary, binary and hexadecimal. Colours are defined as red, green and blue components in denary (range 0 – 255) and converted from a 3 byte value to 2 bytes with binary shifting and masking - from set theory.

The circles are constructed with a series of concentric single pixel rings which are draw using trigonometry: radians, sine and cosine.

The values of the dice thrown are simulated with random number generation 2000 times.

The counts of each throw of a pair of dice are held in an indexed list using a pointer or suffix.

I used to teach mathematics and still find it incredibly useful. I hope you found this Instructable useful.