From 27a6bef84d7a22421a8f8e719f387addfe80f42f Mon Sep 17 00:00:00 2001 From: sickprodigy Date: Sun, 10 Dec 2023 17:45:36 -0500 Subject: [PATCH] Script to log data and time accurately, may be a problem, but we do have the W, so maybe we can update wirelessly. --- Scripts/Log-Date-and-Time.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Scripts/Log-Date-and-Time.py diff --git a/Scripts/Log-Date-and-Time.py b/Scripts/Log-Date-and-Time.py new file mode 100644 index 0000000..3285fa5 --- /dev/null +++ b/Scripts/Log-Date-and-Time.py @@ -0,0 +1,34 @@ +import machine +import utime + +sensor_temp = machine.ADC(machine.ADC.CORE_TEMP) +conversion_factor = 3.3 / (65535) + +led_onboard = machine.Pin(25, machine.Pin.OUT) +led_onboard.value(0) + +rtc=machine.RTC() + +file = open("temps.txt", "w") +#file = open("temps.txt", "a") # To append to log file rather than overwrite + +while True: + reading = sensor_temp.read_u16() * conversion_factor + timestamp=rtc.datetime() + temperature = 27 - (reading - 0.706)/0.001721 + + timestring="%04d-%02d-%02d %02d:%02d:%02d"%(timestamp[0:3] + + timestamp[4:7]) + file.write(timestring + "," + str(temperature) + "\n") + file.flush() + led_onboard.value(1) + utime.sleep(0.01) + led_onboard.value(0) + + utime.sleep(30) + +# Notes +# Given that space is at a premium when writing logs to files on the +# internal Flash, one option may be produce timestamps and then deltas or +# changes after that, forcing a full timestamp every so often to ensure +# things are synchronised