Code - Micropython

The board shows up as a mass storage device when you connect it over USB. So we can write and modify our code without having to use a compiler.

Loading Firmware

Read Tony D's guide on how to use MicroPython with boards like the Feather M0

https://learn.adafruit.com/micropython-for-samd21/load-firmware

You'll also need the drivers for the RTC and OLED, download from the links below:

You can copy and paste the code below into the main.py file


To edit code, use your favorite text editor or our custom version of MU below:

Download: file
import busio
from board import *
import ssd1306
import urtc
import time

# With statement uses I2C interface as context manager for automatic init/deinit.
with busio.I2C(SCL, SDA) as i2c:
    rtc = urtc.PCF8523(i2c)
    oled = ssd1306.SSD1306_I2C(128, 32, i2c)

    #### WHEN RUNNING AT FIRST, UNCOMMENT TO SET TIME! ####
    #datetime = urtc.datetime_tuple(year=2016, month=11, day=12, hour=09, minute=40, second=50)
    #rtc.datetime(datetime)


    while True:
        datetime = rtc.datetime()
        print(datetime)
        oled.fill(0)

        hour = datetime.hour
        ampm = "AM"
        if (hour > 12):
          hour = hour - 12
          if (hour == 0):
              hour = 12
          ampm = "PM"
        oled.text(("%d:%02d:%02d "+ampm) % (hour, datetime.minute, datetime.second), 30, 0)
        oled.text("%d/%d/%d" % (datetime.month, datetime.day, datetime.year), 30, 8)
        oled.text('MicroPython Time', 0, 24)
        oled.show()

        time.sleep(1)
This guide was first published on Nov 23, 2016. It was last updated on Nov 23, 2016. This page (Code - Micropython) was last updated on Sep 21, 2019.