SoftwareSerial Causing bad reading ?
i'm using arduino mini, since doesn't have uart port left. thought use softwareserial, turned out not good. making hardware serial read bad data.
for example, if upload following code, , open serialmonitor , write text longer 4 characters, trim middle text. 123456789, read 123789. if comment line "myserial.write(buffer2,toread);" works expected. there anyway fix ?
for example, if upload following code, , open serialmonitor , write text longer 4 characters, trim middle text. 123456789, read 123789. if comment line "myserial.write(buffer2,toread);" works expected. there anyway fix ?
code: [select]
#include <softwareserial.h>
softwareserial myserial(5, 6); // rx, tx
void setup() {
// open serial communications , wait port open:
serial.begin(57600);
while (!serial) {
; // wait serial port connect. needed native usb port only
}
// set data rate softwareserial port
myserial.begin(9600);
myserial.println("hello, world?");
}
void loop() { // run on , 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);
}
}
softwareserial disables interrupts entire time transmitting each character. this means transmitting 1 character myserial.write preventing serial saving 57600/9600, or 6 characters. the uart can buffer 2 of them before serial gets them, explains 4 lost chars.
the best way have second serial port altsoftserial on pins 8 & 9.
next best neoswserial on other pins, @ bauds 9600, 19200 , 38400.
worst softwareserial.
cheers,
/dev
the best way have second serial port altsoftserial on pins 8 & 9.
next best neoswserial on other pins, @ bauds 9600, 19200 , 38400.
worst softwareserial.
cheers,
/dev
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > SoftwareSerial Causing bad reading ?
arduino
Comments
Post a Comment