From bcf6ba58139197eaaba05abcdbf147ea68f57f9a Mon Sep 17 00:00:00 2001 From: ladyada Date: Fri, 29 Sep 2017 00:06:25 -0400 Subject: [PATCH] logger demo --- Introducing_Gemma_M0/Gemma_Logger.py | 24 +++++++++++++++++++++++ Introducing_Gemma_M0/Gemma_Logger_boot.py | 11 +++++++++++ 2 files changed, 35 insertions(+) create mode 100644 Introducing_Gemma_M0/Gemma_Logger.py create mode 100644 Introducing_Gemma_M0/Gemma_Logger_boot.py diff --git a/Introducing_Gemma_M0/Gemma_Logger.py b/Introducing_Gemma_M0/Gemma_Logger.py new file mode 100644 index 000000000..a8fa70889 --- /dev/null +++ b/Introducing_Gemma_M0/Gemma_Logger.py @@ -0,0 +1,24 @@ +import board +import digitalio +import microcontroller +import time + +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) diff --git a/Introducing_Gemma_M0/Gemma_Logger_boot.py b/Introducing_Gemma_M0/Gemma_Logger_boot.py new file mode 100644 index 000000000..13082b5b2 --- /dev/null +++ b/Introducing_Gemma_M0/Gemma_Logger_boot.py @@ -0,0 +1,11 @@ +import digitalio +import board +import storage + +switch = digitalio.DigitalInOut(board.D0) +switch.direction = digitalio.Direction.INPUT +switch.pull = digitalio.Pull.UP + +# If the D0 is connected to ground with a wire +# CircuitPython can write to the drive +storage.remount("/", switch.value)