EasyManuals Logo

Adafruit Feather M4 Express User Manual

Adafruit Feather M4 Express
178 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #162 background imageLoading...
Page #162 background image
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)
© Adafruit Industries https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51 Page 167 of 183

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Adafruit Feather M4 Express and is the answer not in the manual?

Adafruit Feather M4 Express Specifications

General IconGeneral
BrandAdafruit
ModelFeather M4 Express
CategoryMicrocontrollers
LanguageEnglish

Related product manuals