From 63b3255f4209cbb671cafec92b190e5adc123fcc Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 10 Jan 2019 18:05:01 -0500 Subject: [PATCH] Adding GCM4 SD demo. --- .../GCM4_SD_Temperature_Logging_Demo.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 Adafruit_Grand_Central_M4_Express/GCM4_SD_Temperature_Logging_Demo.py diff --git a/Adafruit_Grand_Central_M4_Express/GCM4_SD_Temperature_Logging_Demo.py b/Adafruit_Grand_Central_M4_Express/GCM4_SD_Temperature_Logging_Demo.py new file mode 100755 index 00000000..9a890a14 --- /dev/null +++ b/Adafruit_Grand_Central_M4_Express/GCM4_SD_Temperature_Logging_Demo.py @@ -0,0 +1,31 @@ +import time +import adafruit_sdcard +import microcontroller +import board +import busio +import digitalio +import storage + +# Setup the little red LED on D13 +led = digitalio.DigitalInOut(board.D13) +led.direction = digitalio.Direction.OUTPUT + +# Connect to the card and mount the filesystem. +spi = busio.SPI(board.SD_SCK, board.SD_MOSI, board.SD_MISO) +cs = digitalio.DigitalInOut(board.SD_CS) +sdcard = adafruit_sdcard.SDCard(spi, cs) +vfs = storage.VfsFat(sdcard) +storage.mount(vfs, "/sd") + +print("Logging temperature to SD card") +# We're going to append to the file +while True: + # Open file for append + with open("/sd/temperature.txt", "a") as file: + led.value = True # Turn on LED to indicate we're writing to the file + temperature = microcontroller.cpu.temperature + print("Temperature = %0.1f" % temperature) + file.write("%0.1f\n" % temperature) + led.value = False # Turn off LED to indicate we're done + # File is saved + time.sleep(1)