code.py
 1  # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  """
 6  Data logging example for Pico. Logs the temperature to a file on the Pico.
 7  """
 8  import time
 9  import board
10  import digitalio
11  import microcontroller
12  
13  led = digitalio.DigitalInOut(board.LED)
14  led.switch_to_output()
15  
16  try:
17      with open("/temperature.txt", "a") as datalog:
18          while True:
19              temp = microcontroller.cpu.temperature
20              datalog.write('{0:f}\n'.format(temp))
21              datalog.flush()
22              led.value = not led.value
23              time.sleep(1)
24  except OSError as e:  # Typically when the filesystem isn't writeable...
25      delay = 0.5  # ...blink the LED every half second.
26      if e.args[0] == 28:  # If the filesystem is full...
27          delay = 0.25  # ...blink the LED faster!
28      while True:
29          led.value = not led.value
30          time.sleep(delay)