Adding and updating data logging examples.

This commit is contained in:
Kattni Rembor 2021-02-10 17:56:43 -05:00
parent dc466bca6d
commit a54164c893
3 changed files with 44 additions and 4 deletions

View file

@ -19,10 +19,10 @@ try:
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
except OSError as e: # Typically when the filesystem isn't writeable...
delay = 0.5 # ...blink the LED every half second.
if e.args[0] == 28: # If the file system is full...
delay = 0.25 # ...blink the LED faster!
while True:
led.value = not led.value
time.sleep(delay)

View file

@ -0,0 +1,26 @@
"""
Data logging example for Pico. Logs the temperature to a file on the Pico.
"""
import time
import board
import digitalio
import microcontroller
led = digitalio.DigitalInOut(board.LED)
led.switch_to_output()
try:
with open("/temperature.txt", "a") as datalog:
while True:
temp = microcontroller.cpu[0].temperature
datalog.write('{0:f}\n'.format(temp))
datalog.flush()
led.value = not led.value
time.sleep(1)
except OSError as e: # Typically when the filesystem isn't writeable...
delay = 0.5 # ...blink the LED every half second.
if e.args[0] == 28: # If the filesystem is full...
delay = 0.25 # ...blink the LED faster!
while True:
led.value = not led.value
time.sleep(delay)

View file

@ -0,0 +1,14 @@
"""
boot.py file for Pico data logging example. If pin GP0 is connected to GND when
the pico starts up, make the filesystem writeable by CircuitPython.
"""
import board
import digitalio
import storage
write_pin = digitalio.DigitalInOut(board.GP0)
write_pin.direction = digitalio.Direction.INPUT
write_pin.pull = digitalio.Pull.UP
# If the write pin is connected to ground, CircuitPython can write to the CIRCUITPY filesystem.
storage.remount("/", write_pin.value)