Adding and updating data logging examples.
This commit is contained in:
parent
dc466bca6d
commit
a54164c893
3 changed files with 44 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
26
Getting_Started_With_Raspberry_Pi_Pico/data_logger.py
Normal file
26
Getting_Started_With_Raspberry_Pi_Pico/data_logger.py
Normal 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)
|
||||
14
Getting_Started_With_Raspberry_Pi_Pico/data_logger_boot.py
Normal file
14
Getting_Started_With_Raspberry_Pi_Pico/data_logger_boot.py
Normal 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)
|
||||
Loading…
Reference in a new issue