I tried to send serial from my esp32 to my mega. I connected from the esp32 rxp2 and tx2 to my mega rx2 and tx2. I know the serial works, but it also sends a lot of nulls and ⸮.
esp32 code:
#include "thingProperties.h"
#define RXp2 16
#define TXp2 17
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
Serial2.begin(115200, SERIAL_8N1, RXp2, TXp2);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
// for (int i =0; i<301; i++)
// {
// Serial2.print(i);
// Serial2.print("#");
// //Serial.println(Serial2.readString());
// Serial.print("sent packet ");Serial.println(i);
// delay(500);
// }
Serial2.write("test#");
Serial.println(temp);
delay(1000);
}
arduino code:
String message;
char character;
#define RXp2 16
#define TXp2 17
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial2.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial2.available() > 0){
character = Serial2.read();
if(character == '#'){
Serial.println(message);
message = "";
Serial.println();
}else{
message.concat(character);
}
}
}
What it prints out:
⸮⸮⸮⸮test
⸮p⸮test
⸮⸮⸮⸮⸮⸮⸮k[⸮۶⸮߯⸮⸮⸮⸮⸮<⸮test
⸮⸮test
⸮⸮⸮test
⸮⸮⸮test
Note: my esp32 code is on the arduino iot cloud.
The code works that it listen until # is sends and then print out the message