Finding NMEA device connection fault [SOLVED]


I have a NMEA 0183 device (wind speed and direction sensor) connected to my Arduino UNO.
I use TinyGPS++ library to extract custom data sequence from NMEA stream.

Everything working great, but time to time this sensor halt and i need switch it off then on to restart.

How i can detect serial connection fault?

I use standard sequence

while (Serial.available() > 0)

I think - impossible to use Serial.available() to control serial fault because big part of time i have empty buffer (1 Hz data refreshing)

So, how i can control connection fault?

Thanks. Sorry my bad English.

If it continually sends data every second, everytime Serial.Available() returns zero, keep track of the time. If it goes more than 5-10 seconds without returning data, you know you have an issue.

I think this is a kludge, though. Find out why it needs to be reset and fix it at the source.

Find out why it needs to be reset and fix it at the source.

What is the wiring to the sensor like? How long? Check grounding, maybe add capacitor(s) from power to ground AT the sensor.

how i can track time?

I don't want to use any delay() in my system - so i don't know cycle time.

May be i can use timer for this?

I can find why wind sensor need to reset - this is prototype, not my development - and it is "black box" for me. My tasc

Short wiring i use- 1.5 meter long, screened, i have good power source and i check power with oscilloscope - no ripple found. So i think - this is inside of sensor.

You will need to change your program logic somewhat. At the very least, you need an else clause in your if loop.

Create an unsigned long variable (I will call it serTimeOut for this example.)
When you check Serial.Available()
if it is zero, save the value of the millis() counter in serTimeOut if serTimeOut is zero.
check to see if you timeout has been reached. IF so, reset the sensor.
if Serial.Available is not zero, set serTimeOut to zero.

Are you using the NMEA connections or the USB connection ? Do you have TTL-RS485 converters for the NMEA A & B signals ?

Read Reply#22 & 26 on the above post.
NMEA is RS485 , NOT TTL. You can't connect the A & B NMEA signals to TTL . You need a MAX485 IC to convert RS485 to TTL

Post the datasheet for you NMEA device or a photo of it taken with your cell phone that shows the phoenix connectors on it and
the label, particularly the ones that say XXa & XXb and post the photo and the datasheet or a link to the manual.

Thanks all!

So - this is part of my code:

void loop(){
if  (Serial.available()==0)

if (timeout>1500)
  flag=50;   //This is for sending over i2c

          for (byte i=0; i<10; i++){   //This is RESET sequence emulation
          digitalWrite(9, HIGH);
          digitalWrite(9, LOW);

/*Serial.print("timeout=");  // for control only
while (Serial.available() > 0){
    timeout =0;  


i use a little delay(300) in end of main loop - this is acceptable for my task and timeout variable not increased to fast.

Read Reply#5