mirror of
https://github.com/supleed2/ELEC50003-P1-CW.git
synced 2024-11-10 01:35:50 +00:00
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
This commit is contained in:
parent
a00eb39ad1
commit
02aed60775
|
@ -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
|
||||
|
|
|
@ -1,33 +1,61 @@
|
|||
#include <Arduino.h>
|
||||
#include <string>
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
#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();
|
||||
}
|
Loading…
Reference in a new issue