Difference between revisions of "Template:LCD1602 RGB Module Guides for Pico"

From Waveshare Wiki
Jump to: navigation, search
Line 1: Line 1:
==Hardware Configuration==
+
===Hardware Configuration===
 
{|border=1; style="width:700px;text-align:center" align="center"
 
{|border=1; style="width:700px;text-align:center" align="center"
 
|-style="background:green; color:white;" align="center"
 
|-style="background:green; color:white;" align="center"
Line 16: Line 16:
 
</center>
 
</center>
  
==Setup environment==
+
===Setup environment===
 
Please refer to Raspberry Pi's guide: https://www.raspberrypi.org/documentation/pico/getting-started/  
 
Please refer to Raspberry Pi's guide: https://www.raspberrypi.org/documentation/pico/getting-started/  
 
==Raspberry Pi==
 
==Raspberry Pi==
Line 27: Line 27:
 
unzip LCD1602-RGB-Module-demo.zip
 
unzip LCD1602-RGB-Module-demo.zip
 
</pre>
 
</pre>
===C===
+
====C====
 
*Hold the BOOTSEL button of Pico, and connect the USB interface of Pico to Raspberry Pi then release the button.<br>
 
*Hold the BOOTSEL button of Pico, and connect the USB interface of Pico to Raspberry Pi then release the button.<br>
 
*Compile and run the LCD1602-RGB-Module-demo examples
 
*Compile and run the LCD1602-RGB-Module-demo examples
Line 37: Line 37:
 
</pre>
 
</pre>
  
===python===
+
====python====
 
*Refer to Raspberry Pi's guides to setup Micropython firmware for Pico<br>
 
*Refer to Raspberry Pi's guides to setup Micropython firmware for Pico<br>
 
*Open the Thonny IDE, and drag the demo to IDE and run on Pico as below. And save RGB1602.py to Pico's file system<br>
 
*Open the Thonny IDE, and drag the demo to IDE and run on Pico as below. And save RGB1602.py to Pico's file system<br>
 
[[File:Pico-10DOF-IMU005.jpg|600px]]<br>
 
[[File:Pico-10DOF-IMU005.jpg|600px]]<br>
  
==Windows==
+
===Windows===
===C===
+
====C====
 
*Download and unzip the demo to your Windows desktop, refer to Raspberry Pi's guides to set up the Windows software environment settings.
 
*Download and unzip the demo to your Windows desktop, refer to Raspberry Pi's guides to set up the Windows software environment settings.
 
*Find the LCD1602-RGB-Module-demo.uf2 file under the build file under the demo directory, press and hold the BOOTSEL button of Pico, connect the USB of Pico to the PC with a MicroUSB cable, and drag the uf2 file into Pico, and then the Pico will run the demo directly.
 
*Find the LCD1602-RGB-Module-demo.uf2 file under the build file under the demo directory, press and hold the BOOTSEL button of Pico, connect the USB of Pico to the PC with a MicroUSB cable, and drag the uf2 file into Pico, and then the Pico will run the demo directly.
Line 54: Line 54:
  
  
===python===
+
====python====
 
*Download and unzip [https://www.waveshare.com/w/upload/3/3d/Pico-10dof-imu.zip the demo] to your Windows desktop, refer to [https://www.waveshare.com/wiki/Raspberry_Pi_Pico Raspberry Pi's guides] to set up the Windows software environment settings.
 
*Download and unzip [https://www.waveshare.com/w/upload/3/3d/Pico-10dof-imu.zip the demo] to your Windows desktop, refer to [https://www.waveshare.com/wiki/Raspberry_Pi_Pico Raspberry Pi's guides] to set up the Windows software environment settings.
 
*Open the demo program in Thonnty, as shown in the figure below:
 
*Open the demo program in Thonnty, as shown in the figure below:

Revision as of 03:26, 8 May 2023

Hardware Configuration

LCD PIN Pico
VCC 3.3V
GND GND
SDA GP4
SCL GP5

LCD1602 RGB Module006.jpg

Setup environment

Please refer to Raspberry Pi's guide: https://www.raspberrypi.org/documentation/pico/getting-started/

Raspberry Pi

  • Open a terminal of Raspberry Pi
  • Download and unzip the demo codes to directory Pico C/C++ SDK
#Note that the directory of SDK may be different for different users, you need to check the actual directory. Generally, it should be ~/pico/.
wget  -P ~/pico https://www.waveshare.com/w/upload/5/5b/LCD1602-RGB-Module-demo.zip
cd ~/pico
unzip LCD1602-RGB-Module-demo.zip

C

  • Hold the BOOTSEL button of Pico, and connect the USB interface of Pico to Raspberry Pi then release the button.
  • Compile and run the LCD1602-RGB-Module-demo examples
cd ~/pico/LCD1602-RGB-Module-demo/Pico/c/build/
cmake ..
make
sudo mount /dev/sda1 /mnt/pico && sudo cp LCD1602_RGB_Module_demo.uf2 /mnt/pico/ && sudo sync && sudo umount /mnt/pico && sleep 2

python

  • Refer to Raspberry Pi's guides to setup Micropython firmware for Pico
  • Open the Thonny IDE, and drag the demo to IDE and run on Pico as below. And save RGB1602.py to Pico's file system

Pico-10DOF-IMU005.jpg

Windows

C

  • Download and unzip the demo to your Windows desktop, refer to Raspberry Pi's guides to set up the Windows software environment settings.
  • Find the LCD1602-RGB-Module-demo.uf2 file under the build file under the demo directory, press and hold the BOOTSEL button of Pico, connect the USB of Pico to the PC with a MicroUSB cable, and drag the uf2 file into Pico, and then the Pico will run the demo directly.
  • 【Note】 If some users want to modify the demo, after debugging, you can use the following method to generate a .uf2 file:
    • 1. Copy LCD1602-RGB-Module-demo folder to your pico-examples file directory, and then modify the CMakelists.txt configuration file in the pico-example directory as shown in the figure below.
    • 2. Open Visual Studio Code, open your pico-examples folder, select LCD1602_RGB_Module_demo, click Generate, you can find the LCD1602_RGB_Module_demo.uf2 file in the build folder.
    • 3. Arag the uf2 file into Pico, and then the Pico will run the demo directly.

LCD1602 RGB Module010.png


python

  • Download and unzip the demo to your Windows desktop, refer to Raspberry Pi's guides to set up the Windows software environment settings.
  • Open the demo program in Thonnty, as shown in the figure below:

LCD1602 RGB Module004.png

  • Here you also need to save RGB1602.py to PICO, select RGB1602.py, save it as Raspberry pi pico, and name it RGB1602.py.

LCD1602 RGB Module005.png

  • And then run the demo under Choose_Color.py or Discoloration.py.
  • Code analysis

Choose_Color.py

#define color
rgb9 = (0,255,0) #cyan’
lcd.setCursor(0, 0) #Set the cursor position
# print the number of seconds since reset:
lcd.printout("Waveshare") #write characters
lcd.setCursor(0, 1) #Set the cursor position to the second row and the zeroth column
lcd.printout("Hello, World!")#write characters
lcd.setRGB(rgb1[0],rgb1[1],rgb1[2]); #Set the backlight

Discoloration.py

t=0
while True:
 
    r = int((abs(math.sin(3.14*t/180)))*255); #RGB changes over time
    g = int((abs(math.sin(3.14*(t+60)/180)))*255);
    b = int((abs(math.sin(3.14*(t+120)/180)))*255);
    t = t + 3;
    lcd.setRGB(r,g,b);#Reset the value of RGB
# set the cursor to column 0, line 1
    lcd.setCursor(0, 0) #Locate to the first row and the zeroth column
# print the number of seconds since reset:
    lcd.printout("Waveshare")#write characters
    lcd.setCursor(0, 1) #Locate to the second row and the zeroth column
    lcd.printout("Hello, World!")#write characters
    time.sleep(0.3)