Page 1 of 2

AttributeError: 'RTC' object has no attribute 'init' WARNING: Could not sync device's clock: 'RTC' object has no attribu

Posted: Sun Jul 11, 2021 3:02 pm
by ian_westbury
I have been running my Pico in MicroPython v1.16 in Thonny on my Raspberry Pi 4.

I have an issue that started today where on powering up and connecting the Pico I get a Warning message.

Traceback (most recent call last):
File "<stdin>", line 10, in <module>
AttributeError: 'RTC' object has no attribute 'init'
WARNING: Could not sync device's clock: 'RTC' object has no attribute 'init'

I had a look through the MicroPython documentation on the stdin file but couldn't find this particular error. If I run a program it runs okay. But if I click on Stop/Restart backend, the error returns. I am just learning MicroPython so I am not trying to change Real Time Clocks, etc. just driving LCD's and stuff.

I have tried reloading the rp2-pico-20210618-v1.16.uf2 file and re-selecting Micropython (Raspberry Pi Pico) in Thonny but I get the same warning.

Does anybody know what causes this warning and how I can get rid of it?

Re: AttributeError: 'RTC' object has no attribute 'init' WARNING: Could not sync device's clock: 'RTC' object has no att

Posted: Sun Jul 11, 2021 3:27 pm
by Roberthh
use rtc.datetime(datetime_tuple) instead, like:

rtc.datetime((21,07,11,0, 17,26,0, 0))

note that the datetime tuple requires 8 entries.

Re: AttributeError: 'RTC' object has no attribute 'init' WARNING: Could not sync device's clock: 'RTC' object has no att

Posted: Sun Jul 11, 2021 4:02 pm
by ian_westbury
Hi

Thanks for the reply.

I think the problem is that I am not actually trying to set the RTC. This warning appears as soon as I initialise the Pico.

Where would I use the rtc.datetime(datetime_tuple)?

Why would this warning suddenly appear?

Re: AttributeError: 'RTC' object has no attribute 'init' WARNING: Could not sync device's clock: 'RTC' object has no att

Posted: Sun Jul 11, 2021 4:06 pm
by Roberthh
You use rtc.datetime(datetime_tuple) to set date / time, and rtc.datetime() git get date & time.
Somewhere in your code is a call to rtc.init() which you should remove.

Re: AttributeError: 'RTC' object has no attribute 'init' WARNING: Could not sync device's clock: 'RTC' object has no att

Posted: Sun Jul 11, 2021 4:31 pm
by fdufnews
Thonny try synchronizing the RTC when it connects to the Pico. To do this it sends a short piece of code to the Pico, the problem is probably there.
Maybe @aivarannamaa can confirm.

Re: AttributeError: 'RTC' object has no attribute 'init' WARNING: Could not sync device's clock: 'RTC' object has no att

Posted: Sun Jul 11, 2021 4:45 pm
by aivarannamaa
MicroPython 1.15 acccepted 7 for Sunday, when synchronizing RTC (which Thonny assumed up to 3.3.10), MicroPython 1.16 does not, therefore Thonny received error and tried alternative approach (some devices have RTC.init)

The solution is to upgrade Thonny to 3.3.11. If you can't (RPi-s apt repo doesn't have 3.3.11 yet), then ignore the message for now. Tomorrow it should work again.

Re: AttributeError: 'RTC' object has no attribute 'init' WARNING: Could not sync device's clock: 'RTC' object has no att

Posted: Sun Aug 01, 2021 10:55 am
by ian_westbury
Thanks @fdufnews and @aivarannamaa.

It dissappeared after a day or two but it comes back occasionally. I can see from the Thonny website that there are later versions than 3.3.10 available. Isn't it possible to download one of the packages for 3.3.13 from the Thonny website and install that on my RPi?

Re: AttributeError: 'RTC' object has no attribute 'init' WARNING: Could not sync device's clock: 'RTC' object has no att

Posted: Sun Aug 01, 2021 12:56 pm
by aivarannamaa
It comes back on Sundays :)

I'll notify Raspberry's people about newer versions.

Re: AttributeError: 'RTC' object has no attribute 'init' WARNING: Could not sync device's clock: 'RTC' object has no att

Posted: Sun Aug 01, 2021 1:43 pm
by fdufnews
Many possible solutions:
1) as Aivar suggested, switching to Thonny 3.3.11
2) taking on living with this error from time to time
3) taking a rest on sunday, so you 'll never encounter the problem

Re: AttributeError: 'RTC' object has no attribute 'init' WARNING: Could not sync device's clock: 'RTC' object has no att

Posted: Sun Aug 01, 2021 3:36 pm
by pythoncoder
fdufnews wrote:
Sun Aug 01, 2021 1:43 pm
...
3) taking a rest on sunday, so you 'll never encounter the problem
<chuckle> "On the seventh day He rested."