millis() problem with Adafruit 32u4 Basic Feather

Hello, I'm having some unexpected behaviour with the millis() function with the Adafruit 32u4 basic feather.

I'm using the following code based on the tutorials, as a test of this function:

const unsigned long interval = 5000;
unsigned long startMillis;
unsigned long currentMillis;

void setup() {
  while (!Serial){;}
  Serial.begin(9600);
  Serial.println("Millis Test");
  startMillis = millis();
} 

void loop() {
  currentMillis = millis();
  if (currentMillis - startMillis >= interval){
    Serial.print("Time ");
    Serial.println(currentMillis);
    startMillis = currentMillis;
    }
}

If my interval is less than 2000, I get the expected behaviour, i.e. the time gets printed out to the serial monitor. For anything greater than 2700 it prints out maybe once and then nothing else.

If I add a Serial print with a delay inside the loop() section, it works fine, but only if the print is there:

const unsigned long interval = 5000;
unsigned long startMillis;
unsigned long currentMillis;

void setup() {
  while (!Serial){;}
  Serial.begin(9600);
  Serial.println("Millis Test");
  startMillis = millis();
} 

void loop() {
  currentMillis = millis();
  if (currentMillis - startMillis >= interval){
    Serial.print("Time ");
    Serial.println(currentMillis);
    startMillis = currentMillis;
    }
  Serial.println("Pass");
  delay(1000);
}

I want to be able to have a long delay period (60sec) using millis() rather then using delay() as I plan to connect the 32u4 Feather to a GPS breakout.

I have also verified that the first code above works fine with an Uno, so its in some way specific to the 32u4 Feather.

Does anyone have any possible solutions?

I tried your first program on my Leonardo (which also uses the 32U4) and it works fine.

...R

Thanks for that.

Does that mean its a hardware issue with my board? I had thought it was a programming thing related to the Serial.print as the second code gives sort-of the expected behaviour...

clnbtlr:
Thanks for that.

Does that mean its a hardware issue with my board?

I have no idea. I don't have a board like yours.

...R

I ordered an Arduino Micro (which uses the same 32u4 chip as the feather) and tried my millis() code again.

I get the same behaviour as before - for an interval value >= 2700, nothing gets printed out to the Serial port.

However, as the Micro has a RX and TX LEDs, I can see some different behaviour that I couldn't before:

  • When the interval is <=2000, TX flashes, and output appears
  • When the interval is >2000 and <2700, RX randomly flashes, TX flashes, and sometimes there is output to serial, but not at the correct interval. Sometimes an interval will get skipped, or a few microseconds get added. This gets worse as the interval is increased closer to 2700.
  • When the interval is =>2700, RX turns on, TX LED flashes, then both turn off, but no serial output

Can anybody explain what's going on here?

I tried your first code as well on a Micro (actually a What's Next Pink) and it works as expected. Modified the interval (1500, 2200, 5000 (original)) and all behave correctly (expected times printed).

Which OS
Which IDE version
Which board manager version

//Edit
Using Windows 10, IDE 1.8.5 and Boards 1.6.21

Thanks, seems like its just me so.

OS: Ubuntu 16.04
IDE: 1.8.11
Boards manager: 1.8.2

Edit: I changed my boards manager to 1.6.21 and still get the same behaviour.

I tried your first code on a 32U4 Feather with a 5 second period and saw no issues

Millis Test
Time 8527
Time 13527
Time 18528
Time 23529
Time 28530

IDE 1.8.9
OS Windows 10
Boards Manager 1.4.12

I'm not certain what you are seeing for boards manager, as I don's see any version beyond 1.4.13

Adafruit AVR Boards by Adafruit version 1.4.12 installed
Boards in this package shows Adafruit Feather 32U4

I think that your Board Manager is for Arduino AVR boards. Look for the Adafruit version.

Yes, the board manager versions 1.8.2 and 1.6.21 mentioned are for the Arduino AVR for the Arduino Micro I tested earlier. My Adafruit AVR version is 1.4.13.

I have now tested my code on Windows 10 using the online IDE and it works as expected.

There must be something wrong with my IDE install on Ubuntu, so I'll try and reinstall and see if that works.

So I've uninstalled version 1.8.11 of the IDE and installed the latest 1.8.12 version on my Ubuntu 16.04 machine but the problem is still happening.

Current installed boards manager versions:

  • Arduino AVR: 1.8.2
  • Adafruit AVR: 1.4.13
    Any suggestions on what I can try to get this working in Ubuntu?

Have a look at this: https://www.arduino.cc/en/Serial.IfSerial.
You might be the only one that has the test for !Serial and the Serial.begin() in a different order. I don't understand that it worked with others, but at least fix it !

Sometimes a bad quality USB cable can cause a lot of trouble. For example when the voltage for the Arduino board is too low. Try another USB port on the computer with an other USB cable.

The problem might that the board is a "Adafruit" version. Adafruit and Sparkfun have sometimes a different bootloader and you should add the specific boards for those to the Arduino IDE.
You could also burn the Arduino bootloader on it, and use it as a Arduino board.
Did you add the additional boards as told here: Arduino IDE Setup | Adafruit Feather 32u4 Basic Proto | Adafruit Learning System.

Sometimes there are "Arduino IDE" on the internet that can be downloaded and they seem to work. Always use https://www.arduino.cc/en/Main/Software.

You could try it on an other computer, or clear everything in case some old things are left behind:

  • Keep your projects in /Arduino !
  • Check all your libraries in /Arduino/libraries
  • Remove the libraries that you have downloaded but don't use anymore. Remove the libraries that are already in the Arduino IDE.
  • Remove the Arduino IDE. Completely remove the folder that you have it installed in.
  • Check the repositories (I used synaptic when I was using Ubuntu), remove all Java and Arduino things.
  • Remove the hidden ~/.arduino15 folder.

Then download the newest Arduino IDE from arduino.cc and try again.

If that does not help, then burn a new bootloader in it.

If that does not help, buy new Arduino board.

If that does not help, show the full extended compiler and upload output.