Hi there,
Given,
Most Important:
– The standard Arduino SoftwareSerial library isn’t officially supported on ESP32. Instead, you’ll need a library designed for ESP32 (for example, ESPSoftwareSerial or an alternative).
– Be sure to install and include the appropriate software serial library for your ESP32-C3.
– Also note that not all pins on the ESP32-C3 can be used for software serial RX/TX. Check the documentation for your board and library to ensure the pins are supported.
– You must specify all settings (baud rate, data bits, stop bits) if the library supports that. In this example, we set the baud rate to 9600 for both software serial ports.
Yea, and the Examples are further down the list UNDER ESPSoftwareSerial.
This one works ,
// Tested with Xiao ESP32C3 BSP ver. 3.0.7
// SoftSerial Version 8.1.0
// Support for High Baud rate is Sketchy, Bigger recieve buffers are limited by RAM constraints on C3
// Roasted and Toasted by PJG
#include <Arduino.h>
#include <SoftwareSerial.h> // Use an ESP32-compatible SoftwareSerial library
// Define baud rate for the software serial ports.
#define SOFTSERIAL_BAUD 9600
// Define pins for the first software serial port: TX on pin 6, RX on pin 7.
#define SS1_TX 6
#define SS1_RX 7
// Define pins for the second software serial port: TX on pin 8, RX on pin 9.
#define SS2_TX 8
#define SS2_RX 9
// Create two instances of ESPSoftwareSerial.
// The constructor parameters are (RX, TX)
SoftwareSerial softSerial1(SS1_RX, SS1_TX);
SoftwareSerial softSerial2(SS2_RX, SS2_TX);
void setup() {
// Start hardware Serial (USB serial) at 115200 baud.
Serial.begin(115200);
delay (2000);
// ; // Wait for Serial connection
//}
Serial.println("Hardware Serial is ready.");
// Start the software serial ports.
softSerial1.begin(SOFTSERIAL_BAUD);
softSerial2.begin(SOFTSERIAL_BAUD);
Serial.println("Software Serial ports are ready.");
// (Optional) If your library supports additional configuration for data bits,
// stop bits, parity, etc., you can configure them here.
}
void loop() {
// If data is available on the hardware serial, read it and forward it
// to both software serial ports.
if (Serial.available()) {
String data = Serial.readStringUntil('\n');
Serial.print("Received on hardware serial: ");
Serial.println(data);
softSerial1.println(data);
softSerial2.println(data);
}
// If data is available on softSerial1, print it to hardware serial.
if (softSerial1.available()) {
String data = softSerial1.readStringUntil('\n');
Serial.print("Received on softSerial1: ");
Serial.println(data);
}
// If data is available on softSerial2, print it to hardware serial.
if (softSerial2.available()) {
String data = softSerial2.readStringUntil('\n');
Serial.print("Received on softSerial2: ");
Serial.println(data);
}
delay(10);
}
3 ports , note the baud rates.
HTH
GL PJ
BTW, The Library Info shows this as the example so stick close to that , you should be golden.
#include <SoftwareSerial.h>
#define MYPORT_TX 12
#define MYPORT_RX 13
EspSoftwareSerial::UART myPort;
[...]
Serial.begin(115200); // Standard hardware serial port
myPort.begin(38400, SWSERIAL_8N1, MYPORT_RX, MYPORT_TX, false);
if (!myPort) { // If the object did not initialize, then its configuration is invalid
Serial.println("Invalid EspSoftwareSerial pin configuration, check config");
while (1) { // Don't continue with invalid configuration
delay (1000);
}
}
[...]