WaveShare Pico LCD-1.8 Display Workout

by tonygo2 in Circuits > Microcontrollers

5003 Views, 12 Favorites, 0 Comments

WaveShare Pico LCD-1.8 Display Workout

Waveshare-13B.jpg

This cheap and neat display from WaveShare caught my attention and I thought I would try it out. The specification boasted:

  • 1.8" TFT Display Fits on top of Raspberry Pi Pico (requires male headers to be fitted)
  • 160×128 resolution
  • 65K RGB colours, clear and colourful
  • SPI interface - requiring minimal IO pins (GPIO pins 8,9,10,11,12,13)
  • Driver: ST7735S
  • MicroPython and C/C++ example code.

https://www.waveshare.com/wiki/Pico-LCD-1.8 will find the documentation and the demonstration program including display driver.

The board was very well made and boxed but did not have protective thin plastic cover. There was a Green TAB, stuck directly onto the glass cover with very stiff glue. After careful removal I needed some gin (solvent) and a cotton bud to gently remove the tough glue still sticking to the glass.

Supplies

WaveShare Pico LCD-1.8 Display (Thepihut.com in UK - £9) and others

Raspberry Pi Pico

3 x 10K potentiometers (optional)

Breadboard/stripboards and connectors (optional)

Pico Decker or similar (Optional)

The Software Demo Program

Waveshare-16.jpg

I navigated to the Python code and downloaded the demo program. I clipped the display onto the Pico and ran the code from Thonny. It produced the screen shown above. Quite colourful and effective but not very interesting.

I looked at the code found that it used FrameBuffer.

https://docs.micropython.org/en/latest/library/fra...

- lists the commands available.

  • .fill(c)
  • .pixel(x,y,c)
  • .hline(x,y,w,c)
  • .vline(x,y,h,c)
  • .line(x1,y1,x2,y2,c)
  • .rect(x,y,w,h,c)
  • .fill_rect(x,y,w,h,c)
  • .text(s,x,y,c)

would all be useful.

The driver code is very difficult to follow and needs to be taken on trust.

Only a few colours were provided in the example code and the rest were just 16-bit hex numbers - not a great deal of help. We need to know what each bit did to the colour displayed.

So, What Colour Is 0x20FB?

ColourBits.jpg

Most of us are familiar with 24-bit RGB colours represented by (255,255,255) with the first byte (8-bits) indicating the red brightness, the second the green brightness and the last the blue brightness. This means (0,255,0) is bright green and (255,0,255) is bright magenta. If we only have 2 bytes (16-bits) these are normally split 5-6-5 (R-G-B) because our eyes can are more sensitive to green.

If you look at the table the brightness of each colour is indicated by number of coloured letters. Red and blue have 0 - 31 levels of brightness and green has 0 - 63.

Adding the values of all the green bits and and the values of all the blue bits produces produces bright cyan and 0xFFFF indicates all bits are set and produces white. Two bytes in Hex is far harder to decipher and 0x20FB is orange.

Another Way of Looking at the Numbers Producing a Colour

colourbits2.jpg

This may be easier to understand.

Looking at Pixels

Waveshare-10.jpg

The documentation states that this display is 160 pixels wide and 128 pixels high. Normally the the top left pixel would be at (0,0) and the bottom right would be at (159,127). [ x = 0 to 159 and y = 0 to 127] Not with this display!

After experimenting by writing individual pixels to the screen I found that the top left pixel is at (1,1) and the bottom right pixel at(159,128) - only 159 pixels wide! [x = 1 to 159 and y = 1 to 128] - very odd!

I now had enough information about the colours and the pixels positions to start writing a graphics workout program.

(The driver problem has now been fixed [10th July 2021] - see last page for the updated version.)

The Workout Program

WaveShare Pico LCD -1.8" display Workout

This demonstrates text, text on a curve, lines, circles, rectangles, boxes, random pixels, plotting line and bar graphs controlled by potentiometers and dynamic colour mixing. (You can dial up any of the 65K different available colours.)

I connected the three 10K potentiometers to the ADC GPIO pins GP26, GP27 and GP28.

Try running the video to see what this display can do.

Downloads

Program - Part 1

WScode1-36.jpg

This is the top of the program showing the importation of the libraries and the start of the display setup sequence. The rest of the driver is very difficult to interpret and since it works can be taken at read.

The width and height numbers were unexpected. The back light can be controlled with PWM on GP13.

Part 2

WScode 176-217.jpg

This shows the backlight setup and provides a couple of useful routines.

colour(R,G,B) converts 3 byte values to the 2 byte system used by this board.

ring(x,y,r,cc) draws circle of radius r centred on (x,y) in colour cc

ring(50,50,40,colour(255,0,0)) draws a red circle

Part 3

WScode 217-262.jpg
Waveshare-11.jpg

Title screen, random pixels and lines

Part 4

WScode 264-289.jpg
Waveshare-13.jpg

This adds the circles. Notice how solid circles are produced from multiple rings.

Part 5

WScode 289-324.jpg
Waveshare-12.jpg
Waveshare-15.jpg

Graph plotting and text on a curve.

Part 6 - the Main Loop

WScode 324-364.jpg

Here we read colour values from the potentiometers and convert them to colour values and bar graphs

Part 7 - End of Loop

WScode 364-384.jpg
Waveshare-14.jpg

This draws the bar graphs and fills in the RGB shade boxes

Early Version With Potentiometers

Waveshare-1.jpg

I hope you have found this interesting and useful.

I'm happy to answer questions and appreciate feedback.

Have fun with your coding.

​Driver Fixed by Waveshare – 10th July 2021

After uploading this Instructable I got in touch with Waveshare and pointed out the problem with the driver and supplied a test program writing to all four corners of the screen. All credit to them, they quickly got back to me with a series of updates for me to check out. Today I received a version which has the origin at (0,0), is 160 pixels wide and 128 pixels high. Problem fixed!

I’ve included the test program here, with the working driver.

Great little board, working properly, easy to program and giving excellent results. Give it a try.