Hi, I'm was trying to use millis function in a project and realised that maybe there's a problem with my Arduino UNO internal clock, so I simply ran a basic code to print millis and what I've got at the serial monitor was a countdown from around 400 to 250 and then it stucked between 255 and 248...
septillion:
You said internal clock, that's not standard. To what did you set it and can that handle 115200 baud?
I don't quite understand what you mean by "not standard", sorry I'm a begginer here jeje. But I'm using Arduino UNO R3, and previously tried with 9600 baud.
Well, thing is that I still get the same results, even with the 1000 ms delay after println... I'm no expert but a simple begginer, but I believe that it's an issue with my board, maybe the internal clock. Is that possible? If so, I should try with another one, right?
erictissembaum:
Well, thing is that I still get the same results, even with the 1000 ms delay after println... I'm no expert but a simple begginer, but I believe that it's an issue with my board, maybe the internal clock.
Try again with the screenshot, you have the serial monitor set to 9600 baud, but the sketch is using 115200. Also, you compiled the sketch, but did not upload to the arduino.
The only thing I can think of that would cause an odd output like that would be if someone were altering the code for the millis() function in the Arudino.h file, the oscillator itself can't be off very far if the serial port is still working.
The MilliSecondUpCounter of my Arduino UNO is counting up the millis at 1-ms interval very nicely.
unsigned long prMilli = 0;
unsigned long n = 0;
void setup()
{
Serial.begin(2000000); //takes 0.02 ms time to send a 4-digit message to Serial Monitor
}
void loop()
{
Serial.println(n);
prMilli = millis();
while (millis() - prMilli < 1)
{
;
}
n = n + 1;
}