diff --git a/Drybox 2.0/boot.py b/Drybox 2.0/boot.py new file mode 100644 index 0000000..f8cb4c1 --- /dev/null +++ b/Drybox 2.0/boot.py @@ -0,0 +1,2 @@ +speed = str(round(machine.freq()/1000000,1)) +print("The starting speed is",speed,"MHz") \ No newline at end of file diff --git a/Drybox 2.0/dht.py b/Drybox 2.0/dht.py index 94204b0..59f1d11 100644 --- a/Drybox 2.0/dht.py +++ b/Drybox 2.0/dht.py @@ -2,8 +2,8 @@ import array import micropython import utime from machine import Pin -from micropython import const - +from micropython import const + class InvalidChecksum(Exception): pass diff --git a/Drybox 2.0/main.py b/Drybox 2.0/main.py new file mode 100644 index 0000000..67567bc --- /dev/null +++ b/Drybox 2.0/main.py @@ -0,0 +1,35 @@ +from machine import Pin, I2C +import utime as time +from dht import DHT11, InvalidChecksum +import gc + +gc.enable() + +#Initilialize data store +try: + f = open("data.csv","r") + f.close() + print("Found Datastore...") +except OSError: # open failed + print("Creating Datastore...") + f = open("data.csv","w") + f.write("id,temp,hum\n") + f.close() + print("Done") + + +#Main Program +while True: + #Measure DHT22 + print("Getting Sensor Values...") + time.sleep(5) + pin = Pin(28, Pin.OUT, Pin.PULL_DOWN) + sensor = DHT11(pin) + t = (sensor.temperature) + h = (sensor.humidity) + print("SensorID: 1, Temperature: {}°C, Humidity: {:.0f}%\nWriting...".format(sensor.temperature, sensor.humidity)) + f = open("data.csv","a") + f.write("1,"+str(t)+","+str(h)+"\n") + f.close() + print("Done") + gc.collect() \ No newline at end of file