I have an Arduino Uno R4 wifi set up with four devices (passive buzzer, PIR, BMP280, RTC DS1307). I have some simple code to monitor data and print out on R4 matrix, and ping the buzzer etc, and it all works. Code works and is debugged.
However, the RTC (which seems to work fine, has battery and keeps the correct set time) intermittently returns 0:0:0 data where I print to the matrix. I have tried many things in troubleshooting, and found the following:
RTC itself seems to work fine, and sometimes the system displays the output time (which is correct).
Other devices work fine, including BMP280 which is also I2C.
Switched I2C wires and connections to Arduino with those for the BMP280 and problem still occurs.
I2C wires are short enough, standard Dupont wires.
Cycling power or resetting sometimes corrects issue, sometime not.
I can post the code although its quite long, is requested. It feels like this is come kind of I2C comms issue, but I really dont know. Initially when I observed the problem it seemed to be associated with switching power from USB 5 VDC to a 9 VDC wall wart power, but then it became clear it happens under all power conditions.
The problem is def intermittent, and I have exhausted all the ideas that Chat GPT could suggest.
Does anyone have any idea? Thanks, Steven Lightfoot
OK thank you. I am not a super sophisticated user, and for now have no idea how to set the I2C frequency, I am simply using RTC libraries and whatever they default to. Here is the relevant code:
Great question - I found the Uno R4 wifi RTC to wildly inaccurate, and I did try syncing with NTP but even that didnt work well, so I happened to have an RTC sd1307 lying around and decided to play with it.
Do you have a good experience with the on board Uno R4 wifi RTC?
I mainly use ESP32 boards. My current favourite is the thumbnail-sized XIAO ESP32C3. They keep time within one second within the default 3-hourly NTP update. Good enough for a clock. The ESP32 only needs one line of code in setup() to extract UTC and local time with automatic daylight savings. Not sure how to do that with an R4.
Leo..
OK thanks. Basically the R4 was sold as having a built in RTC. However, it does not have a separate resonator/crystal and while it does have a new RTC library and nice functions, it has terrible accuracy (like +1 min/hour) so its basically useless. I contacted Arduino and they know its an issue but I dont think its fixable without a hardware change. I have tried using millis() in my R3 to make an ersatz RTC and while its accuracy is better its also not great.
I just happened to get access to an Elegoo ds1307 Rev 3 RTC module so decided to see how it would work, and so far I am pleased EXCEPT from time to time I get all zeroes returned.
I am using the Adafruit RTClib.h and really it all works totally fine except for this intermittent problem. Yesterday with more noodling around its seems to me it might be related to the battery, so I removed it and will play around more without it. My multimeter is dead so I cant test the battery either, ugh.
I will keep playing around. If you have any other ideas, please do speak up! Steven Lightfoot
With more playing around, it seems more and more like the issue is related to the power supply, as the 'zeroes' problem definitely appears with the battery installed in the ds1307 and now also with using the power supply plug (with 9 VDC) but mostly doesnt appear when the Arduino is powered by USB.
Now I have done more testing and when I unplug and replug the other I2C device in the system (BMP280) it causes the RTC to read zeroes, its a direct correlation - and in some cases when I replug the BMP280 and the RTC again provides readings the readings indicate the RTC clock is still running. So it seems to me the the issue is really a communication issue of the RTC output on the comms lines when there are different original power supplies or even when the voltage from the +5VDC bus fluctuates slightly.
Can anyone comment more? The issue is now somewhat repeatable....
Subsequently during testing, I found that the code would not even recognize the ds1307 unit on I2C with the 'begin() command, and hence I have concluded there may be a defect in the unit, so I have discontinued testing until I can get a replacement for more troubsleshooting.