Logging temperature to SD card

Did you know your CircuitPython-compatible microcontroller probably has a thermometer inside?  It does!  microcontroller.cpu.temperature reflects the temperature inside the microcontroller itself, which will frequently be 3-4 degrees C above the ambient temperature.  Note that temperatures are reported in Celsius, not Fahrenheit.

This is a great example to extend with the sensor(s) of your choice, as well as with a Real Time Clock (RTC) so that you know the time that each reading was recorded.  We chose the internal temperature to make this work with a wide range of boards, as long you've configured mount_sd.py!

import time

import board
import digitalio
import microcontroller
import mount_sd

led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT

# Use the filesystem as normal! Our files are under /sd

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)

Adalogger FeatherWing - RTC + SD Add-on For All Feather Boards

PRODUCT ID: 2922
A Feather board without ambition is a Feather board without FeatherWings! This is the Adalogger FeatherWing: it adds both a battery-backed Real Time Clock and micro SD...
OUT OF STOCK

Adafruit Feather nRF52840 Sense

PRODUCT ID: 4516
The Adafruit Feather Bluefruit Sense takes our popular Feather nRF52840 Express and adds a smorgasbord of sensors...
OUT OF STOCK
This guide was first published on Jul 31, 2020. It was last updated on 2020-07-31 12:38:51 -0400.
This page (Logging temperature to SD card) was last updated on Aug 05, 2020.