|
1 | | -# Basic Duplex: MH-Tiny88 ↔ ESP-M3 |
| 1 | +# Basic Duplex: MH-Tiny88 ↔ ESP-M3 (Polling Style) |
2 | 2 |
|
3 | | -This example demonstrates a *full-duplex, bidirectional* link between an *MH-Tiny88* (acting as a sensor node) and an *ESP-M3* (acting as a Wi-Fi bridge). It utilizes *COBS framing* and *Fletcher-16 checksums* to ensure data integrity over a noisy serial line. |
| 3 | +This example demonstrates a *full-duplex, bidirectional* link between an *MH-Tiny88* (Sensor Node) and an *ESP-M3* (Wi-Fi Bridge). It uses the standard *Polling* pattern to check for new data, making it easy to integrate into existing Arduino sketches. |
4 | 4 |
|
5 | | -## 🛠 Hardware Setup |
| 5 | +## 🌟 Features |
6 | 6 |
|
7 | | -Since the MH-Tiny88 operates at *5V* and the ESP-M3 operates at *3.3V*, you must use a voltage divider or level shifter on the Tiny88's TX line to avoid damaging the ESP. |
| 7 | +- *Polling Logic*: Uses `link.available()` and `link.peek()` for manual data handling. |
| 8 | +- *Bi-Directional*: Both devices act as peers, sending and receiving data simultaneously. |
| 9 | +- *Reliable*: Protected by *COBS* framing and *Fletcher-16 checksums*. |
8 | 10 |
|
9 | | -### Wiring Diagram |
| 11 | +## 🛠 Hardware Setup |
10 | 12 |
|
11 | | -MH-Tiny88 (5V) Connection ESP-M3 (3.3V) |
12 | | -TX (D1) ───[ 1kΩ ]──┬── RX |
13 | | -└─[ 2kΩ ]─┤ GND |
14 | | -RX (D0) ────────────── TX |
15 | | -GND ────────────── GND (Common) |
| 13 | +The MH-Tiny88 (*5V*) and ESP-M3 (*3.3V*) require a voltage divider on the Tiny88's TX line to protect the ESP. |
16 | 14 |
|
17 | | -> Note: The 2kΩ resistor goes to Ground, creating a 3.3V signal from the 5V TX. |
| 15 | +*MH-Tiny88 (5V)* | *Connection* | *ESP-M3 (3.3V)* |
| 16 | +TX (D1) | ───[ 1kΩ ]──┬── | RX |
| 17 | + | └─[ 2kΩ ]─┤ | GND |
| 18 | +RX (D0) | ────────────── | TX |
| 19 | +GND | ────────────── | GND (Common) |
18 | 20 |
|
19 | | -## 📂 Example Structure |
| 21 | +## 📂 Code Overview |
| 22 | +This example uses a manual check inside the `loop()` function: |
20 | 23 |
|
21 | | -*SharedData.h*: Defines the struct MyData used by both devices. *Must be identical on both sides*. |
22 | | -*Tiny88_Sensor.ino*: Collects "simulated" sensor data and sends it every 2 seconds. Uses a *callback* to handle incoming commands from the ESP. |
23 | | -*ESPM3_Bridge.ino*: Receives sensor data and immediately sends a command response back to the Tiny88. |
| 24 | +```cpp |
| 25 | +void loop() { |
| 26 | + link.update(); // Keep the engine running |
24 | 27 |
|
25 | | -## 🚀 How to Run |
| 28 | + if (link.available()) { |
| 29 | + const MyData& incoming = link.peek(); |
| 30 | + // Handle your data here... |
| 31 | + |
| 32 | + link.flush(); // Clear the flag to allow the next packet |
| 33 | + } |
| 34 | +} |
| 35 | +``` |
26 | 36 |
|
27 | | -Open Tiny88_Sensor.ino in the Arduino IDE and upload it to your *MH-Tiny88*. |
28 | | -Open ESPM3_Bridge.ino and upload it to your *ESP-M3*. |
29 | | -Open the Serial Monitor for the *ESP-M3* at *9600 Baud*. |
30 | | -You should see the incoming packets from the Tiny88 being displayed. |
| 37 | +- *`link.available()`*: Returns `true` only when a full, verified packet has arrived. |
| 38 | +- *`link.peek()`*: Provides a constant reference to the data without copying it, saving RAM. |
| 39 | +- *`link.flush()`*: Tells the library you have finished reading the data, allowing the hardware buffer to be parsed for the next packet. |
31 | 40 |
|
32 | | -## 📈 Features Demonstrated |
| 41 | +## 🚀 How to Run |
33 | 42 |
|
34 | | -*Asynchronous Callbacks*: Using link.onReceive() for non-blocking command handling. |
35 | | -*Telemetry*: Monitoring link.getStats() for CRC errors or timeouts. |
36 | | -*Safety*: Automatic buffer protection via COBS delimiting. |
| 43 | +Upload `Tiny88_Sensor.ino` to the *MH-Tiny88*. |
| 44 | +Upload `ESPM3_Bridge.ino` to the *ESP-M3*. |
| 45 | +Observe the interaction via the Serial Monitor. |
0 commit comments