I have an Arduino UNO connected to ESP32 through voltage divider with TX0 from Uno to RX2 to ESP32. My goal is to send data from my Uno to my ESP32 through HardwareSerial
. Here's my code for the Uno:
void setup() {
Serial.begin(9600);
}
void loop() {
int t = 100;
String myString = String(t);
Serial.println(t);
delay(5000);
}
Here I assign an int
to 100 and then cast it to String
so I can send it on my ESP32's side. My code for ESP32 is:
#define RXD2 16
#define TXD2 -1
HardwareSerial Serial2(1); // Use UART channel 1
void setup() {
Serial.begin(9600);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
}
void loop() {
if(Serial2.available() >= 1){
Serial.print("Data received:");
Serial.print(Serial2.readString());
}
}
The serial monitor on ESP's side is printing only "100" on every 5 seconds but if I disconnect the Uno from my Port, the ESP's monitor keeps printing "100" even tho it shouldn't.
However, IF I type Serial.println("100");
then I get "Data received: 100" on ESP's side and if I unplug the Uno, the ESP's monitor doesn't print anything or with other words it works properly. Is there a way I can fix this?
String
thing is irrelevant. You're not using it. You're printing the integer. Delete the string rubbish. – Majenko♦ Aug 25 '20 at 12:54String
thing, the ESP's side doesn't act properly and that's what I'm trying to fix. – anthino12 Aug 25 '20 at 13:00