Serial buffering Issue - Arduino Due

Hi guys,

I have been working on arduino for a while now. Currently, i am trying to integrate a wind sensor (LCJ CV7-v) to arduino due. I am using arduino IDE 1.6.5.
Details of wind sensor:

  • flux every 533 milliseconds
  • end of sentence is CR or LF
  • baud rate: 4800
    example output is as follows:

$WIXDR,C,024.0,C,54
$PLCJ,5AFF,63FF,AA,3434,4142
$PLCJE7DB8,73AE,3300,2162,64,
$IIMWV,316.0,R,000.0,N,A
39

Code that i am working on is attached in this post. Also attached is the sensor output that i am getting.
With the output that i get, it seems to me that somehow that bytes are getting dropped as the buffer becomes full.
I have tried to play around with the delay timings and it seems a delay of 533 millis works best.
I am not quite sure what’s going on though.
I referred to http://forum.arduino.cc/index.php?topic=58995.0 thread also, but it dint help my cause.

Please help me in this regard. :confused:
Thanks!

wind_sensor_driver.ino (1.4 KB)

wind_sensor_output.doc (37 KB)

What is your goal?

$WIXDR,C,024.0,C,,*54 => Weather Instrument,CrossTrackError–Dead Reckoning. ( 24.0 deg C)

$IIMWV,316.0,R,000.0,N,A*39 => Integrated Instrumentation,Wind Speed and Angle ( no wind direction 316 deg, R=relative to sensor, N=knots, A=valid data )

$PLCJ,5AFF,63FF,AA,3434,4142 and => Proprietary Code - check manual $PLCJE7DB8,73AE,3300,2162,64,

@knut_ny, Thanks for the reply.

Ultimately i want to extract the wind speed, angle and temp from the packet string in every 15 min interval. But even before that, i am making a check whether or not i am receiving correct data set every time, which unfortunately is not the case because of the bytes getting dropped after some time.

Output comes like this: (as in the attachment in my first post) $ WIXDR,C,024.0,C,,*54 $PLCJ,6AFF,5501,2C,3434,3333 $PLCJE7DB8,73AE,3300,2162,64, $IIMWV,271.0,R,000.0,N,A*39 $W IXDR,C,024.0,C,,*54 $PLCJ,6AFE,56FE,2C,3444,3433 $PLCJE7DB8,73AE,3300,2162,64, $IIMWV,316.0,R,000.0,N,A*39 $W IXDR,C,024.0,C,,*54 $PLCJ,6AFF,56FE,2C,3444,3433 $PLCJE7DB8,73AE,3300,2162,64, $IIMWV,137.0,R,000.0,N,A*38 $WI XDR,C,024.0,C,,*54 $PLCJ,5AFF,6300,AA,3434,4242 $PLCJE7DB8,73AE,3300,2162,64, $IIMWV,227.0,R,000.0,N,A*3A $WI XDR,C,024.0,C,,*54 $PLCJ,5AFE,63FF,AA,3334,4142 $PLCJE7DB8,73AE,3300,2162,64, $IIMWV,316.0,R,000.0,N,A*39 $WI XDR,C,024.0,C,,*54 $PLCJ,5AFF,63FF,AA,3334,4142 $PLCJE7DB8,73AE,3300,2162,64, $IIMWV,137.0,R,000.0,N,A*38 $WIX DR,C,024.0,C,,*54 $PLCJ,5AFF,63FE,AA,3434,4042 $PLCJE7DB8,73AE,3300,2162,64, $IIMWV,316.0,R,000.0,N,A*39 $WIX DR,C,024.0,C,,*54 $PLCJ,5A00,63FE,AA,3434,4042 $PLCJE7DB8,73AE,3300,2162,64, $IIMWV,316.0,R,000.0,N,A*39 $WIX DR,C,024.0,C,,*54 $PLCJ,5AFF,63FF,AA,3434,4142 $PLCJE7DB8,73AE,3300,2162,64, $IIMWV,271.0,R,000.0,N,A*39 $WIX DR,C,024.0,C,,*54 $PLCJ,6AFF,55FE,2C,3434,3333 $PLCJE7DB8,73AE,3300,2162,64, $IIMWV,316.0,R,000.0,N,A*39 $WIXD R,C,024.0,C,,*54 $PLCJ,6AFE,55FF,2C,3434,3433 $PLCJE7DB8,73AE,3300,2162,64, $IIMWV,271.0,R,000.0,N,A*39 $WIXD R,C,024.0,C,,*54 $PLCJ,6AFF,5500,2C,3434,3333 $PLCJE7DB8,73AE,3300,2162,64, $IIMWV,227.0,R,000.0,N,A*3A

Is this something to do with serial buffering? Although, buffer size i came to know is 128 bytes and this packet string is 113 bytes long. So overflow seems unlikely i believe. Please let me know if my understanding is correct. Much appreciated. Thanks!

samarth003: Hi guys,

I have been working on arduino for a while now. Currently, i am trying to integrate a wind sensor (LCJ CV7-v) to arduino due. I am using arduino IDE 1.6.5. Details of wind sensor: - flux every 533 milliseconds - end of sentence is CR or LF - baud rate: 4800 example output is as follows:

$WIXDR,C,024.0,C,,*54 $PLCJ,5AFF,63FF,AA,3434,4142 $PLCJE7DB8,73AE,3300,2162,64, $IIMWV,316.0,R,000.0,N,A*39

Code that i am working on is attached in this post. Also attached is the sensor output that i am getting. With the output that i get, it seems to me that somehow that bytes are getting dropped as the buffer becomes full. I have tried to play around with the delay timings and it seems a delay of 533 millis works best. I am not quite sure what's going on though. I referred to http://forum.arduino.cc/index.php?topic=58995.0 thread also, but it dint help my cause.

Please help me in this regard. :confused: Thanks!

Don't use delay. Just process the serial characters. Here is an example to echo serial from one port to the other in blocks.

/*
echo from Serial2.read to Serial.print by crlf or 114 char block

*/

void setup(){
Serial.begin(57600);
Serial2.begin(4800);
}

#define MAXBUFFER 128
char buffer[MAXBUFFER];
uint8_t pos=0;

void processSerial(){
char ch = Serial2.read();
if ((ch =='\n')||(ch=='\r')) {
   if(pos>0){ // don't send a blank line for each crlf element
     buffer[pos]= 0; // set end marker.
     Serial.println(buffer);
     pos=0;
     }
   }
else {
  buffer[pos++]=ch;
  }
if(pos>114){ // self imposed max length?
  buffer[pos]=0;
  Serial.println(buffer);
  pos=0;
  }
}

void loop(){
  if(Serial2.available()) processSerial();
  }

Chuck.