The bench
Every lesson opens two Unos side by side: the probe on the left and the buoy on the right. They talk over SoftwareSerial at 9600 baud, probe pin 9 to buoy pin 8 and buoy pin 9 to probe pin 8, with their grounds joined. A slide switch on a half-size breadboard, the storm switch, drives pin 4 of both boards: low is a calm sea, high is a storm. Each board also lights a lamp on pin 13: yellow on the probe, green on the buoy.
Take the course at Design a protocol on /learn.
What each pair of sketches does
Each lesson has a probe sketch (ending in p) and a buoy sketch (ending in b).
prtframep,prtframeb: frames of a start byte, a length and a payload, found by a three-state parser. The storm loses a byte, and a gap timeout in the buoy drops the half frame.prtescp,prtescb: frames that end on a 0x7E flag, and byte stuffing with a 0x7D escape for the depths (125 and 126 m) whose bytes are the escape and the flag.prtcrcp,prtcrcb: a CRC-16/CCITT-FALSE on every frame, checked against the standard check value 0x29B1. The storm flips one bit.prtackp,prtackb: stop-and-wait, with acks by sequence number, retries, and a buoy that recognizes a repeat whose ack was lost.prtverp,prtverb: a hello with a version, message types, an unknown type skipped by its length, and a version 2 field that an old buoy ignores.prttextp,prttextb: the same reading as an NMEA-style sentence with an XOR checksum or as a 9-byte binary frame, with the bytes and the parse time of each.prtbossp,prtbossb: the boss project. The probe uploads a 20-reading dive log with flags, stuffing, a version, CRC-16, acks, retries with a growing timeout and a final count, and the buoy stores every reading once and in order.
Where the noise comes from
The simulated wire between the boards is perfect, so the storm is made on purpose. While the switch is on, each sketch damages its own frames on a fixed schedule: a lost byte, a flipped bit, a garbled ack. That is fault injection, which is how real protocols are tested, and the schedule is fixed so the readings in each lesson come out the same every time. The comments at the top of each sketch say exactly what the storm does there.
Honest limits
- No real line noise, crosstalk or timing drift between the boards: only the damage the sketches inject.
- SoftwareSerial is half duplex, as on a real Uno: a board cannot receive while it sends. Stop-and-wait never needs both at once.
- Both boards print to one serial monitor at 115200 baud, so each sketch finishes printing and pauses 20 ms before it talks on the link. That keeps one board's lines from landing inside the other's; a real link would not need the pause.
Related
Talk to chips for UART, I2C and SPI basics, and LoRa long range, where the same ideas cross kilometers by radio.