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

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
ian_westbury
Posts: 4
Joined: Sat May 15, 2021 10:12 am

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

Post by ian_westbury » Sun Jul 11, 2021 3:02 pm

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?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

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

Post by Roberthh » Sun Jul 11, 2021 3:27 pm

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.

ian_westbury
Posts: 4
Joined: Sat May 15, 2021 10:12 am

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

Post by ian_westbury » Sun Jul 11, 2021 4:02 pm

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?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

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

Post by Roberthh » Sun Jul 11, 2021 4:06 pm

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.

fdufnews
Posts: 76
Joined: Mon Jul 25, 2016 11:31 am

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

Post by fdufnews » Sun Jul 11, 2021 4:31 pm

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.

User avatar
aivarannamaa
Posts: 171
Joined: Fri Sep 22, 2017 3:19 pm
Location: Estonia
Contact:

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

Post by aivarannamaa » Sun Jul 11, 2021 4:45 pm

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.
Aivar Annamaa
https://thonny.org

ian_westbury
Posts: 4
Joined: Sat May 15, 2021 10:12 am

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

Post by ian_westbury » Sun Aug 01, 2021 10:55 am

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?

User avatar
aivarannamaa
Posts: 171
Joined: Fri Sep 22, 2017 3:19 pm
Location: Estonia
Contact:

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

Post by aivarannamaa » Sun Aug 01, 2021 12:56 pm

It comes back on Sundays :)

I'll notify Raspberry's people about newer versions.
Aivar Annamaa
https://thonny.org

fdufnews
Posts: 76
Joined: Mon Jul 25, 2016 11:31 am

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

Post by fdufnews » Sun Aug 01, 2021 1:43 pm

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

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

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

Post by pythoncoder » Sun Aug 01, 2021 3:36 pm

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."
Peter Hinch
Index to my micropython libraries.

Post Reply