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.
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:
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
# 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)
print(i2c.scan()) # print the I2C address
print(“change back RGB in one go”) # still not certain about this section
i2c.writeto(114, ‘\x7C’ ‘+’ ‘\xFF’ ‘\x00’)
print(“change to one/two lines with 07/06”) #this changes to one line with 07
print(“change contrast”) # \x00 gives best contrast
i2c.writeto(114, ‘\x18’ ‘\x00’)
i2c.writeto(114, ‘\x2D’) #clear display
i2c.writeto(114, ‘Hello World. I am a SerLCD.’)
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.
I then wanted to use the Pico as a thermometer and run it headless with the use of a 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:
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! :
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!