Wednesday 24 March 2021

how to interface i2c lcd with raspberry pi pico


In my previous vlog, I showed you how to start with the Raspberry pi pico. 

And in this tutorial, I am going to show you how to interface I2C 16*2 LCD with Raspberry pi also I am showing how to display the internal temperature of Raspberry pi Pico in LCD. let’s get startedo for this

we need 

Raspberry pi Pico,

I2c LCD ,

some jumper wires, 

and a breadboard

 first let's place pico on Breadboard. then connect the VCC of LCD to Vbus of the pico then connect ground to ground sda to gpio 8 and scl to pin 9 that’s the first i2c port of pico. That’s all about hardware connection. Now we can connect pico to the computer via USB cable. Please watch my previous video to know more about this.

Now open Tonny Ide we have three code files. main.py is our code and the other two are the libraries for controlling LCD. First, we need to save these 3 files on Raspberry pi for that go to files and save. I already saved the files remember you have to give the exact name as I gave. in the main code section first I imported the library. Then I defined the i2c port then the display finally I printed hello world.

Now click run And that's it. You can see hello world text on LCD. This way we can display anything on LCD.

Next, let's display the internal temperature of the rp2040 chip .for that first I defined and imported Library functions then I defined the temperature sensor pin. Then declared the i2c port and pin and also the display. 

In while section first, two lines of code are for converting the analog value to temperature rest is for displaying the temperature in LCD. That's it let's save and run. Now you see the temperature on LCD. 

 circuit diagram

download code and circuit from here

No comments:

Post a Comment