Hello everyone, i am trying to communicate with another device using an Arduino Nano. I have connected the device to the software serial ports, and i use the hardware serial ports to print the output of the serial port. I use 115200 baudrate everywhere, i can read most of the output of the device correctly, but at points it prints something like that: " Creating 1 MTD partitions on "P⸮⸮MTS⸮⸮ՊT⸮⸮Uɥ⸮⸮⸮2⸮⸮͡⸮⸮j ". Any idea what could be causing that? Since it displays most of the output properly?
#include <SoftwareSerial.h>
SoftwareSerial mySerial(4, 5); // RX, TX
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
// set the data rate for the SoftwareSerial port
mySerial.begin(115200);
}
void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}
rozakos:
at points it prints something like that: " Creating 1 MTD partitions on "P⸮⸮MTS⸮⸮ՊT⸮⸮Uɥ⸮⸮⸮2⸮⸮͡⸮⸮j ". Any idea what could be causing that?
If the device name has Unicode characters and you are displaying them as ASCII, that could cause them to appear wrong. Serial.read() returns an int. Perhaps Serial.write() is sending both bytes of that int. Try casting the int to a char before writing it:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(4, 5); // RX, TX
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
// set the data rate for the SoftwareSerial port
mySerial.begin(115200);
}
void loop() { // run over and over
if (mySerial.available()) {
Serial.write((char)mySerial.read());
}
if (Serial.available()) {
mySerial.write((char)Serial.read());
}
}