The previous article: Playing with RP2040 LCD Drawing Basic Shape Test , introduced the use of MicroPython to perform basic graphics drawing on the RP2040 LCD, including pixel drawing, straight line drawing, rectangle drawing, etc. However, there seems to be no good support for drawing pictures.
I found an example of using MicroPython to display pictures on the LCD of gc9a01 on the Internet. The LCD driver firmware has been compiled and can be used directly or modified and compiled by yourself. It is quite good. The project link address is:
1. Change Python firmware
To use MicroPython and the function interface in this project to display images on the LCD, you need to first replace the RP2040 with the firmware here. The replacement method is the same as described before, that is, press BOOT and RESET to restart. After installing BOOT, a folder will pop up. Drag the following firmware into it. The specific process of firmware burning can be referred to in the previous article:
2 Modify pin definition
Then you can use the test program in the project to perform a picture display test. Before testing, you need to change the pin definition, because the LCD pin definition of the board used in the downloaded project is different from that of RP2040. You can refer to the pin definition writing method in the Weixue LCD basic routine and make corresponding modifications. The modified code is as follows, jpg.py program:
import gc
import time
from machine import Pin, SPI
import gc9a01
DC = 8
CS = 9
SCK = 10
MOSI = 11
RST = 12
BL = 25
gc.enable()
gc.collect()
def main():
'''
Decode and draw jpg on display
'''
spi = SPI(1, baudrate=60000000, sck=Pin(SCK), mosi=Pin(MOSI))
tft = gc9a01.GC9A01(
spi,
240,
240,
reset=Pin(RST, Pin.OUT),
cs=Pin(CS, Pin.OUT),
dc=Pin(DC, Pin.OUT),
backlight=Pin(BL, Pin.OUT),
rotation=0)
# enable display and clear screen
tft.init()
# cycle thru jpg's
while True:
for image in ["bigbuckbunny.jpg", "bluemarble.jpg"]:
tft.jpg(image, 0, 0, gc9a01.SLOW)
time.sleep(5)
main()
It can be seen that with the support of the LCD compilation library, the application code becomes very concise. After specifying the LCD pin and initializing it, you only need to specify the jpg image to be displayed to display the image, and the image does not require additional encoding conversion.
3. Put the image file into the board
Before testing, you need to put the jpg image and program to be displayed into the RP2040 board, corresponding to the py file. The previous article ( Playing with RP2040 and Setting up the Python Development Environment ) introduced a way: open the py file through Thonny on the computer, then connect the serial port to the board, click Save As, and choose to save it to the board.
How to save jpg images to the board? Here is another method of copying files, using the ampy tool.
3.1 Install ampy
You need to have a Python development environment on your Windows computer, and then use the pip command to install the adafruit-ampy tool
pip install adafruit-ampy
After the installation is complete, you can enter the ampy command to confirm whether the installation is successful:
The main command used here is put, which is used to send files from the computer to the RP2040 board.
3.2 Use apmy command to transfer files
In the directory of the file to be uploaded, hold down the shift key and right-click the directory, and select "Open PowerShell window this time".
For example, if the jpg image to be uploaded is in the examples/RP2/jpg directory, hold down the shift key and right-click on the jpg folder.
Use the ls command to view the files in the jpg directory, and then use the following command to push the files
ampy --port COM31 put alien.jpg
-
COM31 is the serial port number of your board
-
alien.jpg is the file name to be sent. This is a picture file. In addition, folder sending is also supported.
Please note that: when executing this command, the serial port of the board must be connected to the computer, but the serial port cannot be connected to other software. If it is connected to Thonny, disconnect Thonny from the board.
The result of a successful file sending is as follows:
After sending successfully, you can signal Thonny to connect to the board again, and confirm whether the image is already in the board by opening the file and opening the board file.
4 Run the test
After putting the program and the picture into the board, you can test it. Since my board put a main.py program into it when testing the basic elements of LCD painting in the previous article, the program will run by default when it is turned on. Without deleting the program, use Thonny to open the jpg.py picture test program in the board and click Run in Thonny to run it. The test effect is as follows:
5 Conclusion
This article introduces how to use MicroPython to test the display of full-screen images on the LCD on the RP2040. By replacing the compiled Python firmware of the LCD driver, placing the jpg file to be displayed into the board through ampy, and modifying the pin definition of the test program, the image display on the LCD can be realized.