Link to Chinese Version.
In embedded development, Slave computers typically don’t participate in decision-making and serve as actuators or sensors.
In this project, each module functions as a slave computer executing instructions from the host computer.
Development Setup
- Slave computer: Arduino Uno
- Host computer: Raspberry Pi 5
Code Design
State computer Design
The slave computer doesn’t make decisions and can be treated as a state computer:
stateDiagram-v2
[*] --> Disconnected
Disconnected --> CheckConnection: Periodic check
CheckConnection --> Disconnected: No response
CheckConnection --> WaitCommand: Responded
WaitCommand --> CheckConnection: Periodic check
WaitCommand --> FeedbackConfirm: Checksum confirmed
FeedbackConfirm --> Execute: Verified & confirmed
FeedbackConfirm --> CheckConnection: No response/canceled
Execute --> WaitCommand
Communication Protocol Design
-
Physical layer (Communication Channel): UART over USB
Advantages:
- Easy operation
- Reliable USB connection
-
Data packet structure (Encoder-modulator/”Link Layer”):
packet-beta
title UART Packet
0-7: "Start Byte"
8-15: "CRC"
16-79: "Data"
80-87: "Stop Byte"
-
Application layer (Message Source):
Packet size: 16 bytes (designed for Python compatibility, equivalent to two
int
types):struct __attribute__((packed)) STRUCT_Message { int32_t msg_type; char data[4]; } Message;
-
Connection protocols:
ping
: Test host computer availabilitywait
: Notify host computer of standby statuscommand
: Instruction execution cycle
Protocol details available in the Year 2 Project Slave Computer Wiki.
Debugging Design
With no display/terminal, the onboard LED indicates status:
- Blinking: No connection
- Steady: Connected
The following figure is a screenshot of the protocol design during development (translated by Google):
Issues & Solutions
Serial port occupation during programming
Analysis: Conflict between host computer process and programming process
Solution: Manually close host computer process before programming
Intermittent connectivity
Analysis: CRC validation failures (observed via serial debugging)
Solution: Track last 8 ping records - consider connected if majority succeed
Testing
Connection test: Verify slave computer status changes when host computer starts/stops
Servo control test: Validate host computer command execution
Serial message capture: Oscilloscope verification of communication
Synchronized testing with host computer - see Host Computer Development Blog for details.