Serial issue/uploading problem

Hello

I've encounted a weird problem with Serial. I'm using a Pro clone, and programming it via a FTDI module. All has been fine up till now. But now I have a program that requires the arduino to send a Serial message back to the PC several times a second, and after about 200 times, i.e. after a few seconds, the Serial port becomes unresponsive and the program appears to hang. Then I can't even upload a sketch, not even the bare minimum. Switching USB sockets makes no difference. I get these error messages:

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM3
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xe7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xe7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xe7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xe7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xe7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xe7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xe7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xe7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xe7
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xe7

avrdude done.  Thank you.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

Nothing I can do will fix it, not even a brand new programming module. Same problem with a different PC. The strangest thing is that if I walk away for half an hour, it usually becomes responsive again, but then the same issue occurs.

I thought that because I had a biggish capacitor across the power supply that could be stopping the arduino from resetting, but I've removed that and the problem is still there.

As I say, I've been uploading and running sketches to this module for weeks without difficulty. What can have happened?

Possibly outside my league !

Did the COM port change?
How do you monitor the serial output?
What becomes unresponsive, the Pro (I assume Pro Mini) or the terminal program?

Please post your code, you might be flooding the serial port on the PC due to an error; at this moment we don't know how much "several times a second" is :wink:

OK, the sketch is posted below. It's not the most elegant piece of code, I was just trying something out. As you see, normally the message "nothing happened yet" should sent to the PC repeatedly until a button is pressed. Sometimes this happens for a few seconds - i.e. a get the message about 100 times - and then everything freezes. Sometimes it doesn't get this far, and nothing ever appears on the serial monitor.

After this, the Arduino remains unresponsive and won't upload further sketches

  • even if reset, powered down, and unplugged
  • even if moved to a different PC (so it doesn't seem to be anything to do with the PC ports)

The same thing happens when I use a different board and programmer so I don't think the board or connections are faulty. I've also tried different cables.

Then, I go away and do something else, come back after a couple of hours, and it's possible to upload a sketch again.

It's as if there's something in the sketch that disables the arduino for a while but this really does seem unlikely.

#include <avr/wdt.h>


const int buttonPin = 2;
int reading = 1;
int functionOption = 0;
int lastButtonState = HIGH;   // the previous reading from the input pin
int counter = 0;
int originalFunctionOption;
void setup()
{
  Serial.begin(9600);
  pinMode(2, INPUT_PULLUP);
  wdt_enable(WDTO_2S);
}

void loop()
{

  Serial.println("nothing happened yet");
  if (digitalRead (buttonPin) == LOW)
  {
    while (1)
    {
      originalFunctionOption = functionOption;
      counter++;
      reading = digitalRead(buttonPin);

      if (reading == LOW)
      {
        delay (200);
        if (reading == LOW) {
          functionOption++;
          if (functionOption > 7) functionOption = 0;
        }
      }
      if (functionOption != originalFunctionOption) {
        Serial.print ("functionOption = ");
        Serial.println(functionOption);
      }

      delay (50);
      if ( (functionOption == originalFunctionOption) && (counter > 100))
      {
        Serial.println("timed out");
        Serial.print ("functionOption = ");
        Serial.println(functionOption);

        wdt_reset();
      }
      if (functionOption != originalFunctionOption) counter = 0;

    }
  }
}

Looks like you might be the victim of the WDT bug. Is that 0.2 seconds? Or 2 seconds.

Can't remember the details, but I think that the boot loader does not disable the WDT and hence it keeps on firing while you're trying to start the upload.

Do some research.

You can try to keep the Arduino in reset till the IDE reports the memory usage and starts uploading; release the reset at that moment.

Ah, thanks I didn't know there was a WDT bug. It's meant to be 2 seconds. I'll look into it.