Logging the Temperature
The way boot.py works is by checking to see if the pin you specified in the switch setup in your code is connected to a
ground pin. If it is, it changes the read-write state of the file system, so the CircuitPython core can begin logging the
temperature to the board.
For help finding the correct pins, see the wiring diagrams and information in the Find the Pins section of the
CircuitPython Digital In & Out guide (https://adafru.it/Bes). Instead of wiring up a switch, however, you'll be connecting
the pin directly to ground with alligator clips or jumper wires.
import time
import board
import digitalio
import microcontroller
led = digitalio.DigitalInOut(board.D13)
led.switch_to_output()
try:
with open("/temperature.txt", "a") as fp:
while True:
temp = microcontroller.cpu.temperature
# do the C-to-F conversion here if you would like
fp.write('{0:f}\n'.format(temp))
fp.flush()
led.value = not led.value
time.sleep(1)
except OSError as e:
delay = 0.5
if e.args[0] == 28:
delay = 0.25
while True:
led.value = not led.value
time.sleep(delay)