dual-controller-sync
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDual-Controller Synchronization Guide
双控制器同步指南
When to Use This Skill
何时使用该技能
Apply this skill when the user:
- Has issues with I2C communication between main and camera controllers
- Needs to debug the dual-ESP32 robocar architecture
- Wants to monitor both controllers simultaneously
- Experiences timing or synchronization issues
当用户遇到以下场景时可使用本技能:
- 主控与摄像头控制器之间的I2C通信存在异常
- 需要调试双ESP32无人车架构
- 需要同时监控两个控制器的运行状态
- 遇到时序或同步类问题
Architecture Overview
架构概述
┌─────────────────────┐ I2C ┌─────────────────────┐
│ Main Controller │◄────────────►│ Camera Module │
│ Heltec WiFi LoRa │ │ ESP32-CAM │
│ │ │ │
│ - AI decisions │ │ - Image capture │
│ - Motor control │ │ - Vision analysis │
│ - LoRa comms │ │ - I2C slave │
└─────────────────────┘ └─────────────────────┘┌─────────────────────┐ I2C ┌─────────────────────┐
│ Main Controller │◄────────────►│ Camera Module │
│ Heltec WiFi LoRa │ │ ESP32-CAM │
│ │ │ │
│ - AI decisions │ │ - Image capture │
│ - Motor control │ │ - Vision analysis │
│ - LoRa comms │ │ - I2C slave │
└─────────────────────┘ └─────────────────────┘Build Both Controllers
编译两个控制器固件
bash
undefinedbash
undefinedBuild main controller
编译主控制器固件
make robocar-build-main
make robocar-build-main
Build camera module
编译摄像头模块固件
make robocar-build-cam
make robocar-build-cam
Or build both
同时编译两者固件
make robocar-build-all
undefinedmake robocar-build-all
undefinedMonitor Both Controllers
监控两个控制器运行状态
Two Terminal Setup
双终端配置方案
Open two terminals and monitor both:
Terminal 1 - Main Controller:
bash
make robocar-monitor-main PORT=/dev/cu.usbserial-0001Terminal 2 - Camera Module:
bash
make robocar-monitor-cam PORT=/dev/cu.usbserial-0002打开两个终端分别监控两个设备:
终端1 - 主控制器:
bash
make robocar-monitor-main PORT=/dev/cu.usbserial-0001终端2 - 摄像头模块:
bash
make robocar-monitor-cam PORT=/dev/cu.usbserial-0002Identifying Ports
端口识别方法
If unsure which device is which:
bash
ls -la /dev/cu.usbserial-* /dev/ttyUSB*Look for:
- Device that appears first after connecting main controller
- Device that appears after connecting camera module
如果不确定设备对应的端口:
bash
ls -la /dev/cu.usbserial-* /dev/ttyUSB*判断规则:
- 连接主控制器后最先出现的设备
- 连接摄像头模块后新增的设备
I2C Communication Debugging
I2C通信调试
Common I2C Issues
常见I2C问题
| Symptom | Possible Cause | Solution |
|---|---|---|
| No response | Wrong address | Verify 7-bit address format |
| Timeout | Missing pull-ups | Add 4.7K resistors on SDA/SCL |
| Corrupted data | Speed too fast | Reduce I2C clock frequency |
| Intermittent | Loose connection | Check wiring |
| 现象 | 可能原因 | 解决方案 |
|---|---|---|
| 无响应 | 地址配置错误 | 确认使用7位地址格式 |
| 超时 | 缺少上拉电阻 | 在SDA/SCL线路上添加4.7K电阻 |
| 数据损坏 | 传输速率过高 | 降低I2C时钟频率 |
| 通信不稳定 | 连接松动 | 检查接线是否牢固 |
I2C Address Configuration
I2C地址配置
Ensure both controllers use the same address:
Main controller (master):
c
#define CAMERA_I2C_ADDR 0x55 // 7-bit addressCamera module (slave):
c
#define I2C_SLAVE_ADDR 0x55 // Must match master确保两个控制器使用相同的通信地址:
主控制器(主设备):
c
#define CAMERA_I2C_ADDR 0x55 // 7-bit address摄像头模块(从设备):
c
#define I2C_SLAVE_ADDR 0x55 // Must match masterVerify I2C Wiring
验证I2C接线
Main Controller Camera Module
SDA (21) ◄──────────► SDA (GPIO)
SCL (22) ◄──────────► SCL (GPIO)
GND ◄──────────► GNDPull-up resistors (4.7K) on SDA and SCL to 3.3V.
Main Controller Camera Module
SDA (21) ◄──────────► SDA (GPIO)
SCL (22) ◄──────────► SCL (GPIO)
GND ◄──────────► GNDSDA和SCL线路需要接4.7K上拉电阻到3.3V。
Protocol Debugging
协议调试
Expected Communication Pattern
预期通信流程
- Main sends command byte
- Camera processes command
- Camera sends response
- Main reads response
- 主控制器发送命令字节
- 摄像头处理接收的命令
- 摄像头返回响应数据
- 主控制器读取响应数据
Debug Logging
调试日志配置
Enable verbose I2C logging in both projects:
c
esp_log_level_set("i2c", ESP_LOG_DEBUG);Look for matching transactions:
- Main: "Sent command 0x01 to 0x55"
- Camera: "Received command 0x01"
在两个项目中开启I2C详细日志输出:
c
esp_log_level_set("i2c", ESP_LOG_DEBUG);查找匹配的通信事务日志:
- 主控制器:"Sent command 0x01 to 0x55"
- 摄像头:"Received command 0x01"
Timing Issues
时序问题处理
If commands arrive too fast:
Add delay between commands:
c
i2c_master_cmd_begin(I2C_NUM, cmd, pdMS_TO_TICKS(100));
vTaskDelay(pdMS_TO_TICKS(10)); // Wait for slave to process如果命令发送频率过高:
在命令之间添加延迟:
c
i2c_master_cmd_begin(I2C_NUM, cmd, pdMS_TO_TICKS(100));
vTaskDelay(pdMS_TO_TICKS(10)); // Wait for slave to processFlash Workflow
烧录流程
Flash Both Controllers
烧录两个控制器固件
bash
undefinedbash
undefinedFlash main controller first
先烧录主控制器
make robocar-flash-main PORT=/dev/cu.usbserial-0001
make robocar-flash-main PORT=/dev/cu.usbserial-0001
Then flash camera (requires GPIO0 to GND)
再烧录摄像头(需要先将GPIO0接GND)
Connect GPIO0 to GND on ESP32-CAM
把ESP32-CAM上的GPIO0连接到GND
make robocar-flash-cam PORT=/dev/cu.usbserial-0002
make robocar-flash-cam PORT=/dev/cu.usbserial-0002
Disconnect GPIO0 from GND and reset
烧录完成后断开GPIO0与GND的连接并复位设备
undefinedundefinedDevelopment Cycle
开发迭代流程
For rapid iteration:
- Make code changes
- Build:
make robocar-build-all - Flash main:
make robocar-flash-main - Flash camera (GPIO0→GND):
make robocar-flash-cam - Monitor both in separate terminals
适用于快速开发迭代场景:
- 修改代码
- 编译:
make robocar-build-all - 烧录主控制器:
make robocar-flash-main - 烧录摄像头(GPIO0接GND):
make robocar-flash-cam - 在独立终端中同时监控两个控制器
Common Synchronization Issues
常见同步问题
Issue: Camera Not Responding
问题:摄像头无响应
Symptoms:
- Main reports I2C timeout
- Camera not in monitor output
Debug Steps:
- Verify camera is powered and running
- Check I2C address matches
- Verify GPIO pins for I2C slave
- Check clock speed compatibility
现象:
- 主控制器上报I2C超时
- 监控输出中没有摄像头的运行日志
调试步骤:
- 确认摄像头已通电并正常运行
- 检查I2C地址是否匹配
- 确认I2C从设备的GPIO引脚配置正确
- 检查时钟速率兼容性
Issue: Corrupted Data
问题:数据损坏
Symptoms:
- Data received but values wrong
- Checksum failures
Debug Steps:
- Reduce I2C speed (try 100kHz)
- Add pull-up resistors
- Check for noise on long wires
- Verify endianness of multi-byte data
现象:
- 能收到数据但数值错误
- 校验和校验失败
调试步骤:
- 降低I2C速率(建议尝试100kHz)
- 添加上拉电阻
- 检查长线路是否存在噪声干扰
- 确认多字节数据的字节序配置正确
Issue: Timing Mismatch
问题:时序不匹配
Symptoms:
- Works sometimes, fails other times
- Camera not ready when main sends command
Debug Steps:
- Add handshake mechanism
- Increase timeout values
- Use interrupt-based I2C on camera
- Add ready signal GPIO
现象:
- 通信时好时坏,成功率不稳定
- 主控制器发送命令时摄像头未就绪
调试步骤:
- 添加通信握手机制
- 增大超时时间阈值
- 摄像头端使用基于中断的I2C实现
- 新增就绪信号GPIO引脚
Tools and Commands
工具与命令
bash
undefinedbash
undefinedShow system info
展示系统信息
make robocar-info
make robocar-info
Check environment
检查开发环境
make check-environment
make check-environment
Clean and rebuild
清理并重新编译
make robocar-clean
make robocar-build-all
make robocar-clean
make robocar-build-all
Full dev cycle for main
主控制器完整开发流程
make robocar-develop-main PORT=/dev/xxx
make robocar-develop-main PORT=/dev/xxx
Full dev cycle for camera
摄像头模块完整开发流程
make robocar-develop-cam PORT=/dev/xxx
undefinedmake robocar-develop-cam PORT=/dev/xxx
undefined