void read_dust() {
String readString;
while (Serial3.available())
{
// delay(10);
char c = Serial3.read(); //gets one byte from serial buffer
readString += c;} //makes the string readString
if (readString.length() >0)
{
Serial.print(readString);
}
}
void setup()
{
Serial3.begin(230400, SERIAL_7N1); // PM2.5 sensor,should use 203400, 8N1
Serial.begin(9600); // mega
}
void loop()
{
read_dust();
delay(1000);
Serial.println();
}
this PM2.5 sensor is my lab's partner's work, they advise monitor it with baud rate 230400,8N1.
I should test it and capture the tofloat data from mega for picturising with Meguno . While using USB connect the sensor to computer, terminal can show the complete string. But when using the above code with mega board, the string sending back will lost last few numbers.
how to restore this number lossing problem with mega?
-
use ttl to usb, data OK (complete string)
https://drive.google.com/file/d/1U-Cn7-nqBLqRnx0nrVFJ6_BbmEORTvp8/view -
use mega with above code, string lose some numbers
https://drive.google.com/file/d/16DsfzM997WjepP1ZLFCqL73dmnMUdCit/view
ps: If use Serial3.begin(230400, SERIAL_8N1); we get some number become garbled(revers question mark), so, after try and error, we use 7N1 (no garbled).