Arduino UNO Q 采用双处理器架构,内部包含:
MPU(主处理器):Qualcomm QRB2210,Cortex-A53 核心,运行 Linux 系统
MCU(微控制器):STM32U585,Cortex-M33 核心,运行 Arduino 固件
两个处理器之间通过内部 UART 串口连接,由 Arduino App Lab 自动管理。
通信采用 RPC(远程过程调用) 模式,由 Arduino_RouterBridge 库提供。
MPU(Python)通过 Bridge.call("name", args) 向 MCU 发起调用,MCU 端通过 Bridge.provide_safe("name", function) 注册对应函数并响应。
所有 RPC 参数和返回值通过 MsgPack 二进制格式序列化。这意味着:
支持的基本类型:int、bool、String(arduino::String)
不支持:C 风格的 const char*(这是最常见的编译错误原因)
MCU 端(sketch.ino)
#include "ArduinoGraphics.h"
#include "Arduino_Modulino.h"
#include <Arduino_LED_Matrix.h>
#include "Arduino_RouterBridge.h"
ArduinoLEDMatrix matrix;
// 显示状态映射
// 0=空, 1=S(Standby), 2=R(Running), 3=H(Healthy), 4=E(Error)
int display_state = 0;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH); // 初始灭
matrix.begin();
Bridge.begin();
Monitor.begin();
// 注册——所有参数只能用 int 或 bool
Bridge.provide_safe("set_led", set_led);
Bridge.provide_safe("set_state", set_state); // int: 1=S, 2=R, 3=H, 4=E
Bridge.provide_safe("clear_matrix", clear_matrix);
// 开机显示 S
set_state(1);
Monitor.println("Ready");
}
void loop() {
delay(100);
}
/**
* 控制 LED_BUILTIN(LED3)
* state: 0=亮(低电平有效), 1=灭
*/
void set_led(int state) {
digitalWrite(LED_BUILTIN, state ? HIGH : LOW);
Monitor.print("LED state: ");
Monitor.println(state);
}
/**
* LED 矩阵显示状态字符(通过 int 而非 char*)
*/
void set_state(int code) {
display_state = code;
const char* chars[] = {"", "S", "R", "H", "E"};
if (code < 1 || code > 4) {
matrix.beginDraw();
matrix.clear();
matrix.endDraw();
return;
}
matrix.beginDraw();
matrix.clear();
matrix.stroke(0xFFFF00); // 黄色
matrix.textFont(Font_5x7);
matrix.beginText(0, 1, 0xFFFF00);
matrix.print(chars[code]);
matrix.endText();
matrix.endDraw();
Monitor.print("Display: ");
Monitor.println(chars[code]);
}
/**
* 清空矩阵
*/
void clear_matrix() {
matrix.beginDraw();
matrix.clear();
matrix.endDraw();
Monitor.println("Matrix cleared");
}需要添加几个头文件:ArduinoGraphics.h,Arduino_LED_Matrix.h,Arduino_RouterBridge.h,Arduino_Modulino.h
在App Lab左侧进行查找添加


初始化流程:
配置 LED_BUILTIN 为输出,初始为 HIGH
调用 matrix.begin() 初始化 LED 矩阵
调用 Bridge.begin() 初始化串口桥
调用 Monitor.begin() 初始化 Console 输出
用 Bridge.provide_safe() 注册三个 RPC 函数
三个 RPC 函数说明:
| set_led | Bridge.call("set_led", 0) | 控制板上 LED3 亮/灭 |
| set_state | Bridge.call("set_state", 1) | 矩阵显示状态字符 |
| clear_matrix | Bridge.call("clear_matrix") | 清空矩阵显示 |
set_state 函数映射表:
| 0 | (空) | 无显示 |
| 1 | S | Standby 待机 |
| 2 | R | Running 运行中 |
| 3 | H | Healthy 正常 |
| 4 | E | Error 错误 |
MPU 端(main.py)
from arduino.app_utils import *
import time
def loop():
global cycle
time.sleep(2)
cycle += 1
# 显示 S (Standby)
Bridge.call("set_state", 1)
print(f"Cycle {cycle}: SetState(1=S)")
time.sleep(1)
# 点亮 LED3
Bridge.call("set_led", 0) # 0 = ON (低电平有效)
print(f"Cycle {cycle}: LED ON")
time.sleep(1)
# 灭 LED3
Bridge.call("set_led", 1) # 1 = OFF
print(f"Cycle {cycle}: LED OFF")
time.sleep(1)
# 显示 H (Healthy)
Bridge.call("set_state", 3) # 3 = H
print(f"Cycle {cycle}: SetState(3=H)")
time.sleep(1)
# 显示 E (Error)
Bridge.call("set_state", 4) # 4 = E
print(f"Cycle {cycle}: SetState(4=E)")
time.sleep(1)
# 清空矩阵
Bridge.call("clear_matrix")
print(f"Cycle {cycle}: Clear")
if cycle >= 5:
print("Done!")
cycle = 0
App.run(user_loop=loop)| 1 | Bridge.call("set_state", 1) | 矩阵显示 "S" |
| 2 | Bridge.call("set_led", 0) | 点亮 LED3 |
| 3 | Bridge.call("set_led", 1) | 熄灭 LED3 |
| 4 | Bridge.call("set_state", 3) 然后 4 | 矩阵依次显示 "H" → "E" |
| 5 | Bridge.call("clear_matrix") | 清空矩阵 |
Python 变量必须在 App.run() 之前全局初始化(否则会报 NameError)
Bridge.call() 是非阻塞调用,返回执行结果
Monitor.print() 在 MCU 端输出,显示在 App Lab Console 中
MPU Console 输出:

MCU Monitor 输出:

LED 矩阵显示: 按 S → H → E → 空 的顺序循环显示,每个 cycle 状态变化一次。
板上 LED3: 每次循环中点亮后熄灭一次,肉眼可观察。

我要赚赏金
