I'm using Arduino mini, since it doesn't have any UART port left. I thought to use SoftwareSerial, but it turned out not very good. Its making hardware serial to read bad data.
For example, if you upload the following code, and open the SerialMonitor and write any text longer than 4 characters, it will trim the middle text. Like 123456789, will only read 123789. But if I comment the line "mySerial.write(buffer2,toRead);" it works as expected. Is there anyway to fix this ?
#include <SoftwareSerial.h>
SoftwareSerial mySerial(5, 6); // RX, TX
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
mySerial.println("Hello, world?");
}
void loop() { // run over and over
//if (mySerial.available()) {
// Serial.write(mySerial.read());
// }
if (Serial.available()) {
int toRead = Serial.available();
byte buffer2[256];
Serial.readBytes(buffer2, toRead) ;
mySerial.write(buffer2,toRead);
Serial.write(buffer2,toRead);
}
}