RPI Pico I2C LCD Control

by T_622 in Circuits > Microcontrollers

6320 Views, 3 Favorites, 0 Comments

RPI Pico I2C LCD Control

unnamed.jpg

To start, this is a project that adapts code from the python version of Dave Hyland's I2C LCD controller. This is a simple yet effective LCD controller that allows a user to control 16x2 or 20x4 I2C LCDS. The code provides most of the standard Arduino LiquidCrystal functions such as writing to the display, moving cursor, display on / off, custom chars and more. (Check out my GitHub page for all the functions). To clear up some misconceptions about the level translators: I use them merely to ensure that when powering the LCD with 5V, that the Pico is sending proper 5V signals to the LCD and the data from the LCD is shifted down to 3.3V for the Pico. Other than that, you need a little bit of patience and some time!

Code files and GitHub page:

- https://github.com/T-622/RPI-PICO-I2C-LCD

Supplies

- RPI Pico

- PCF8574T 16x2 OR 20x4 I2C Backpack

- Jumper Wires

- Schematic

- Level Shifters (I Recommend These)

- USB Micro to type-B cable

- Thonny programming IDE

- Program files from my GitHub (https://github.com/T-622/RPI-PICO-I2C-LCD)

- Dupont or Breadboard hookup wire

- Breadboard

- About 15 Minutes

Obtain the Code and Software! (Set Up the Pico)

To start, ensure you have read the Raspberry Pi foundation's getting started guide! If this the first time using your Pico, you need to flash the MicroPython .UF2 firmware file. To do this, simply hold the BOOTSEL button down on the Pico while plugging it into your PC. It will show up now as a flash drive. Drag and drop through a file explorer the downloaded .UF2 file onto the new flash drive that is the Pico. After having flashed, the Pico will eject itself from the computer and reboot (unplugging and replugging after the fact never hurts). Now it is time to install Thonny. Download from the below link the Thonny executable. After installing, open the ide and click the bottom left hand corner's box and select "Configure interpreter". When the menu appears, make sure the top drop-down box is set to "MicroPython (Raspberry Pi Pico)". With this, you are now set to program the Pico with MicroPython!

Links:

- .UF2 Firmware file (It will automatically download)

- Thonny programming IDE (Select proper OS download in top-right corner of the page)

Wiring It Up!

Schematic.jpg

To connect everything, I have provided a schematic that shows how to connect all the components with a level shifter. Like said, we use a level shifter here to send a 3.3V signal up to 5V for the LCD and the reverse for data going to the Pico. We use the VBUS pin for a 5V supply to power the LCD and high voltage reference for the level shifter (It bumps the Pico's I2C voltage level to this referenced voltage). On the opposing side, we shift the high voltage signals from the LCD to the low voltage reference (3.3V ref from the Pico). This is why we have 2 voltage rails on the breadboard. If the shifter or display is not connected properly, the console will display "OSERROR: 5" when running the test code. The connections are below:

SCL -- SCL

SDA -- SDA

Programming the Pico and Controlling the LCD

In order to finish this project, we need to upload some python .PY files to the Pico through Thonny. To start, visit my GitHub page repository that contains the 3 python files. Download the files as .ZIP and extract them. Next, open up Thonny and (File --> Open --> [Each individial downloaded python file]) open each downloaded python file. To finish, File --> Save Copy --> Raspberry Pi Pico --> Name each file exactly the same way it was downloaded including the .PY extension. This process is repeated for each file. This means, when on the lcd_api.py file, save it to the board with the same name. TinkerNut on Youtube has a video about this.

Links:

- GitHub Repository (All code is here)

- TinkerNut's Youtube Video!

Enjoy! (Additional Programming Info)

This project should work easily if everything is properly connected. Please refer to the GitHub page for additional info about program functions and custom characters! If you have any questions, please create an issue or message me through GitHub and I would be happy to listen to suggestions or questions.

Happy Making!

Tyler Peppy