Go Down

Topic: Serial.read for high data rate input (Read 1 time) previous topic - next topic


Apr 01, 2011, 12:28 am Last Edit: Apr 01, 2011, 12:31 am by andresp Reason: 1

I'm using an Arduino Mega 2560 to handle the data of a Sparkfun Razor 9DOF IMU, which is constantly sending the accelerometers, gyroscopes and magnetometers values through a Serial connection to the Arduino. However, I'm loosing several data when reading the raw output of the IMU in the Arduino. This only happens when I add more code besides the typical output of the Serial1 input. Seems like the Arduino doesn't have a consistent buffer system to temporarily store the data that is being received on the serial port when it is executing other code.

This produces the correct output:
Code: [Select]

if(Serial1.available() > 0)
 Serial.print(Serial1.read(), BYTE);

This (most of the times) doesn't produce the correct output:
Code: [Select]

if(Serial1.available() > 0) {
   char ch = Serial1.read();
   if (ch == '\n') {
     //some parser processing
     s = "";
   else s += ch;

I have created a workaround by flushing and discarding some characters in order to keep receiving valid data (correct sentences) but that significantly reduces the update rate of the IMU. Have you ever faced this problem before? and do you know any other solution for it?

Thanks in advance.


Don't print out the data you receive, this is robbing you of the time.


I need to print the data to the Serial port to monitor it (otherwise I wouldn't know whether it is working correctly or not). Even if it was not for monitoring purposes I would still need to print data to the Serial port (at basically the same data rate) because it is used in a Java application.



I think I will need to process the data in the Java application then. thanks anyway  ;)

Go Up