<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MicroPython Clock Task with RTC and NTP sync]]></title><description><![CDATA[<p dir="auto">Just new to MicroPhyton, I just collected some code pieces in the web to get a "Clock" background task coded with RTC and NTP Sync by just some code lines.<br />
BTW. No flickering on the display etc.</p>
<p dir="auto">Please feel free to comment; need to learn ;-)</p>
<pre><code># RTC Clock with NTP Sync for M5STACK
# References:
# https://forum.micropython.org/viewtopic.php?t=4329
# Lobo Version to init RTC and timezone
# https://forum.micropython.org/viewtopic.php?f=18&amp;t=3553&amp;p=21616&amp;hilit=timezone#p21616
from m5stack import machine
from m5stack import lcd
from time import strftime
import utime
import _thread

# move to lowest line on M5STACK display
lcd.setCursor(0, 227)
lcd.setColor(lcd.WHITE)
lcd.print("RTC Clock 1")

# initiate rtc
rtc = machine.RTC()
print("Synchronize time from NTP server with TZ=Germany ...")
rtc.ntp_sync(server="hr.pool.ntp.org", tz="CET-1CEST,M3.5.0,M10.5.0/3")

def watch():
    while True:
        # start position for Date
        if not rtc.synced():                                                            # set color to sync status    
            lcd.setColor(lcd.RED)
        else: 
            lcd.setColor(lcd.GREEN)
#       lcd.setCursor(92, 227)                                                          # uncomment if you need date on display
#       lcd.print("Date {}".format(utime.strftime("%Y-%m-%d", utime.localtime())))      # uncomment if needed
        # start position for time only
        lcd.setCursor(213, 227)                                                         # uncomment if date active (see upper lines)
        lcd.print(" Time {}".format(utime.strftime('%H:%M:%S', utime.localtime())))
        utime.sleep(1)

_thread.start_new_thread ("clock",watch, ())
</code></pre>
]]></description><link>https://community.m5stack.com/topic/197/micropython-clock-task-with-rtc-and-ntp-sync</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 21:18:34 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/197.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 03 May 2018 14:26:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to MicroPython Clock Task with RTC and NTP sync on Sat, 04 Apr 2020 21:24:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/f3rn4nd0d" aria-label="Profile: f3rn4nd0d">@<bdi>f3rn4nd0d</bdi></a> I got "no module named 'wifisetup'" error, and without that, no 'strftime' in time... What am I missing in Mycropython for my M5Stack Gray?</p>
<p dir="auto">Thanks for your help.</p>
]]></description><link>https://community.m5stack.com/post/8015</link><guid isPermaLink="true">https://community.m5stack.com/post/8015</guid><dc:creator><![CDATA[kalon33]]></dc:creator><pubDate>Sat, 04 Apr 2020 21:24:25 GMT</pubDate></item><item><title><![CDATA[Reply to MicroPython Clock Task with RTC and NTP sync on Thu, 11 Apr 2019 08:37:10 GMT]]></title><description><![CDATA[<p dir="auto">Just a little comment. I've used this code to have a tiny watch on a M5stick and it did not work till I added the connection to internet. So the code in my case looks like this:</p>
<p dir="auto">import wifisetup<br />
wifisetup.auto_connect()<br />
from m5stack import *<br />
from m5ui import *<br />
...</p>
<p dir="auto">and then the rest of the code is similar, changing timezone and whatnot.</p>
<p dir="auto">Thanks for the code and best regards / Fernando</p>
]]></description><link>https://community.m5stack.com/post/3642</link><guid isPermaLink="true">https://community.m5stack.com/post/3642</guid><dc:creator><![CDATA[f3rn4nd0d]]></dc:creator><pubDate>Thu, 11 Apr 2019 08:37:10 GMT</pubDate></item><item><title><![CDATA[Reply to MicroPython Clock Task with RTC and NTP sync on Fri, 04 Jan 2019 19:20:55 GMT]]></title><description><![CDATA[<p dir="auto">yes, already answered, thanks to <a class="plugin-mentions-user plugin-mentions-a" href="/user/simm" aria-label="Profile: simm">@<bdi>simm</bdi></a></p>
]]></description><link>https://community.m5stack.com/post/2323</link><guid isPermaLink="true">https://community.m5stack.com/post/2323</guid><dc:creator><![CDATA[M5MPy]]></dc:creator><pubDate>Fri, 04 Jan 2019 19:20:55 GMT</pubDate></item><item><title><![CDATA[Reply to MicroPython Clock Task with RTC and NTP sync on Sat, 29 Dec 2018 20:34:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ithasu" aria-label="Profile: ithasu">@<bdi>ithasu</bdi></a>,</p>
<p dir="auto">check this link <a href="https://prom-electric.ru/media/uclibc-zoneinfo-list.txt" target="_blank" rel="noopener noreferrer nofollow ugc">uclibc timezone list</a></p>
]]></description><link>https://community.m5stack.com/post/2254</link><guid isPermaLink="true">https://community.m5stack.com/post/2254</guid><dc:creator><![CDATA[simm]]></dc:creator><pubDate>Sat, 29 Dec 2018 20:34:21 GMT</pubDate></item><item><title><![CDATA[Reply to MicroPython Clock Task with RTC and NTP sync on Sun, 23 Dec 2018 19:21:24 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for your example. Where did you found the tz argument ? I cannot find any exhausitive documentation on the function.</p>
]]></description><link>https://community.m5stack.com/post/2223</link><guid isPermaLink="true">https://community.m5stack.com/post/2223</guid><dc:creator><![CDATA[ItHasU]]></dc:creator><pubDate>Sun, 23 Dec 2018 19:21:24 GMT</pubDate></item></channel></rss>