Setting the time on the Tildagon


I'm beginning my adventures in MicroPython in the hope that I'll have something interesting working on the Tildagon Badge for EMF2026. Here's a basic implementation of a clockface.

Here's how to set the time on the badge. There's a hardware clock which should keep time between reboots.

  1. Install mpremote on your computer.
  2. Connect the Tildagon to your computer using a USB-C data cable
  3. On your computer's command line, run mpremote. You should see: > Connected to MicroPython at /dev/ttyACM0 > Use Ctrl-] or Ctrl-x to exit this shell
  4. Hold down the ctrl key on your computer. While holding it down, press the C key on your computer. This will open up a shell for you to enter commands.
  5. Enter the following commands one at a time, followed by enter
Python 3 Python 3from machine import RTC
rtc = RTC()
rtc.datetime()

That will display the time that the badge currently thinks it is.

For example: (2000, 1, 1, 5, 0, 1, 47, 984022)

This is a slightly unusual format. It is: year, month, day, weekday, hours, minutes, seconds, subseconds.

The "weekday" is 0 for Monday, 1 for Tuesday etc.

This is an array. So, to access individual elements of the time, you can say:

Python 3 Python 3year = rtc.datetime()[0]

Alternatively, you can do:

Python 3 Python 3import time
time.localtime()

That will return something like: (2024, 6, 11, 15, 11, 39, 1, 163)

Which, according to the documentation, is "year, month, mday, hour, minute, second, weekday, yearday".

Setting the clock

To manually set the date and time, run:

Python 3 Python 3rtc.datetime((2023, 6, 16, 1, 15, 36, 0, 0))

NTP

If you want to use NTP to synchronise the time with an Internet-based atomic clock, here's what you need to do.

  1. Connect your badge to WiFi.
  2. As above, connect with USB and run mpremote, then obtain a shell.
  3. Enter the following commands one at a time, followed by enter:
Python 3 Python 3import ntptime
ntptime.settime()
rtc.datetime()

That will now show you the synchronised time. Note, it will be set to UTC. There's no way to set the timezone - you'll have to deal with that in your code elsewhere.

You can also read the reference documentation about the Real Time Clock.


Share this post on…

  • Mastodon
  • Facebook
  • LinkedIn
  • BlueSky
  • Threads
  • Reddit
  • HackerNews
  • Lobsters
  • WhatsApp
  • Telegram

One thought on “Setting the time on the Tildagon”

What are your reckons?

All comments are moderated and may not be published immediately. Your email address will not be published.

Allowed HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <p> <pre> <br> <img src="" alt="" title="" srcset="">