arduino-serial-monitor

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Arduino Serial Monitor

Arduino Serial Monitor

This skill provides advanced tools for reading and analyzing serial monitor data from Arduino boards, enhancing the debugging experience beyond the basic Arduino IDE serial monitor.
本Skill提供了用于读取和分析Arduino开发板串口监视器数据的高级工具,相比基础的Arduino IDE串口监视器,可大幅提升调试体验。

Features

功能特性

  • Real-time Serial Monitoring: Connect to Arduino serial ports and display data in real-time
  • Data Logging: Save serial output to files with timestamps for later analysis
  • Filtering & Pattern Matching: Filter output by keywords, regex patterns, or data types
  • Error Detection: Automatically highlight common error patterns and warnings
  • Multiple Format Support: Handle different data formats (text, JSON, CSV, binary)
  • Cross-platform: Works with Windows, macOS, and Linux serial ports
  • 实时串口监控:连接到Arduino串口并实时显示数据
  • 数据记录:将串口输出保存到带时间戳的文件中,以便后续分析
  • 过滤与模式匹配:按关键词、正则表达式或数据类型过滤输出内容
  • 错误检测:自动高亮常见错误模式和警告信息
  • 多格式支持:支持处理不同数据格式(文本、JSON、CSV、二进制)
  • 跨平台兼容:可在Windows、macOS和Linux系统的串口上运行

Usage

使用方法

Basic Serial Monitoring

基础串口监控

bash
undefined
bash
undefined

Monitor serial port with default settings (9600 baud)

使用默认设置(9600波特率)监控串口

uv run --no-project scripts/monitor_serial.py --port COM3
uv run --no-project scripts/monitor_serial.py --port COM3

Specify baud rate and output file

指定波特率和输出文件

uv run --no-project scripts/monitor_serial.py --port /dev/ttyACM0 --baud 115200 --output debug.log
uv run --no-project scripts/monitor_serial.py --port /dev/ttyACM0 --baud 115200 --output debug.log

Filter for specific patterns

过滤特定模式内容

uv run --no-project scripts/monitor_serial.py --port COM3 --filter "ERROR|WARNING"
undefined
uv run --no-project scripts/monitor_serial.py --port COM3 --filter "ERROR|WARNING"
undefined

Advanced Debugging

高级调试

bash
undefined
bash
undefined

Parse JSON data from serial

解析串口输出的JSON数据

uv run --no-project scripts/monitor_serial.py --port COM3 --format json --pretty
uv run --no-project scripts/monitor_serial.py --port COM3 --format json --pretty

Monitor with timestamp and color coding

带时间戳和颜色编码的监控

uv run --no-project scripts/monitor_serial.py --port COM3 --timestamp --color
uv run --no-project scripts/monitor_serial.py --port COM3 --timestamp --color

Detect common Arduino errors

检测常见Arduino错误

uv run --no-project scripts/monitor_serial.py --port COM3 --detect-errors
undefined
uv run --no-project scripts/monitor_serial.py --port COM3 --detect-errors
undefined

Script Options

脚本选项

  • --port
    : Serial port (e.g., COM3, /dev/ttyACM0)
  • --baud
    : Baud rate (default: 9600)
  • --output
    : Output file for logging
  • --filter
    : Regex pattern to filter lines
  • --format
    : Data format (text, json, csv, binary)
  • --timestamp
    : Add timestamps to output
  • --color
    : Enable color-coded output
  • --detect-errors
    : Highlight common error patterns
  • --timeout
    : Connection timeout in seconds
  • --port
    :串口端口(例如:COM3、/dev/ttyACM0)
  • --baud
    :波特率(默认值:9600)
  • --output
    :用于记录数据的输出文件
  • --filter
    :用于过滤行内容的正则表达式
  • --format
    :数据格式(text、json、csv、binary)
  • --timestamp
    :为输出内容添加时间戳
  • --color
    :启用颜色编码输出
  • --detect-errors
    :高亮常见错误模式
  • --timeout
    :连接超时时间(秒)

Common Arduino Debugging Scenarios

常见Arduino调试场景

Memory Issues

内存问题

Filter for: "low memory|stack overflow|heap"
过滤规则:"low memory|stack overflow|heap"

Sensor Data Validation

传感器数据验证

Filter for: "sensor|reading|value"
Format as: json
过滤规则:"sensor|reading|value"
格式设置:json

Timing Analysis

时序分析

Enable: --timestamp
Filter for: "start|end|duration"
启用:--timestamp
过滤规则:"start|end|duration"

Communication Errors

通信错误

Filter for: "timeout|failed|error"
Enable: --detect-errors
过滤规则:"timeout|failed|error"
启用:--detect-errors

Integration with Arduino CLI

与Arduino CLI集成

bash
undefined
bash
undefined

Compile and upload, then monitor

编译、上传,然后监控

arduino-cli compile --fqbn arduino:avr:uno sketch/ arduino-cli upload -p COM3 --fqbn arduino:avr:uno sketch/ uv run --no-project scripts/monitor_serial.py --port COM3
undefined
arduino-cli compile --fqbn arduino:avr:uno sketch/ arduino-cli upload -p COM3 --fqbn arduino:avr:uno sketch/ uv run --no-project scripts/monitor_serial.py --port COM3
undefined

Troubleshooting

故障排除

Port Not Found

端口未找到

  • Check
    arduino-cli board list
    for available ports
  • Ensure Arduino is connected and drivers are installed
  • Try different port names (COM1-COM99 on Windows, /dev/ttyACM* on Linux)
  • 运行
    arduino-cli board list
    查看可用端口
  • 确保Arduino已连接且驱动已安装
  • 尝试不同的端口名称(Windows系统为COM1-COM99,Linux系统为/dev/ttyACM*)

No Data Received

未接收到数据

  • Verify baud rate matches Arduino sketch (
    Serial.begin(9600)
    )
  • Check USB cable connection
  • Reset Arduino board while monitoring
  • 确认波特率与Arduino程序中的设置匹配(
    Serial.begin(9600)
  • 检查USB线缆连接情况
  • 在监控时重置Arduino开发板

Permission Errors (Linux/macOS)

权限错误(Linux/macOS)

bash
undefined
bash
undefined

Add user to dialout group

将用户添加到dialout组

sudo usermod -a -G dialout $USER
sudo usermod -a -G dialout $USER

Logout and login again

注销后重新登录

undefined
undefined

Dependencies

依赖项

  • Python 3.8+
  • pyserial
  • colorama (for colored output)
  • Install via:
    uv add pyserial colorama
  • Python 3.8+
  • pyserial
  • colorama(用于彩色输出)
  • 安装命令:
    uv add pyserial colorama

Examples

示例

Basic Temperature Sensor Monitoring

基础温度传感器监控

python
// Arduino sketch
void setup() {
  Serial.begin(9600);
}

void loop() {
  float temp = analogRead(A0) * 0.488;
  Serial.print("Temperature: ");
  Serial.print(temp);
  Serial.println(" C");
  delay(1000);
}
bash
uv run --no-project scripts/monitor_serial.py --port COM3 --filter "Temperature" --timestamp
python
// Arduino程序
void setup() {
  Serial.begin(9600);
}

void loop() {
  float temp = analogRead(A0) * 0.488;
  Serial.print("Temperature: ");
  Serial.print(temp);
  Serial.println(" C");
  delay(1000);
}
bash
uv run --no-project scripts/monitor_serial.py --port COM3 --filter "Temperature" --timestamp

JSON Data Parsing

JSON数据解析

python
// Arduino sketch with JSON output
#include <ArduinoJson.h>

void setup() {
  Serial.begin(115200);
}

void loop() {
  StaticJsonDocument<200> doc;
  doc["temperature"] = analogRead(A0) * 0.488;
  doc["humidity"] = analogRead(A1) * 0.146;
  doc["timestamp"] = millis();
  serializeJson(doc, Serial);
  Serial.println();
  delay(2000);
}
bash
uv run --no-project scripts/monitor_serial.py --port COM3 --format json --pretty
python
// 输出JSON格式数据的Arduino程序
#include <ArduinoJson.h>

void setup() {
  Serial.begin(115200);
}

void loop() {
  StaticJsonDocument<200> doc;
  doc["temperature"] = analogRead(A0) * 0.488;
  doc["humidity"] = analogRead(A1) * 0.146;
  doc["timestamp"] = millis();
  serializeJson(doc, Serial);
  Serial.println();
  delay(2000);
}
bash
uv run --no-project scripts/monitor_serial.py --port COM3 --format json --pretty