From 02aed60775cf88a6398b303d15ddb538127fd95c Mon Sep 17 00:00:00 2001 From: Aadi Desai <21363892+supleed2@users.noreply.github.com> Date: Tue, 1 Jun 2021 17:46:31 +0100 Subject: [PATCH] Add software serial library and demo Connect each TX/RX pair as loopback: results in message passing through both pairs of hardware and software UARTs and echoing back input to serial monitor --- Control/platformio.ini | 1 + Control/src/main.cpp | 54 ++++++++++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/Control/platformio.ini b/Control/platformio.ini index 88d8882..1f6cf0c 100644 --- a/Control/platformio.ini +++ b/Control/platformio.ini @@ -15,3 +15,4 @@ framework = arduino monitor_speed = 115200 upload_port = COM[3] monitor_filters = send_on_enter +lib_deps = plerup/EspSoftwareSerial@^6.12.6 diff --git a/Control/src/main.cpp b/Control/src/main.cpp index 847d03a..d3e85ef 100644 --- a/Control/src/main.cpp +++ b/Control/src/main.cpp @@ -1,33 +1,61 @@ #include #include +#include #define RX1pin 14 // Pin 10 on expansion board #define TX1pin 4 // Pin 11 on expansion board #define RX2pin 15 // Pin 12 on expansion board #define TX2pin 2 // Pin 13 on expansion board +#define RX3pin 18 // Pin 6 on expansion board +#define TX3pin 5 // Pin 7 on expansion board +#define RX4pin 17 // Pin 8 on expansion board +#define TX4pin 16 // Pin 9 on expansion board -void forwardprint(); +void forwardprint1() { + if(Serial1.available()){ + input1 = String(Serial1.readStringUntil('\n')); + Serial2.println(input1); + } +} +void forwardprint2() { + if(Serial2.available()){ + input2 = String(Serial2.readStringUntil('\n')); + Serial3.println(input2); + } +} +void forwardprint3() { + if(Serial3.available()){ + input3 = String(Serial3.readStringUntil('\n')); + Serial4.println(input3); + } +} +void forwardprint4() { + if(Serial4.available()){ + input4 = String(Serial4.readStringUntil('\n')); + Serial.println(input4); + } +} int counter; -String input1, input2; +String input, input1, input2, input3, input4; +SoftwareSerial Serial3; +SoftwareSerial Serial4; void setup() { Serial.begin(115200); // Set up hardware UART 0 (Connected to USB port) Serial1.begin(9600, SERIAL_8N1, RX1pin, TX1pin); // Set up hardware UART 1 Serial2.begin(9600, SERIAL_8N1, RX2pin, TX2pin); // Set up hardware UART 2 + Serial3.begin(9600, SWSERIAL_8N1, RX3pin, TX3pin); // Set up software UART 3 + Serial4.begin(9600, SWSERIAL_8N1, RX4pin, TX4pin); // Set up software UART 4 } void loop() { - forwardprint(); if(Serial.available()){ - input1 = String(Serial.readStringUntil('\n')); - Serial1.println(input1); + input = String(Serial.readStringUntil('\n')); + Serial1.println(input); } -} - -void forwardprint() { - if(Serial2.available()){ - input2 = String(Serial2.readStringUntil('\n')); - Serial.println(input2); - } -} + forwardprint1(); + forwardprint2(); + forwardprint3(); + forwardprint4(); +} \ No newline at end of file