From dd03583a279495e4c8831c269a9df6531f1f152e Mon Sep 17 00:00:00 2001 From: mattmcw Date: Tue, 4 Jul 2023 18:45:51 -0400 Subject: [PATCH] Proof of concept works. Nano can proxy requests to ESP32 via soft serial and then receives confirmation after event. Nano has a cleaner serial interface and will not throw junk into mcopy app serial listener. --- .gitignore | 4 +++- notes/esp32_serial/esp32_serial.ino | 3 ++- notes/nano_softserial/nano_softserial.ino | 26 ++++++++++++++++------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 6834386..6a38cd6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ node_modules dist -*.svd \ No newline at end of file +*.svd +*debug_custom.json +*debug.cfg \ No newline at end of file diff --git a/notes/esp32_serial/esp32_serial.ino b/notes/esp32_serial/esp32_serial.ino index 64757c7..c2a2b62 100644 --- a/notes/esp32_serial/esp32_serial.ino +++ b/notes/esp32_serial/esp32_serial.ino @@ -20,6 +20,7 @@ void loop () { } if (cmd == 'x') { - Serial2.print('x'); + Serial2.print(cmd); } + cmd = 'z'; } diff --git a/notes/nano_softserial/nano_softserial.ino b/notes/nano_softserial/nano_softserial.ino index a7840bf..6b4c59e 100644 --- a/notes/nano_softserial/nano_softserial.ino +++ b/notes/nano_softserial/nano_softserial.ino @@ -5,26 +5,36 @@ SoftwareSerial softPort(SOFTWARE_RX, SOFTWARE_TX); +volatile char proxy = 'z'; volatile char cmd = 'z'; -volatile long now; -volatile long start; + void setup () { + Serial.begin(57600); softPort.begin(9600); - start = millis(); pinMode(LED_BUILTIN, OUTPUT); } - +////// +// Sending an x character to the nano over +// Serial will proxy it to the ESP32 over SoftSerial +// which will reflect it back to the Nano +// and will turn on the built-in LED. Proof of +// concept round trip +////// void loop () { - now = millis(); + if (Serial.available() > 0) { + proxy = Serial.read(); + softPort.print(proxy); + } if (softPort.available() > 0) { cmd = softPort.read(); } + if (cmd != 'z') { + Serial.println(cmd); + } if (cmd == 'x') { digitalWrite(LED_BUILTIN, HIGH); } - if (now >= start + 5000) { - softPort.print('x'); - } + cmd = 'z'; }