unsigned long m = 0;
int second = 1;
void setup() {
Serial.begin(115200);
}
void loop() {
m = micros();
if(m>second*1000000) {
Serial.println(m);
second++;
}
}
Results in being an entire second too slow after 15 minutes, at a insanely precise rate. Is this a problem with my specific unit? The issue even happens without doing serial prints, but I thought this was the simplest way to show the problem.
If it is an Arduino Uno or the like, that drift is expected.
The manufacturers use an inexpensive crystal or resonator for the main CPU clock, and not only is the frequency inaccurate, it is also strongly temperature-dependent.
Use a temperature compensated RTC, like the DS3231, for accurate timekeeping (if the module has a battery, even when the Arduino is powered down).
Can you show a photo of your board ? I think that the cheapest crystal is still better than a resonator. A cheap crystal might stop working with freezing temperatures (below 0°C). For a accurate timing, you need a board with a crystal and using millis() is easier.
It's a brand new Arduino Uno Rev3. Looking into it further I see someone saying that the crystal on the board is only for USB communication and the CPU uses a ceramic res. I cannot believe how much time I spent learning about timers on arduino for this project without anyone saying "oh yeah but they insanely inaccurate"
I understand that, sure. I'm not mad that it is this way, if I knew I wanted really accurate timing before I got to this point I would have done the research. But pretty much all forum posts and guides talk about micros() like it IS accurate down to 4μs. I just wish I found out sooner is all.