arduino-serial-monitor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseArduino 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
undefinedbash
undefinedMonitor 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"
undefineduv run --no-project scripts/monitor_serial.py --port COM3 --filter "ERROR|WARNING"
undefinedAdvanced Debugging
高级调试
bash
undefinedbash
undefinedParse 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
undefineduv run --no-project scripts/monitor_serial.py --port COM3 --detect-errors
undefinedScript Options
脚本选项
- : Serial port (e.g., COM3, /dev/ttyACM0)
--port - : Baud rate (default: 9600)
--baud - : Output file for logging
--output - : Regex pattern to filter lines
--filter - : Data format (text, json, csv, binary)
--format - : Add timestamps to output
--timestamp - : Enable color-coded output
--color - : Highlight common error patterns
--detect-errors - : Connection timeout in seconds
--timeout
- :串口端口(例如:COM3、/dev/ttyACM0)
--port - :波特率(默认值:9600)
--baud - :用于记录数据的输出文件
--output - :用于过滤行内容的正则表达式
--filter - :数据格式(text、json、csv、binary)
--format - :为输出内容添加时间戳
--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"
格式设置:jsonTiming 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-errorsIntegration with Arduino CLI
与Arduino CLI集成
bash
undefinedbash
undefinedCompile 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
undefinedarduino-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
undefinedTroubleshooting
故障排除
Port Not Found
端口未找到
- Check for available ports
arduino-cli board list - 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
undefinedbash
undefinedAdd user to dialout group
将用户添加到dialout组
sudo usermod -a -G dialout $USER
sudo usermod -a -G dialout $USER
Logout and login again
注销后重新登录
undefinedundefinedDependencies
依赖项
- 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" --timestamppython
// 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" --timestampJSON 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 --prettypython
// 输出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