mcopy/notes/nano_softserial/nano_softserial.ino

41 lines
848 B
Arduino
Raw Normal View History

2023-07-04 02:35:29 +00:00
#include <SoftwareSerial.h>
#define SOFTWARE_RX 10
#define SOFTWARE_TX 11
SoftwareSerial softPort(SOFTWARE_RX, SOFTWARE_TX);
volatile char proxy = 'z';
2023-07-04 21:15:26 +00:00
volatile char cmd = 'z';
2023-07-04 21:15:26 +00:00
2023-07-04 02:35:29 +00:00
void setup () {
Serial.begin(57600);
2023-07-04 21:15:26 +00:00
softPort.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
2023-07-04 02:35:29 +00:00
}
//////
// 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
//////
2023-07-04 02:35:29 +00:00
void loop () {
if (Serial.available() > 0) {
proxy = Serial.read();
softPort.print(proxy);
}
2023-07-04 02:35:29 +00:00
if (softPort.available() > 0) {
2023-07-04 21:15:26 +00:00
cmd = softPort.read();
}
if (cmd != 'z') {
Serial.println(cmd);
}
2023-07-04 21:15:26 +00:00
if (cmd == 'x') {
digitalWrite(LED_BUILTIN, HIGH);
}
cmd = 'z';
2023-07-04 02:35:29 +00:00
}