i'm having problems with the SoftwareSerial lib.
I need to communicate with an Arduino Leonardo 32u4 and an ESP32 via SOFTWARESERIAL. I'm cannot modify the ESP32 firmware, but it works fine. (It offers an "echo" service for testing, and with other components).
When I send a string from the Arduino to the ESP32 everything works fine.
Neither "echo" messages or other messages have arrived on my Arduino.
Of course I integrated a bidirectional level converter (3.3 to 5 volts) between ESP32 & Arduino.
For the moment i've reduced my code to:
#include <SoftwareSerial.h>
SoftwareSerial uart(10, 9);
void setup(){
Serial.begin(9600); // Serial-Monitor
uart.begin(1200); // yes, i am sure
}
void loop() {
int x = uart.read();
Serial.print(x); Serial.println(" ."); // Monitor: -1 .
delay(1000); // dont flood
uart.write(":-)"); // arrives at ESP32
//uart.write(x);
}
(the ESP32 shows the ':-)' and returns it, also tested with RasPIs, but the SerialMonitor on Arduino says always '-1 .')
After 2 bricked Leonardos i also tested some Adafruit Pro Micro Boards with the same issue.
Not the ESP32 is the problem, it is my sketch for the Arduino Leonardo (with 32u4).
The data did not arrive on the Arduino.
The source code from my first post runs on my Arduino - not the ESP32. The ESP32 only runs a different firmware with an echo server.
If the Arduino is sending some serial data to the ESP32 then everything is fine. But when the ESP32 sends serial data to my Arduino, nothing has arrived: 'SoftwareSerial.read ()' returns '-1'
Some background information:
The ESP32-firmware is an ready software and writes the protocol via UART (1200 baud). Now I have to replace the logging device with my Arduino. It should parse the log respond to special entries. For example, by starting my computer and sending an email.
Everything works fine, only the Arduinos does not received anything by UART.
I have also tested various Arduino Leonardos, Adafruit Pro Micro - no change at all
When I use my Raspberry Pi or BusPirate, the data from ESP32 arrive.
The firmware of this ESP32 also has a UART echo mode for testing. This echo mode replies to every message with the received message and shows the message on a display.
Klaus_K:
Why do you want to use Software Serial? Your ESP32 has hardware UARTs.
I am using the software Serial on the Arduino as the Arduino Hardware-Serial is used for testing/debugging by Arduino Studio "Serial Monitor" via USB connected to the PC
I do not have a Arduino Leonardo but the documentation, schematic and variant file suggest the Serial Monitor is connected directly to the Arduino via native USB. This means you should be able use the hardware UART for your connection to the ESP32. Because the name Serial is used for USB you need to use Serial1 for the UART. The pins are available at the J2 connector of your board.
You can find the files here:
Schematic as PDF under DOCUMENTATION
Header file for Leonardo with UART definitions (see end of file)