15浏览
查看: 15|回复: 0

[Micropython] Micropython玩转ESP32P4:开启屏幕显示

[复制链接]
本帖最后由 PY学习笔记 于 2025-8-19 17:40 编辑

近期,DFRobot已经推出了全新开发板 FireBeetle 2 ESP32-P4。这块开发板搭载了 ESP32-P4 主控,虽未集成 Wi-Fi 与蓝牙,但凭借强劲性能,依然令人眼前一亮。很荣幸能体验这块开发板!
1.开发板介绍
FireBeetle 2 ESP32-P4有很多种外设:
  • Type-C USB CDC:Type-C USB烧录、调试接口
  • IO3/LED:板载LED引脚
  • Power LED:主板电源指示灯
  • RST:复位按键
  • IO35/BOOT:IO引脚/BOOT按键
  • MIC: MEMS PDM麦克风
  • HIGH-SPEED USB OTG 2.0: Type-C高速USB OTG 2.0
  • ESP32-P4:ESP32-P4芯片
  • MIPI-DSI: 两通道MIPI-DSI屏幕(兼容树莓派4B DSI屏幕线序)
  • MIPI-CSI: 两通道MIPI-DSI屏幕(兼容树莓派4B CSI摄像头线序)
  • TF Card: TF卡插槽
  • 16MB FLASH: 16MB Flash存储
  • ESP32-C6:ESP32-C6-MINI-1模组,通过SDIO与ESP32-P4连接,用于扩展WiFi、蓝牙

2.添加屏幕驱动
依旧放在GitHub上:
https://github.com/Vincent1-python/esp32p4-micropython-dfrobot-rpi-dsi-driver
按照《Micropython玩转ESP32P4:绑定AI相关模块》再次编译下载即可
3.正式体验
这里先做一个单显示测试:
  1. from lcd import *
  2. from machine import Pin
  3. from machine import I2C
  4. i2c = I2C(0,scl=Pin(8), sda=Pin(7))
  5. init()
  6. i2c.writeto_mem(0x45, 0x86, b'\xff')
  7. # 初始化LCD
  8. clear(WHITE)
  9. string(10, 0, 500, 32, 32, "DFRobot ESP32-P4 MIPI LCD TEST", RED)
  10. string(10, 40, 240, 24, 24, "PYSN", BLUE)
  11. string(10, 80, 240, 24, 24, "DFRobot", BRRED)
复制代码

触摸测试:
  1. from machine import Pin
  2. from machine import I2C
  3. import time,lcd
  4. from ft5x06 import FT5x06
  5. # 触摸点颜色和状态
  6. POINT_COLOR_TBL = [lcd.RED, lcd.GREEN, lcd.BLUE, lcd.YELLOW, lcd.BLACK]
  7. last_points = [[0, 0] for _ in range(5)]  # 5个触摸点的最后位置
  8. def lcd_draw_bline(x1, y1, x2, y2, size, color):
  9.     """优化后的带宽度直线绘制函数"""
  10.     dx = abs(x2 - x1)
  11.     dy = abs(y2 - y1)
  12.     sx = 1 if x1 < x2 else -1
  13.     sy = 1 if y1 < y2 else -1
  14.     err = dx - dy
  15.    
  16.     while True:
  17.         lcd.fill_circle(x1, y1, size, color)
  18.         if x1 == x2 and y1 == y2:
  19.             break
  20.         e2 = 2 * err
  21.         if e2 > -dy:
  22.             err -= dy
  23.             x1 += sx
  24.         if e2 < dx:
  25.             err += dx
  26.             y1 += sy
  27. if __name__ == "__main__":
  28.    
  29.     lcd.init()
  30.     i2c = I2C(0,scl=Pin(8), sda=Pin(7))
  31.     t = FT5x06(i2c)
  32.     i2c.writeto_mem(0x45, 0x86, b'\xff')
  33.     lcd.clear(lcd.WHITE)
  34.     while True:
  35.         touch = t.get_positions()
  36.         if touch:
  37.             for i, point in enumerate(touch[:5]):
  38.                 # 计算当前触摸点坐标
  39.                 curr_x = 800-point[0]
  40.                 curr_y = 480-point[1]
  41.                
  42.                 # 绘制从上次位置到当前位置的线
  43.                 if last_points[i] != [0, 0]:
  44.                     lcd_draw_bline(last_points[i][0], last_points[i][1],
  45.                                  curr_x, curr_y, 4, POINT_COLOR_TBL[i])
  46.                
  47.                 # 更新最后位置
  48.                 last_points[i] = [curr_x, curr_y]
  49.         else:
  50.             # 无触摸时重置所有点
  51.             for i in range(5):
  52.                 last_points[i] = [0, 0]
复制代码


4.效果
Micropython玩转ESP32P4:开启屏幕显示图1
Micropython玩转ESP32P4:开启屏幕显示图2




您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4 备案 沪公网安备31011502402448

© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail