Skip to content

Instantly share code, notes, and snippets.

@waldo323
Last active April 6, 2018 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waldo323/a5763841edb6119b3effa34d37558734 to your computer and use it in GitHub Desktop.
Save waldo323/a5763841edb6119b3effa34d37558734 to your computer and use it in GitHub Desktop.
import board
import busio
import adafruit_pcf8523
import time
import digitalio
import adafruit_sdcard
import storage
myI2C = busio.I2C(board.SCL, board.SDA)
rtc = adafruit_pcf8523.PCF8523(myI2C)
days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
# Use board.SD_CS for Feather M0 Adalogger
cs = digitalio.DigitalInOut(board.D10)
# Or use a GPIO pin like 15 for ESP8266 wiring:
#cs = digitalio.DigitalInOut(board.GPIO15)
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
with open("/sd/test.txt", "w") as f:
f.write("Hello world!\r\n")
t = rtc.datetime
#print(t) # uncomment for debugging
f.write("The date is %s %d/%d/%d\r\n" % (days[t.tm_wday], t.tm_mday, t.tm_mon, t.tm_year))
f.write("The time is %d:%02d:%02d\r\n" % (t.tm_hour, t.tm_min, t.tm_sec))
# time.sleep(1) # wait a second
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment