Datasheet
file temperature.txt
The key part of this demo is in these lines:
This is a slightly complex demo but it's for a good reason. We use with (a 'context') to open the file for appending, that
way the file is only opened for the very short time its written to. This is safer because then if the SD card is removed or
the board turned off, all the data will be safe(r).
We use the LED to let the person using this know that the temperature is being written, it turns on just before the write
and then off right after.
After the LED is turned off the with ends and the context closes, the file is safely stored.
print("Logging temperature to filesystem")
# append to the file!
while True:
# open file for append
with open("/sd/temperature.txt", "a") as f:
led.value = True # turn on LED to indicate we're writing to the file
t = microcontroller.cpu.temperature
print("Temperature = %0.1f" % t)
f.write("%0.1f\n" % t)
led.value = False # turn off LED to indicate we're done
# file is saved
time.sleep(1)
© Adafruit Industries https://learn.adafruit.com/adafruit-adalogger-featherwing Page 34 of 36