Pico’s Progress 2 – Using a liquid crystal display (LCD) with a Pico

I’ve now worked through every chapter of the book ‘Getting started with Micropython on Raspberry Pi Pico’, mentioned in my previous post: Pico’s Progress – Learning physical computing with an R Pi Pico , except the Chapter 9 ‘Data Logger’.

Chapter 10 ‘Digital communication protocols’ has taken me a very long time due to my difficulty with the liquid crystal display (LCD) I decided to use. Also, I only worked with the I2C protocol so if you want to use SPI you will need to look elsewhere.

Sparkfun SerLCD – RGB Text (Qwiic) LCD-16397

The seller of this display https://www.skpang.co.uk/ was very helpful – however I had difficulties with the wiring and coding. I wanted to use the MicroPython language. However, Sparkfun only seem to have explained the LCD display’s coding commands for the Arduino language – so we, I and my husband, found we did a lot of guesswork at the beginning. We had to buy a Qwiic cable before we could attach the display to the breadboard and this is the one we bought: https://shop.pimoroni.com/products/jst-sh-cable-qwiic-stemma-qt-compatible?variant=31910609846355 Which is available both at: shop.pimoroni.com and: https://thepihut.com/ .

NB The Qwiic cable has a yellow wire for the SCL (the clock) rather than the purple wire shown in the text on p118.

Our main problem though was that we had wired it up as it shows in the book – and it worked better when we changed the wiring to this:

Wiring a SerLCD display using I2C

The main difference is that the power wire is connected to pin 36, 3V3(OUT), rather than pin 40, VBUS. I was assured that it would work with either but we finally started getting results when we used 3V3(OUT).

NB Make sure you put the black wire in a GND pin! For example, pin 38 is used here. For some reason I kept putting the black wire in the wrong position which I’m sure is not good for your Pico or display!

Here is our code to display a Hello World message:

from machine import I2C

import utime

# attach red/power to 3V3(OUT)

# attach black/ground to GND

sda=machine.Pin(0)  # I2C0 SDA GP0/pin 1 (Pinout p129 Pico book)

scl=machine.Pin(1)  # I2C0 SCL GP1/pin 2

i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)

utime.sleep(2)

print(i2c.scan()) # print the I2C address

utime.sleep(2)

print(“change back RGB in one go”)  # still not certain about this section

i2c.writeto(114, ‘\x7C’ ‘+’ ‘\xFF’ ‘\x00’)

utime.sleep(2)

print(“change to one/two lines with 07/06”)   #this changes to one line with 07

i2c.writeto(114, ‘\x7C’)

i2c.writeto(114, ‘\x06’)

print(“change contrast”)  # \x00 gives best contrast

i2c.writeto(114, ‘\x7C’)

i2c.writeto(114, ‘\x18’ ‘\x00’)

utime.sleep(2)

i2c.writeto(114, ‘\x7C’)

i2c.writeto(114, ‘\x2D’)  #clear display

utime.sleep(2)

i2c.writeto(114, ‘Hello World.  I am a SerLCD.’)

print(“all done”)

We think some of this can be left out but, after around a month trying to make the display work, we didn’t want to alter anything.

_________________________________________________________

Thermometer Code

I then wanted to use the Pico as a thermometer and run it headless with the use of a lipstick power bank.

Lipstick Power Bank

So that the Pico could be used as a thermometer, I then altered the first line, of my code, just to say:

import machine

in order that I had the analogue-to-digital converter part of the ‘machine‘ MicroPython library as well as the I2C part.

Next I got rid of i2c.writeto(114, ‘Hello World.  I am a SerLCD.’) and added the temperature reading code from p98 -99 and p120 of the book, and hooray, the temperature was displayed! :

SerLCD displaying Pico temperature

I resaved my thermometer code, (using ‘Save As’), onto the Pico as main.py then, with the addition of the lipstick power bank, took the Pico setup around and about with me, displaying temperatures where ever I needed. Job done!

Happy tinkering!

One thought on “Pico’s Progress 2 – Using a liquid crystal display (LCD) with a Pico

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s