As the name implies, Time-based One Time Passwords rely on time. For any internet connected device, this can be done fairly easy using a NTP service. However, the MacroPad does not have any wifi capabilities, so can not readily connect to the internet. To get around this, we will use an external time source, a Real Time Clock (RTC) device, directly connected to the MacroPad.
An RTC has a battery backup to maintain time tracking even when the rest of the system is powered down.
Connecting RTC
In this guide we use a PCF8523 RTC breakout. But you can use any other I2C RTC breakout, as long as it has a CircuitPython driver library. Follow the assembly instructions in the PCF8523 guide to solder on the header pins.
Once the header pins are soldered on, use the STEMMA QT cable and connect:
- PCF8523 GND to STEMMA QT black cable
- PCF8523 VCC to STEMMA QT red cable
- PCF8523 SDA to STEMMA QT blue cable
- PCF8523 SCL to STEMMA QT yellow cable
The SQW pin does not need to be connected.
Setting the RTC
Use the rtc_setter.py code below and edit the time values to be something many seconds into the future. Edit these lines:
# values to set YEAR = 2021 MON = 1 DAY = 1 HOUR = 12 MIN = 23 SEC = 42
Copy the rtc_setter.py code to your CIRCUITPY folder. Then, connect to the CircuitPython REPL and run the code as follows:
import rtc_setter
It will show the time you set and wait until you press ENTER to actually set the time.
Now watch some other time source that is showing the current time. When the time you set arrives, press ENTER.
The RTC will now be set to that time. The code will loop forever showing the RTC time as a way to check that is actually set and working. You can press <CTRL><C> to break out of the code or just reset.
# SPDX-FileCopyrightText: 2021 Carter Nelson for Adafruit Industries # # SPDX-License-Identifier: MIT import time import board from adafruit_pcf8523.pcf8523 import PCF8523 i2c = board.I2C() # uses board.SCL and board.SDA # i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller pcf = PCF8523(i2c) # values to set YEAR = 2021 MON = 1 DAY = 1 HOUR = 12 MIN = 23 SEC = 42 print("Ready to set RTC to: {:4}/{:2}/{:2} {:2}:{:02}:{:02}".format(YEAR, MON, DAY, HOUR, MIN, SEC)) _ = input("Press ENTER to set.") pcf.datetime = time.struct_time((YEAR, MON, DAY, HOUR, MIN, SEC, 0, -1, -1)) print("SET!") while True: now = pcf.datetime print("{:4}/{:2}/{:2} {:2}:{:02}:{:02}".format(now.tm_year, now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec)) time.sleep(1)
Page last edited January 21, 2025
Text editor powered by tinymce.