Raspberry Pi Pico TFT LCD 触摸屏使用教程

本教程将向您展示如何使用micropython脚本设置Pico和TFT触摸显示屏。您将学习如何使用触摸屏控制Pico以及如何在屏幕上显示信息。

您是否正在寻找Raspberry Pi Pico TFT LCD触摸屏教程?本教程将向您展示如何使用micropython脚本设置Pico和TFT触摸显示屏。您将学习如何使用触摸屏控制Pico以及如何在屏幕上显示信息。

重要提示:
本文使用的TFT显示屏驱动芯片:ILI9341,驱动程序:Python,主控:RPi-Pico,连接方式为:SPI

学完本教程,您将拥有一个在自己项目上能工作的TFT触摸显示屏。这是一个非常适合与Raspberry Pi Pico一起使用的小显示屏,因为它非常易于设置和使用。


配件

  • 2.8-inch TFT 触摸显示屏
  • Raspberry Pi Pico
  • 面包板
  • 跳线若干
  • USB 连接线

ILI9341 驱动芯片

ILI9341是一个流行的显示驱动芯片,通常用于中小型TFT LCD显示器。它由ILI Technology Corp.公司制造,旨在驱动分辨率高达240×320像素的显示器,如2.8英寸TFT触摸显示器。

ILI9341是真正的262144色单芯片片上系统(SOC)驱动器,专为具有240x320点RGB图像的TFT(有源矩阵薄膜晶体管)液晶显示器而设计。

芯片通过SPI(串行外围接口)与微控制器通信。

2.8-inch TFT 触摸显示屏

2.8英寸TFT触摸屏是一个可以显示图形和文本的小屏幕。它的分辨率是320×240像素,这意味着它可以水平显示320像素,垂直显示240像素。

Raspberry Pi Pico TFT LCD 触摸屏使用教程

这个显示屏还具有触敏界面,允许您通过用手指或手写笔触摸项目来与项目进行交互,类似于您使用智能手机或平板电脑的方式。它通常用于便携式游戏机、数码相框和小型嵌入式手持设备等电子项目。

TFT代表“薄膜晶体管”,这种显示屏通常用于需要对用户触摸有良好响应的小型图形触摸屏的项目。

2.8 inch TFT 触摸显示屏引脚

Raspberry Pi Pico TFT LCD 触摸屏使用教程

Pin Name Description
T_IRQ Touch screen interrupt signal, low level when touch is detected
T_DO Touch SPI bus output
T_DIN Touch SPI bus input
T_CS Touch screen chip select signal, low level enable
T_CLK Touch SPI bus clock signal
SDO (MISO) SPI bus read data signal, if not needed, can be left unconnected
LED Backlight control, high-level lighting, if not controlled, connect to 3.3V to keep it always bright
SCK SPI bus clock signal
SDI (MOSI) SPI bus writes data signal
DC/RS LCD register/data selection signal, high level: register, low level: data
RESET LCD reset signal, low-level reset
CS LCD chip select signal, low level enable
GND Ground
VCC 5V/3.3V power input


InTFT LCD触摸屏显示屏与Raspberry Pi Pico的接线图

Raspberry Pi Pico TFT LCD 触摸屏使用教程

根据下表连接引脚:

ili9341 TFT Display Pin Raspberry Pi Pico
VCC 3.3V
GND GND
CS GP17
RESET GP7
DC/RS GP6
SDI(MOSI) GP15
SCK GP14
LED 3.3V

完成所有连接后,打开Raspberry Pi Pico的电源。使用跳线将显示屏连接到Raspberry Pi Pico。

Raspberry Pi Pico TFT LCD 触摸屏使用教程


Micropython 代码和库

将TFT LCD触摸屏与Raspberry Pi Pico连接的代码。主代码需要一个用于TFT LCD显示器的库。用ThonnyIDE对Raspberry Pi Pico进行编程请参考本站相关文章。

ili9341.py

复制以下库代码并命名为ili9341.py,将其保存到Raspberry Pi Pico

ILI9341.py
"""ILI9341 LCD/Touch module."""
from time import sleep
from math import cos, sin, pi, radians
from sys import implementation
from framebuf import FrameBuffer, RGB565  # type: ignore
import ustruct  # type: ignore
def color565(r, g, b):
    """Return RGB565 color value.
    Args:
        r (int): Red value.
        g (int): Green value.
        b (int): Blue value.
    """
    return (r & 0xf8) << 8 | (g & 0xfc) << 3 | b >> 3
class Display(object):
    """Serial interface for 16-bit color (5-6-5 RGB) IL9341 display.
    Note:  All coordinates are zero based.
    """
    # Command constants from ILI9341 datasheet
    NOP = const(0x00)  # No-op
    SWRESET = const(0x01)  # Software reset
    RDDID = const(0x04)  # Read display ID info
    RDDST = const(0x09)  # Read display status
    SLPIN = const(0x10)  # Enter sleep mode
    SLPOUT = const(0x11)  # Exit sleep mode
    PTLON = const(0x12)  # Partial mode on
    NORON = const(0x13)  # Normal display mode on
    RDMODE = const(0x0A)  # Read display power mode
    RDMADCTL = const(0x0B)  # Read display MADCTL
    RDPIXFMT = const(0x0C)  # Read display pixel format
    RDIMGFMT = const(0x0D)  # Read display image format
    RDSELFDIAG = const(0x0F)  # Read display self-diagnostic
    INVOFF = const(0x20)  # Display inversion off
    INVON = const(0x21)  # Display inversion on
    GAMMASET = const(0x26)  # Gamma set
    DISPLAY_OFF = const(0x28)  # Display off
    DISPLAY_ON = const(0x29)  # Display on
    SET_COLUMN = const(0x2A)  # Column address set
    SET_PAGE = const(0x2B)  # Page address set
    WRITE_RAM = const(0x2C)  # Memory write
    READ_RAM = const(0x2E)  # Memory read
    PTLAR = const(0x30)  # Partial area
    VSCRDEF = const(0x33)  # Vertical scrolling definition
    MADCTL = const(0x36)  # Memory access control
    VSCRSADD = const(0x37)  # Vertical scrolling start address
    PIXFMT = const(0x3A)  # COLMOD: Pixel format set
    WRITE_DISPLAY_BRIGHTNESS = const(0x51)  # Brightness hardware dependent!
    READ_DISPLAY_BRIGHTNESS = const(0x52)
    WRITE_CTRL_DISPLAY = const(0x53)
    READ_CTRL_DISPLAY = const(0x54)
    WRITE_CABC = const(0x55)  # Write Content Adaptive Brightness Control
    READ_CABC = const(0x56)  # Read Content Adaptive Brightness Control
    WRITE_CABC_MINIMUM = const(0x5E)  # Write CABC Minimum Brightness
    READ_CABC_MINIMUM = const(0x5F)  # Read CABC Minimum Brightness
    FRMCTR1 = const(0xB1)  # Frame rate control (In normal mode/full colors)
    FRMCTR2 = const(0xB2)  # Frame rate control (In idle mode/8 colors)
    FRMCTR3 = const(0xB3)  # Frame rate control (In partial mode/full colors)
    INVCTR = const(0xB4)  # Display inversion control
    DFUNCTR = const(0xB6)  # Display function control
    PWCTR1 = const(0xC0)  # Power control 1
    PWCTR2 = const(0xC1)  # Power control 2
    PWCTRA = const(0xCB)  # Power control A
    PWCTRB = const(0xCF)  # Power control B
    VMCTR1 = const(0xC5)  # VCOM control 1
    VMCTR2 = const(0xC7)  # VCOM control 2
    RDID1 = const(0xDA)  # Read ID 1
    RDID2 = const(0xDB)  # Read ID 2
    RDID3 = const(0xDC)  # Read ID 3
    RDID4 = const(0xDD)  # Read ID 4
    GMCTRP1 = const(0xE0)  # Positive gamma correction
    GMCTRN1 = const(0xE1)  # Negative gamma correction
    DTCA = const(0xE8)  # Driver timing control A
    DTCB = const(0xEA)  # Driver timing control B
    POSC = const(0xED)  # Power on sequence control
    ENABLE3G = const(0xF2)  # Enable 3 gamma control
    PUMPRC = const(0xF7)  # Pump ratio control
    ROTATE = {
        0: 0x88,
        90: 0xE8,
        180: 0x48,
        270: 0x28
    }
    def __init__(self, spi, cs, dc, rst,
                 width=240, height=320, rotation=0):
        """Initialize OLED.
        Args:
            spi (Class Spi):  SPI interface for OLED
            cs (Class Pin):  Chip select pin
            dc (Class Pin):  Data/Command pin
            rst (Class Pin):  Reset pin
            width (Optional int): Screen width (default 240)
            height (Optional int): Screen height (default 320)
            rotation (Optional int): Rotation must be 0 default, 90. 180 or 270
        """
        self.spi = spi
        self.cs = cs
        self.dc = dc
        self.rst = rst
        self.width = width
        self.height = height
        if rotation not in self.ROTATE.keys():
            raise RuntimeError('Rotation must be 0, 90, 180 or 270.')
        else:
            self.rotation = self.ROTATE[rotation]
        # Initialize GPIO pins and set implementation specific methods
        if implementation.name == 'circuitpython':
            self.cs.switch_to_output(value=True)
            self.dc.switch_to_output(value=False)
            self.rst.switch_to_output(value=True)
            self.reset = self.reset_cpy
            self.write_cmd = self.write_cmd_cpy
            self.write_data = self.write_data_cpy
        else:
            self.cs.init(self.cs.OUT, value=1)
            self.dc.init(self.dc.OUT, value=0)
            self.rst.init(self.rst.OUT, value=1)
            self.reset = self.reset_mpy
            self.write_cmd = self.write_cmd_mpy
            self.write_data = self.write_data_mpy
        self.reset()
        # Send initialization commands
        self.write_cmd(self.SWRESET)  # Software reset
        sleep(.1)
        self.write_cmd(self.PWCTRB, 0x00, 0xC1, 0x30)  # Pwr ctrl B
        self.write_cmd(self.POSC, 0x64, 0x03, 0x12, 0x81)  # Pwr on seq. ctrl
        self.write_cmd(self.DTCA, 0x85, 0x00, 0x78)  # Driver timing ctrl A
        self.write_cmd(self.PWCTRA, 0x39, 0x2C, 0x00, 0x34, 0x02)  # Pwr ctrl A
        self.write_cmd(self.PUMPRC, 0x20)  # Pump ratio control
        self.write_cmd(self.DTCB, 0x00, 0x00)  # Driver timing ctrl B
        self.write_cmd(self.PWCTR1, 0x23)  # Pwr ctrl 1
        self.write_cmd(self.PWCTR2, 0x10)  # Pwr ctrl 2
        self.write_cmd(self.VMCTR1, 0x3E, 0x28)  # VCOM ctrl 1
        self.write_cmd(self.VMCTR2, 0x86)  # VCOM ctrl 2
        self.write_cmd(self.MADCTL, self.rotation)  # Memory access ctrl
        self.write_cmd(self.VSCRSADD, 0x00)  # Vertical scrolling start address
        self.write_cmd(self.PIXFMT, 0x55)  # COLMOD: Pixel format
        self.write_cmd(self.FRMCTR1, 0x00, 0x18)  # Frame rate ctrl
        self.write_cmd(self.DFUNCTR, 0x08, 0x82, 0x27)
        self.write_cmd(self.ENABLE3G, 0x00)  # Enable 3 gamma ctrl
        self.write_cmd(self.GAMMASET, 0x01)  # Gamma curve selected
        self.write_cmd(self.GMCTRP1, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E,
                       0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00)
        self.write_cmd(self.GMCTRN1, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31,
                       0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F)
        self.write_cmd(self.SLPOUT)  # Exit sleep
        sleep(.1)
        self.write_cmd(self.DISPLAY_ON)  # Display on
        sleep(.1)
        self.clear()
    def block(self, x0, y0, x1, y1, data):
        """Write a block of data to display.
        Args:
            x0 (int):  Starting X position.
            y0 (int):  Starting Y position.
            x1 (int):  Ending X position.
            y1 (int):  Ending Y position.
            data (bytes): Data buffer to write.
        """
        self.write_cmd(self.SET_COLUMN, *ustruct.pack(">HH", x0, x1))
        self.write_cmd(self.SET_PAGE, *ustruct.pack(">HH", y0, y1))
        self.write_cmd(self.WRITE_RAM)
        self.write_data(data)
    def cleanup(self):
        """Clean up resources."""
        self.clear()
        self.display_off()
        self.spi.deinit()
        print('display off')
    def clear(self, color=0):
        """Clear display.
        Args:
            color (Optional int): RGB565 color value (Default: 0 = Black).
        """
        w = self.width
        h = self.height
        # Clear display in 1024 byte blocks
        if color:
            line = color.to_bytes(2, 'big') * (w * 8)
        else:
            line = bytearray(w * 16)
        for y in range(0, h, 8):
            self.block(0, y, w - 1, y + 7, line)
    def display_off(self):
        """Turn display off."""
        self.write_cmd(self.DISPLAY_OFF)
    def display_on(self):
        """Turn display on."""
        self.write_cmd(self.DISPLAY_ON)
    def draw_circle(self, x0, y0, r, color):
        """Draw a circle.
        Args:
            x0 (int): X coordinate of center point.
            y0 (int): Y coordinate of center point.
            r (int): Radius.
            color (int): RGB565 color value.
        """
        f = 1 - r
        dx = 1
        dy = -r - r
        x = 0
        y = r
        self.draw_pixel(x0, y0 + r, color)
        self.draw_pixel(x0, y0 - r, color)
        self.draw_pixel(x0 + r, y0, color)
        self.draw_pixel(x0 - r, y0, color)
        while x < y:
            if f >= 0:
                y -= 1
                dy += 2
                f += dy
            x += 1
            dx += 2
            f += dx
            self.draw_pixel(x0 + x, y0 + y, color)
            self.draw_pixel(x0 - x, y0 + y, color)
            self.draw_pixel(x0 + x, y0 - y, color)
            self.draw_pixel(x0 - x, y0 - y, color)
            self.draw_pixel(x0 + y, y0 + x, color)
            self.draw_pixel(x0 - y, y0 + x, color)
            self.draw_pixel(x0 + y, y0 - x, color)
            self.draw_pixel(x0 - y, y0 - x, color)
    def draw_ellipse(self, x0, y0, a, b, color):
        """Draw an ellipse.
        Args:
            x0, y0 (int): Coordinates of center point.
            a (int): Semi axis horizontal.
            b (int): Semi axis vertical.
            color (int): RGB565 color value.
        Note:
            The center point is the center of the x0,y0 pixel.
            Since pixels are not divisible, the axes are integer rounded
            up to complete on a full pixel.  Therefore the major and
            minor axes are increased by 1.
        """
        a2 = a * a
        b2 = b * b
        twoa2 = a2 + a2
        twob2 = b2 + b2
        x = 0
        y = b
        px = 0
        py = twoa2 * y
        # Plot initial points
        self.draw_pixel(x0 + x, y0 + y, color)
        self.draw_pixel(x0 - x, y0 + y, color)
        self.draw_pixel(x0 + x, y0 - y, color)
        self.draw_pixel(x0 - x, y0 - y, color)
        # Region 1
        p = round(b2 - (a2 * b) + (0.25 * a2))
        while px < py:
            x += 1
            px += twob2
            if p < 0:
                p += b2 + px
            else:
                y -= 1
                py -= twoa2
                p += b2 + px - py
            self.draw_pixel(x0 + x, y0 + y, color)
            self.draw_pixel(x0 - x, y0 + y, color)
            self.draw_pixel(x0 + x, y0 - y, color)
            self.draw_pixel(x0 - x, y0 - y, color)
        # Region 2
        p = round(b2 * (x + 0.5) * (x + 0.5) +
                  a2 * (y - 1) * (y - 1) - a2 * b2)
        while y > 0:
            y -= 1
            py -= twoa2
            if p > 0:
                p += a2 - py
            else:
                x += 1
                px += twob2
                p += a2 - py + px
            self.draw_pixel(x0 + x, y0 + y, color)
            self.draw_pixel(x0 - x, y0 + y, color)
            self.draw_pixel(x0 + x, y0 - y, color)
            self.draw_pixel(x0 - x, y0 - y, color)
    def draw_hline(self, x, y, w, color):
        """Draw a horizontal line.
        Args:
            x (int): Starting X position.
            y (int): Starting Y position.
            w (int): Width of line.
            color (int): RGB565 color value.
        """
        if self.is_off_grid(x, y, x + w - 1, y):
            return
        line = color.to_bytes(2, 'big') * w
        self.block(x, y, x + w - 1, y, line)
    def draw_image(self, path, x=0, y=0, w=320, h=240):
        """Draw image from flash.
        Args:
            path (string): Image file path.
            x (int): X coordinate of image left.  Default is 0.
            y (int): Y coordinate of image top.  Default is 0.
            w (int): Width of image.  Default is 320.
            h (int): Height of image.  Default is 240.
        """
        x2 = x + w - 1
        y2 = y + h - 1
        if self.is_off_grid(x, y, x2, y2):
            return
        with open(path, "rb") as f:
            chunk_height = 1024 // w
            chunk_count, remainder = divmod(h, chunk_height)
            chunk_size = chunk_height * w * 2
            chunk_y = y
            if chunk_count:
                for c in range(0, chunk_count):
                    buf = f.read(chunk_size)
                    self.block(x, chunk_y,
                               x2, chunk_y + chunk_height - 1,
                               buf)
                    chunk_y += chunk_height
            if remainder:
                buf = f.read(remainder * w * 2)
                self.block(x, chunk_y,
                           x2, chunk_y + remainder - 1,
                           buf)
    def draw_letter(self, x, y, letter, font, color, background=0,
                    landscape=False):
        """Draw a letter.
        Args:
            x (int): Starting X position.
            y (int): Starting Y position.
            letter (string): Letter to draw.
            font (XglcdFont object): Font.
            color (int): RGB565 color value.
            background (int): RGB565 background color (default: black).
            landscape (bool): Orientation (default: False = portrait)
        """
        buf, w, h = font.get_letter(letter, color, background, landscape)
        # Check for errors (Font could be missing specified letter)
        if w == 0:
            return w, h
        if landscape:
            y -= w
            if self.is_off_grid(x, y, x + h - 1, y + w - 1):
                return 0, 0
            self.block(x, y,
                       x + h - 1, y + w - 1,
                       buf)
        else:
            if self.is_off_grid(x, y, x + w - 1, y + h - 1):
                return 0, 0
            self.block(x, y,
                       x + w - 1, y + h - 1,
                       buf)
        return w, h
    def draw_line(self, x1, y1, x2, y2, color):
        """Draw a line using Bresenham's algorithm.
        Args:
            x1, y1 (int): Starting coordinates of the line
            x2, y2 (int): Ending coordinates of the line
            color (int): RGB565 color value.
        """
        # Check for horizontal line
        if y1 == y2:
            if x1 > x2:
                x1, x2 = x2, x1
            self.draw_hline(x1, y1, x2 - x1 + 1, color)
            return
        # Check for vertical line
        if x1 == x2:
            if y1 > y2:
                y1, y2 = y2, y1
            self.draw_vline(x1, y1, y2 - y1 + 1, color)
            return
        # Confirm coordinates in boundary
        if self.is_off_grid(min(x1, x2), min(y1, y2),
                            max(x1, x2), max(y1, y2)):
            return
        # Changes in x, y
        dx = x2 - x1
        dy = y2 - y1
        # Determine how steep the line is
        is_steep = abs(dy) > abs(dx)
        # Rotate line
        if is_steep:
            x1, y1 = y1, x1
            x2, y2 = y2, x2
        # Swap start and end points if necessary
        if x1 > x2:
            x1, x2 = x2, x1
            y1, y2 = y2, y1
        # Recalculate differentials
        dx = x2 - x1
        dy = y2 - y1
        # Calculate error
        error = dx >> 1
        ystep = 1 if y1 < y2 else -1
        y = y1
        for x in range(x1, x2 + 1):
            # Had to reverse HW ????
            if not is_steep:
                self.draw_pixel(x, y, color)
            else:
                self.draw_pixel(y, x, color)
            error -= abs(dy)
            if error < 0:
                y += ystep
                error += dx
    def draw_lines(self, coords, color):
        """Draw multiple lines.
        Args:
            coords ([[int, int],...]): Line coordinate X, Y pairs
            color (int): RGB565 color value.
        """
        # Starting point
        x1, y1 = coords[0]
        # Iterate through coordinates
        for i in range(1, len(coords)):
            x2, y2 = coords[i]
            self.draw_line(x1, y1, x2, y2, color)
            x1, y1 = x2, y2
    def draw_pixel(self, x, y, color):
        """Draw a single pixel.
        Args:
            x (int): X position.
            y (int): Y position.
            color (int): RGB565 color value.
        """
        if self.is_off_grid(x, y, x, y):
            return
        self.block(x, y, x, y, color.to_bytes(2, 'big'))
    def draw_polygon(self, sides, x0, y0, r, color, rotate=0):
        """Draw an n-sided regular polygon.
        Args:
            sides (int): Number of polygon sides.
            x0, y0 (int): Coordinates of center point.
            r (int): Radius.
            color (int): RGB565 color value.
            rotate (Optional float): Rotation in degrees relative to origin.
        Note:
            The center point is the center of the x0,y0 pixel.
            Since pixels are not divisible, the radius is integer rounded
            up to complete on a full pixel.  Therefore diameter = 2 x r + 1.
        """
        coords = []
        theta = radians(rotate)
        n = sides + 1
        for s in range(n):
            t = 2.0 * pi * s / sides + theta
            coords.append([int(r * cos(t) + x0), int(r * sin(t) + y0)])
        # Cast to python float first to fix rounding errors
        self.draw_lines(coords, color=color)
    def draw_rectangle(self, x, y, w, h, color):
        """Draw a rectangle.
        Args:
            x (int): Starting X position.
            y (int): Starting Y position.
            w (int): Width of rectangle.
            h (int): Height of rectangle.
            color (int): RGB565 color value.
        """
        x2 = x + w - 1
        y2 = y + h - 1
        self.draw_hline(x, y, w, color)
        self.draw_hline(x, y2, w, color)
        self.draw_vline(x, y, h, color)
        self.draw_vline(x2, y, h, color)
    def draw_sprite(self, buf, x, y, w, h):
        """Draw a sprite (optimized for horizontal drawing).
        Args:
            buf (bytearray): Buffer to draw.
            x (int): Starting X position.
            y (int): Starting Y position.
            w (int): Width of drawing.
            h (int): Height of drawing.
        """
        x2 = x + w - 1
        y2 = y + h - 1
        if self.is_off_grid(x, y, x2, y2):
            return
        self.block(x, y, x2, y2, buf)
    def draw_text(self, x, y, text, font, color,  background=0,
                  landscape=False, spacing=1):
        """Draw text.
        Args:
            x (int): Starting X position.
            y (int): Starting Y position.
            text (string): Text to draw.
            font (XglcdFont object): Font.
            color (int): RGB565 color value.
            background (int): RGB565 background color (default: black).
            landscape (bool): Orientation (default: False = portrait)
            spacing (int): Pixels between letters (default: 1)
        """
        for letter in text:
            # Get letter array and letter dimensions
            w, h = self.draw_letter(x, y, letter, font, color, background,
                                    landscape)
            # Stop on error
            if w == 0 or h == 0:
                print('Invalid width {0} or height {1}'.format(w, h))
                return
            if landscape:
                # Fill in spacing
                if spacing:
                    self.fill_hrect(x, y - w - spacing, h, spacing, background)
                # Position y for next letter
                y -= (w + spacing)
            else:
                # Fill in spacing
                if spacing:
                    self.fill_hrect(x + w, y, spacing, h, background)
                # Position x for next letter
                x += (w + spacing)
                # # Fill in spacing
                # if spacing:
                #     self.fill_vrect(x + w, y, spacing, h, background)
                # # Position x for next letter
                # x += w + spacing
    def draw_text8x8(self, x, y, text, color,  background=0,
                     rotate=0):
        """Draw text using built-in MicroPython 8x8 bit font.
        Args:
            x (int): Starting X position.
            y (int): Starting Y position.
            text (string): Text to draw.
            color (int): RGB565 color value.
            background (int): RGB565 background color (default: black).
            rotate(int): 0, 90, 180, 270
        """
        w = len(text) * 8
        h = 8
        # Confirm coordinates in boundary
        if self.is_off_grid(x, y, x + 7, y + 7):
            return
        # Rearrange color
        r = (color & 0xF800) >> 8
        g = (color & 0x07E0) >> 3
        b = (color & 0x1F) << 3
        buf = bytearray(w * 16)
        fbuf = FrameBuffer(buf, w, h, RGB565)
        if background != 0:
            bg_r = (background & 0xF800) >> 8
            bg_g = (background & 0x07E0) >> 3
            bg_b = (background & 0x1F) << 3
            fbuf.fill(color565(bg_b, bg_r, bg_g))
        fbuf.text(text, 0, 0, color565(b, r, g))
        if rotate == 0:
            self.block(x, y, x + w - 1, y + (h - 1), buf)
        elif rotate == 90:
            buf2 = bytearray(w * 16)
            fbuf2 = FrameBuffer(buf2, h, w, RGB565)
            for y1 in range(h):
                for x1 in range(w):
                    fbuf2.pixel(y1, x1,
                                fbuf.pixel(x1, (h - 1) - y1))
            self.block(x, y, x + (h - 1), y + w - 1, buf2)
        elif rotate == 180:
            buf2 = bytearray(w * 16)
            fbuf2 = FrameBuffer(buf2, w, h, RGB565)
            for y1 in range(h):
                for x1 in range(w):
                    fbuf2.pixel(x1, y1,
                                fbuf.pixel((w - 1) - x1, (h - 1) - y1))
            self.block(x, y, x + w - 1, y + (h - 1), buf2)
        elif rotate == 270:
            buf2 = bytearray(w * 16)
            fbuf2 = FrameBuffer(buf2, h, w, RGB565)
            for y1 in range(h):
                for x1 in range(w):
                    fbuf2.pixel(y1, x1,
                                fbuf.pixel((w - 1) - x1, y1))
            self.block(x, y, x + (h - 1), y + w - 1, buf2)
    def draw_vline(self, x, y, h, color):
        """Draw a vertical line.
        Args:
            x (int): Starting X position.
            y (int): Starting Y position.
            h (int): Height of line.
            color (int): RGB565 color value.
        """
        # Confirm coordinates in boundary
        if self.is_off_grid(x, y, x, y + h - 1):
            return
        line = color.to_bytes(2, 'big') * h
        self.block(x, y, x, y + h - 1, line)
    def fill_circle(self, x0, y0, r, color):
        """Draw a filled circle.
        Args:
            x0 (int): X coordinate of center point.
            y0 (int): Y coordinate of center point.
            r (int): Radius.
            color (int): RGB565 color value.
        """
        f = 1 - r
        dx = 1
        dy = -r - r
        x = 0
        y = r
        self.draw_vline(x0, y0 - r, 2 * r + 1, color)
        while x < y:
            if f >= 0:
                y -= 1
                dy += 2
                f += dy
            x += 1
            dx += 2
            f += dx
            self.draw_vline(x0 + x, y0 - y, 2 * y + 1, color)
            self.draw_vline(x0 - x, y0 - y, 2 * y + 1, color)
            self.draw_vline(x0 - y, y0 - x, 2 * x + 1, color)
            self.draw_vline(x0 + y, y0 - x, 2 * x + 1, color)
    def fill_ellipse(self, x0, y0, a, b, color):
        """Draw a filled ellipse.
        Args:
            x0, y0 (int): Coordinates of center point.
            a (int): Semi axis horizontal.
            b (int): Semi axis vertical.
            color (int): RGB565 color value.
        Note:
            The center point is the center of the x0,y0 pixel.
            Since pixels are not divisible, the axes are integer rounded
            up to complete on a full pixel.  Therefore the major and
            minor axes are increased by 1.
        """
        a2 = a * a
        b2 = b * b
        twoa2 = a2 + a2
        twob2 = b2 + b2
        x = 0
        y = b
        px = 0
        py = twoa2 * y
        # Plot initial points
        self.draw_line(x0, y0 - y, x0, y0 + y, color)
        # Region 1
        p = round(b2 - (a2 * b) + (0.25 * a2))
        while px < py:
            x += 1
            px += twob2
            if p < 0:
                p += b2 + px
            else:
                y -= 1
                py -= twoa2
                p += b2 + px - py
            self.draw_line(x0 + x, y0 - y, x0 + x, y0 + y, color)
            self.draw_line(x0 - x, y0 - y, x0 - x, y0 + y, color)
        # Region 2
        p = round(b2 * (x + 0.5) * (x + 0.5) +
                  a2 * (y - 1) * (y - 1) - a2 * b2)
        while y > 0:
            y -= 1
            py -= twoa2
            if p > 0:
                p += a2 - py
            else:
                x += 1
                px += twob2
                p += a2 - py + px
            self.draw_line(x0 + x, y0 - y, x0 + x, y0 + y, color)
            self.draw_line(x0 - x, y0 - y, x0 - x, y0 + y, color)
    def fill_hrect(self, x, y, w, h, color):
        """Draw a filled rectangle (optimized for horizontal drawing).
        Args:
            x (int): Starting X position.
            y (int): Starting Y position.
            w (int): Width of rectangle.
            h (int): Height of rectangle.
            color (int): RGB565 color value.
        """
        if self.is_off_grid(x, y, x + w - 1, y + h - 1):
            return
        chunk_height = 1024 // w
        chunk_count, remainder = divmod(h, chunk_height)
        chunk_size = chunk_height * w
        chunk_y = y
        if chunk_count:
            buf = color.to_bytes(2, 'big') * chunk_size
            for c in range(0, chunk_count):
                self.block(x, chunk_y,
                           x + w - 1, chunk_y + chunk_height - 1,
                           buf)
                chunk_y += chunk_height
        if remainder:
            buf = color.to_bytes(2, 'big') * remainder * w
            self.block(x, chunk_y,
                       x + w - 1, chunk_y + remainder - 1,
                       buf)
    def fill_rectangle(self, x, y, w, h, color):
        """Draw a filled rectangle.
        Args:
            x (int): Starting X position.
            y (int): Starting Y position.
            w (int): Width of rectangle.
            h (int): Height of rectangle.
            color (int): RGB565 color value.
        """
        if self.is_off_grid(x, y, x + w - 1, y + h - 1):
            return
        if w > h:
            self.fill_hrect(x, y, w, h, color)
        else:
            self.fill_vrect(x, y, w, h, color)
    def fill_polygon(self, sides, x0, y0, r, color, rotate=0):
        """Draw a filled n-sided regular polygon.
        Args:
            sides (int): Number of polygon sides.
            x0, y0 (int): Coordinates of center point.
            r (int): Radius.
            color (int): RGB565 color value.
            rotate (Optional float): Rotation in degrees relative to origin.
        Note:
            The center point is the center of the x0,y0 pixel.
            Since pixels are not divisible, the radius is integer rounded
            up to complete on a full pixel.  Therefore diameter = 2 x r + 1.
        """
        # Determine side coordinates
        coords = []
        theta = radians(rotate)
        n = sides + 1
        for s in range(n):
            t = 2.0 * pi * s / sides + theta
            coords.append([int(r * cos(t) + x0), int(r * sin(t) + y0)])
        # Starting point
        x1, y1 = coords[0]
        # Minimum Maximum X dict
        xdict = {y1: [x1, x1]}
        # Iterate through coordinates
        for row in coords[1:]:
            x2, y2 = row
            xprev, yprev = x2, y2
            # Calculate perimeter
            # Check for horizontal side
            if y1 == y2:
                if x1 > x2:
                    x1, x2 = x2, x1
                if y1 in xdict:
                    xdict[y1] = [min(x1, xdict[y1][0]), max(x2, xdict[y1][1])]
                else:
                    xdict[y1] = [x1, x2]
                x1, y1 = xprev, yprev
                continue
            # Non horizontal side
            # Changes in x, y
            dx = x2 - x1
            dy = y2 - y1
            # Determine how steep the line is
            is_steep = abs(dy) > abs(dx)
            # Rotate line
            if is_steep:
                x1, y1 = y1, x1
                x2, y2 = y2, x2
            # Swap start and end points if necessary
            if x1 > x2:
                x1, x2 = x2, x1
                y1, y2 = y2, y1
            # Recalculate differentials
            dx = x2 - x1
            dy = y2 - y1
            # Calculate error
            error = dx >> 1
            ystep = 1 if y1 < y2 else -1
            y = y1
            # Calcualte minimum and maximum x values
            for x in range(x1, x2 + 1):
                if is_steep:
                    if x in xdict:
                        xdict[x] = [min(y, xdict[x][0]), max(y, xdict[x][1])]
                    else:
                        xdict[x] = [y, y]
                else:
                    if y in xdict:
                        xdict[y] = [min(x, xdict[y][0]), max(x, xdict[y][1])]
                    else:
                        xdict[y] = [x, x]
                error -= abs(dy)
                if error < 0:
                    y += ystep
                    error += dx
            x1, y1 = xprev, yprev
        # Fill polygon
        for y, x in xdict.items():
            self.draw_hline(x[0], y, x[1] - x[0] + 2, color)
    def fill_vrect(self, x, y, w, h, color):
        """Draw a filled rectangle (optimized for vertical drawing).
        Args:
            x (int): Starting X position.
            y (int): Starting Y position.
            w (int): Width of rectangle.
            h (int): Height of rectangle.
            color (int): RGB565 color value.
        """
        if self.is_off_grid(x, y, x + w - 1, y + h - 1):
            return
        chunk_width = 1024 // h
        chunk_count, remainder = divmod(w, chunk_width)
        chunk_size = chunk_width * h
        chunk_x = x
        if chunk_count:
            buf = color.to_bytes(2, 'big') * chunk_size
            for c in range(0, chunk_count):
                self.block(chunk_x, y,
                           chunk_x + chunk_width - 1, y + h - 1,
                           buf)
                chunk_x += chunk_width
        if remainder:
            buf = color.to_bytes(2, 'big') * remainder * h
            self.block(chunk_x, y,
                       chunk_x + remainder - 1, y + h - 1,
                       buf)
    def is_off_grid(self, xmin, ymin, xmax, ymax):
        """Check if coordinates extend past display boundaries.
        Args:
            xmin (int): Minimum horizontal pixel.
            ymin (int): Minimum vertical pixel.
            xmax (int): Maximum horizontal pixel.
            ymax (int): Maximum vertical pixel.
        Returns:
            boolean: False = Coordinates OK, True = Error.
        """
        if xmin < 0:
            print('x-coordinate: {0} below minimum of 0.'.format(xmin))
            return True
        if ymin < 0:
            print('y-coordinate: {0} below minimum of 0.'.format(ymin))
            return True
        if xmax >= self.width:
            print('x-coordinate: {0} above maximum of {1}.'.format(
                xmax, self.width - 1))
            return True
        if ymax >= self.height:
            print('y-coordinate: {0} above maximum of {1}.'.format(
                ymax, self.height - 1))
            return True
        return False
    def load_sprite(self, path, w, h):
        """Load sprite image.
        Args:
            path (string): Image file path.
            w (int): Width of image.
            h (int): Height of image.
        Notes:
            w x h cannot exceed 2048
        """
        buf_size = w * h * 2
        with open(path, "rb") as f:
            return f.read(buf_size)
    def reset_cpy(self):
        """Perform reset: Low=initialization, High=normal operation.
        Notes: CircuitPython implemntation
        """
        self.rst.value = False
        sleep(.05)
        self.rst.value = True
        sleep(.05)
    def reset_mpy(self):
        """Perform reset: Low=initialization, High=normal operation.
        Notes: MicroPython implemntation
        """
        self.rst(0)
        sleep(.05)
        self.rst(1)
        sleep(.05)
    def scroll(self, y):
        """Scroll display vertically.
        Args:
            y (int): Number of pixels to scroll display.
        """
        self.write_cmd(self.VSCRSADD, y >> 8, y & 0xFF)
    def set_scroll(self, top, bottom):
        """Set the height of the top and bottom scroll margins.
        Args:
            top (int): Height of top scroll margin
            bottom (int): Height of bottom scroll margin
        """
        if top + bottom <= self.height:
            middle = self.height - (top + bottom)
            print(top, middle, bottom)
            self.write_cmd(self.VSCRDEF,
                           top >> 8,
                           top & 0xFF,
                           middle >> 8,
                           middle & 0xFF,
                           bottom >> 8,
                           bottom & 0xFF)
    def sleep(self, enable=True):
        """Enters or exits sleep mode.
        Args:
            enable (bool): True (default)=Enter sleep mode, False=Exit sleep
        """
        if enable:
            self.write_cmd(self.SLPIN)
        else:
            self.write_cmd(self.SLPOUT)
    def write_cmd_mpy(self, command, *args):
        """Write command to OLED (MicroPython).
        Args:
            command (byte): ILI9341 command code.
            *args (optional bytes): Data to transmit.
        """
        self.dc(0)
        self.cs(0)
        self.spi.write(bytearray([command]))
        self.cs(1)
        # Handle any passed data
        if len(args) > 0:
            self.write_data(bytearray(args))
    def write_cmd_cpy(self, command, *args):
        """Write command to OLED (CircuitPython).
        Args:
            command (byte): ILI9341 command code.
            *args (optional bytes): Data to transmit.
        """
        self.dc.value = False
        self.cs.value = False
        # Confirm SPI locked before writing
        while not self.spi.try_lock():
            pass
        self.spi.write(bytearray([command]))
        self.spi.unlock()
        self.cs.value = True
        # Handle any passed data
        if len(args) > 0:
            self.write_data(bytearray(args))
    def write_data_mpy(self, data):
        """Write data to OLED (MicroPython).
        Args:
            data (bytes): Data to transmit.
        """
        self.dc(1)
        self.cs(0)
        self.spi.write(data)
        self.cs(1)
    def write_data_cpy(self, data):
        """Write data to OLED (CircuitPython).
        Args:
            data (bytes): Data to transmit.
        """
        self.dc.value = True
        self.cs.value = False
        # Confirm SPI locked before writing
        while not self.spi.try_lock():
            pass
        self.spi.write(data)
        self.spi.unlock()
        self.cs.value = True

示例代码


colors.py

这个MicroPython脚本通过将显示屏的颜色设置为不同的值来测试显示屏。

该脚本将显示颜色设置为红色,并使用sleep()函数等待1秒。它重复此过程,将显示颜色设置为不同的颜色(橙色、黄色、绿色、蓝色、紫色、粉色、棕色、灰色和白色),每次等待1秒。

from time import sleep
from ili9341 import Display, color565
from machine import Pin, SPI
def test():
    """Test code."""
    # Baud rate of 40000000 seems about the max
    spi = SPI(1, baudrate=10000000, sck=Pin(14), mosi=Pin(15))
    display = Display(spi, dc=Pin(6), cs=Pin(17), rst=Pin(7))
    # Set display color to red
    display.clear(color565(255, 0, 0))
    sleep(1)
    # Set display color to orange
    display.clear(color565(255, 128, 0))
    sleep(1)
    # Set display color to yellow
    display.clear(color565(255, 255, 0))
    sleep(1)
    # Set display color to green
    display.clear(color565(0, 255, 0))
    sleep(1)
    # Set display color to blue
    display.clear(color565(0, 0, 255))
    sleep(1)
    # Set display color to purple
    display.clear(color565(128, 0, 128))
    sleep(1)
    # Set display color to pink
    display.clear(color565(255, 192, 203))
    sleep(1)
    # Set display color to brown
    display.clear(color565(139, 69, 19))
    sleep(1)
    # Set display color to gray
    display.clear(color565(128, 128, 128))
    sleep(1)
    # Set display color to white
    display.clear(color565(255, 255, 255))
    sleep(1)
test()

运行效果图

Raspberry Pi Pico TFT LCD 触摸屏使用教程


animation.py

from time import sleep
from ili9341 import Display, color565
from machine import Pin, SPI
# Constants
SPI_SPEED = 10000000
DC_PIN = Pin(6)
CS_PIN = Pin(17)
RST_PIN = Pin(7)
BACK_COLOR = color565(0, 0, 0)
RECT_COLOR = color565(255, 0, 0)
POLY_COLOR = color565(0, 64, 255)
CIRC_COLOR = color565(0, 255, 0)
ELLP_COLOR = color565(255, 0, 0)
# Create display object
spi = SPI(1, baudrate=SPI_SPEED, sck=Pin(14), mosi=Pin(15))
display = Display(spi, dc=DC_PIN, cs=CS_PIN, rst=RST_PIN)
# Draw rectangles
def draw_rectangles():
    for x in range(0, 225, 15):
        display.fill_rectangle(x, 0, 15, 227, RECT_COLOR)
# Draw polygons
def draw_polygons():
    display.fill_polygon(7, 120, 120, 100, POLY_COLOR)
    sleep(1)
    display.draw_polygon(3, 120, 286, 30, POLY_COLOR, rotate=15)
    sleep(3)
# Draw circles
def draw_circles():
    display.fill_circle(132, 132, 70, CIRC_COLOR)
    sleep(1)
    display.draw_circle(132, 96, 70, color565(0, 0, 255))
    sleep(1)
# Draw ellipses
def draw_ellipses():
    display.fill_ellipse(96, 96, 30, 16, ELLP_COLOR)
    sleep(1)
    display.draw_ellipse(96, 256, 16, 30, color565(255, 255, 0))
# Clear screen and draw shapes
display.clear(BACK_COLOR)
draw_rectangles()
display.clear(BACK_COLOR)
draw_polygons()
display.clear(BACK_COLOR)
draw_circles()
display.clear(BACK_COLOR)
draw_ellipses()
# Clean up
display.cleanup()

运行效果图

Raspberry Pi Pico TFT LCD 触摸屏使用教程


bouncing_box.py

from machine import Pin, SPI
from random import random, seed
from ili9341 import Display, color565
from utime import sleep_us, ticks_cpu, ticks_us, ticks_diff
class Box(object):
    """Bouncing box."""
    def __init__(self, screen_width, screen_height, size, display, color):
        """Initialize box.
        Args:
            screen_width (int): Width of screen.
            screen_height (int): Width of height.
            size (int): Square side length.
            display (ILI9341): display object.
            color (int): RGB565 color value.
        """
        self.size = size
        self.w = screen_width
        self.h = screen_height
        self.display = display
        self.color = color
        # Generate non-zero random speeds between -5.0 and 5.0
        seed(ticks_cpu())
        r = random() * 10.0
        self.x_speed = 5.0 - r if r < 5.0 else r - 10.0
        r = random() * 10.0
        self.y_speed = 5.0 - r if r < 5.0 else r - 10.0
        self.x = self.w / 2.0
        self.y = self.h / 2.0
        self.prev_x = self.x
        self.prev_y = self.y
    def update_pos(self):
        """Update box position and speed."""
        x = self.x
        y = self.y
        size = self.size
        w = self.w
        h = self.h
        x_speed = abs(self.x_speed)
        y_speed = abs(self.y_speed)
        self.prev_x = x
        self.prev_y = y
        if x + size >= w - x_speed:
            self.x_speed = -x_speed
        elif x - size <= x_speed + 1:
            self.x_speed = x_speed
        if y + size >= h - y_speed:
            self.y_speed = -y_speed
        elif y - size <= y_speed + 1:
            self.y_speed = y_speed
        self.x = x + self.x_speed
        self.y = y + self.y_speed
    def draw(self):
        """Draw box."""
        x = int(self.x)
        y = int(self.y)
        size = self.size
        prev_x = int(self.prev_x)
        prev_y = int(self.prev_y)
        self.display.fill_hrect(prev_x - size,
                                prev_y - size,
                                size, size, 0)
        self.display.fill_hrect(x - size,
                                y - size,
                                size, size, self.color)
def test():
    """Bouncing box."""
    try:
        # Baud rate of 40000000 seems about the max
        spi = SPI(1, baudrate=10000000, sck=Pin(14), mosi=Pin(15))
        display = Display(spi, dc=Pin(6), cs=Pin(17), rst=Pin(7))
        display.clear()
        colors = [color565(255, 0, 0),
                  color565(0, 255, 0),
                  color565(0, 0, 255),
                  color565(255, 255, 0),
                  color565(0, 255, 255),
                  color565(255, 0, 255)]
        sizes = [12, 11, 10, 9, 8, 7]
        boxes = [Box(239, 319, sizes[i], display,
                 colors[i]) for i in range(6)]
        while True:
            timer = ticks_us()
            for b in boxes:
                b.update_pos()
                b.draw()
            # Attempt to set framerate to 30 FPS
            timer_dif = 33333 - ticks_diff(ticks_us(), timer)
            if timer_dif > 0:
                sleep_us(timer_dif)
    except KeyboardInterrupt:
        display.cleanup()
test()

运行效果图

Raspberry Pi Pico TFT LCD 触摸屏使用教程


在Raspberry Pi Pico上显示您的图像! 2.8″ TFT LCD

要在2.8英寸TFT LCD屏幕和Raspberry Pi Pico上显示图像,首先,图像必须转换为与屏幕兼容的原始格式。这可以通过图像编辑器或在线转换工具来完成。

要将大小为240×320像素的图像转换为原始文件格式,您可以使用Python或任何在线转换工具。下面是一个示例Python脚本,我们可以使用它将图像转换为原始格式:

在Thonny IDE中安装Pillow库

Open the “Tools” menu and click on “Manage packages”. Search “Pillow” and install it.

Raspberry Pi Pico TFT LCD 触摸屏使用教程

或者,您也可以使用pip命令安装Pillow

pip3 install pillow

要使用Python中的Pillow库将JPG图像转换为原始图像文件,可以使用以下代码:


img2rgb565.py

创建一个新文件夹,并在新文件夹中将以下代码另存为“img2rgb565.py”.

# Set the encoding to UTF-8
# This is important when working with non-ASCII characters in the code or input files
# as it ensures that the interpreter can correctly decode them.
# Without this, the program may crash with a UnicodeDecodeError.
# For more information: https://docs.python.org/3/howto/unicode.html
# -*- coding: utf-8 -*-
# Import necessary modules
from PIL import Image
from struct import pack
from os import path
import sys
def error(msg):
    """Display error and exit."""
    print (msg)
    sys.exit(-1)
def write_bin(f, pixel_list):
    """Save image in RGB565 format."""
    # Convert each pixel's RGB values to RGB565 format
    for pix in pixel_list:
        r = (pix[0] >> 3) & 0x1F
        g = (pix[1] >> 2) & 0x3F
        b = (pix[2] >> 3) & 0x1F
        # Write the pixel data to the output file in big-endian byte order
        f.write(pack('>H', (r << 11) + (g << 5) + b))
if __name__ == '__main__':
    # Get the input filename from the command-line arguments
    args = sys.argv
    # Check that only one argument was passed (the input filename)
    if len(args) != 2:
        error('Please specify input file: ./img2rgb565.py testing.png')
    # Get the input filename and check that it exists
    in_path = args[1]
    if not path.exists(in_path):
        error('File Not Found: ' + in_path)
    # Set the output filename to the input filename with .raw extension
    filename, ext = path.splitext(in_path)
    out_path = filename + '.raw'
    # Open the input image and convert it to RGB mode
    img = Image.open(in_path).convert('RGB')
    # Get the RGB values for each pixel in the image and store them in a list
    pixels = list(img.getdata())
    # Open the output file and write the RGB565 pixel data to it
    with open(out_path, 'wb') as f:
        write_bin(f, pixels)
    # Print a message indicating that the output file was saved
    print('Saved: ' + out_path) 

上面提供的代码将图像文件转换为原始格式。

要使用此脚本,您需要在系统上安装Python并安装PIL(Python Imaging Library)包。

例如,如果您在img2rgb565.py脚本的同一目录中有一个名为“test.png”的图像文件。只要图像文件和脚本文件在同一目录中,

Raspberry Pi Pico TFT LCD 触摸屏使用教程

在 thonny IDE 中打开 img2rgb565.py

Raspberry Pi Pico TFT LCD 触摸屏使用教程

用Run 命令来转换 jpg文件 为 RAW文件

%Run img2rgb565.py test.png

Raspberry Pi Pico TFT LCD 触摸屏使用教程

这里假设输入文件的名称是test.png。如果文件的名称不同,则需要将test.png替换为文件的实际名称。

Raspberry Pi Pico TFT LCD 触摸屏使用教程
Raspberry Pi Pico TFT LCD 触摸屏使用教程

运行脚本后,它将在同一目录中创建一个名为test.raw的新文件。此文件包含图像的原始二进制数据。

接下来上传 test.raw 文件到 Raspberry pi pico w

Raspberry Pi Pico TFT LCD 触摸屏使用教程
Raspberry Pi Pico TFT LCD 触摸屏使用教程

 

现在您已经生成了test.raw文件并将其上传到Raspberry Pi Pico,您可以使用以下脚本在显示器上显示图像。

Image.py

from time import sleep
from ili9341 import Display
from machine import Pin, SPI
def test():
    """Test code."""
    # Baud rate of 40000000 seems about the max
    spi = SPI(1, baudrate=10000000, sck=Pin(14), mosi=Pin(15))
    display = Display(spi, dc=Pin(6), cs=Pin(17), rst=Pin(7))
    display.draw_image('test.raw', 0, 0, 240, 320)
    sleep(200)
    display.cleanup()
test()

运行效果图

Raspberry Pi Pico TFT LCD 触摸屏使用教程


Raspberry Pi Pico TFT LCD 触摸屏使用教程

原文:https://diyprojectslab.com/raspberry-pi-pico-tft-lcd-touch-screen-tutorial


- 本文内容来自网络,如有侵权,请联系本站处理。

2024-12   阅读(1)   评论(0)
 标签: 创客 Pico MicroPython 显示屏

涨知识
74HC595

74HC595是一个8位串行输入、并行输出的位移缓存器。并行输出为三态输出。

评论:
相关文章
ESP32 MicroPython存储数据到闪存

在MicroPython的ESP32库中,NVS类用于管理非易失性存储,支持 32 位有符号整数和 二进制blob。


MicroPython umqtt库的使用

umqtt 是 MicroPython 的一个轻量级 MQTT 客户端库,使得在微控制器上使用 MQTT 协议变得简单易行。本文将介绍 umqtt 的实用方法,帮助您更好地在项目中应用这一技术。


小鹏物联网 MicroPython 图像采集方案

本方案是一个基于ESP32-CAM + 物联网的图像采集方案。


esp32cam开发板烧录micropython固件

‌ESP32-CAM与MicroPython结合可实现摄像头图像采集、视频流传输等功能,不过Micropython官方没有支持ESP32-CAM的固件,需要烧录第三方的专有固件。


小鹏物联网 MicroPython 智能浇花方案

相信很多人都有把绿植给养死的经历,可能是浇水过多、忘记浇水、较长时间不在家不能浇水等,本文介绍一种可以灵活定制的智能浇花方案。


MicroPython 开发ESP32应用之线程介绍及实例分析

MicroPython 在 ESP32 上支持线程(Thread)功能,通过_thread模块实现。线程允许程序并发执行多个任务,适合处理需要同时运行的场景,例如传感器数据采集和网络通信。


ESP32 MicroPython采集模拟传感器数值

使用了 MicroPython 库,通过 定时器(Timer) 和 ADC(模数转换器) 功能来实时读取传感器数据。使用定时器可以实现高精度、非阻塞、低资源消耗的周期性任务,保证实时性和可靠性,特别适用于嵌入式系统中的多任务处理和低功耗场景。


ESP32 MicroPython外部引脚中断处理

本文旨在介绍如何在运行MicroPython的ESP32上使用外部引脚中断功能。


新品Raspberry Pi Pico 2,你想知道的都在这里了!

Pico 2采用了树莓派自主设计的新款高性能安全型微控制器 RP2350,核心时钟速度更高、内存翻倍、Arm 核心更强大、具有新的安全功能和升级的接口能力,相比前代产品性能和功能都有大幅提升,同时保持与 Pico 系列产品的硬件和软件兼容性。


MicroPython Wifi网络

ESP32自带了WiFi模块,因此我们可以很容易的让ESP32接入网络。

搜索
小鹏STEM教研服务

专属教研服务系统,助您构建STEM课程体系,打造一站式教学环境。