Button A re-activates the display
Button B turns the LEDS on for two mins (they fade) Always get a red LED 1 flash when a data point is logged.
This commit is contained in:
parent
135fb1e730
commit
451e61057a
84
main.py
84
main.py
@ -1,16 +1,32 @@
|
|||||||
# A weather station program display the date, time, temperature and humidity on the OLED screen with Air Quality and eCO2 on ZIP LEDs (Red/Green)
|
# A weather station program display the date, time, temperature and humidity on the OLED screen with Air Quality and eCO2 on ZIP LEDs (Red/Green)
|
||||||
from PicoAirQuality import KitronikBME688, KitronikDataLogger, KitronikOLED, KitronikRTC, KitronikZIPLEDs
|
from PicoAirQuality import KitronikBME688, KitronikDataLogger, KitronikButton, KitronikOLED, KitronikRTC, KitronikZIPLEDs
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logFileName = "atmosphere_log.txt"
|
logFileName = "atmosphere_log.txt"
|
||||||
|
|
||||||
|
buttons = KitronikButton()
|
||||||
|
|
||||||
|
def ButtonA_IRQHandler(pin):
|
||||||
|
global buttonA
|
||||||
|
buttonA = 30
|
||||||
|
print("button A pressed", buttonA)
|
||||||
|
|
||||||
|
# LEDS ON FOR 2 MINS 10% brightness
|
||||||
|
def ButtonB_IRQHandler(pin):
|
||||||
|
global buttonB
|
||||||
|
buttonB = 2*60
|
||||||
|
print("button B pressed", buttonB)
|
||||||
|
|
||||||
|
buttons.buttonA.irq(trigger=machine.Pin.IRQ_RISING, handler=ButtonA_IRQHandler)
|
||||||
|
buttons.buttonB.irq(trigger=machine.Pin.IRQ_RISING, handler=ButtonB_IRQHandler)
|
||||||
|
|
||||||
bme688 = KitronikBME688()
|
bme688 = KitronikBME688()
|
||||||
oled = KitronikOLED()
|
oled = KitronikOLED()
|
||||||
rtc = KitronikRTC()
|
rtc = KitronikRTC()
|
||||||
zipleds = KitronikZIPLEDs(3)
|
zipleds = KitronikZIPLEDs(3)
|
||||||
# Python u arse hole sec = Integer()
|
|
||||||
#rtc.setDate(07, 4, 2022)
|
#rtc.setDate(07, 4, 2022)
|
||||||
#rtc.setTime(21, 58, 0)
|
#rtc.setTime(21, 58, 0)
|
||||||
|
|
||||||
@ -21,7 +37,7 @@ sec = 0
|
|||||||
#f.write("# Data Logging: Date, Time, Temperature, Pressure, Humidity, AirQuality, CO2\n")
|
#f.write("# Data Logging: Date, Time, Temperature, Pressure, Humidity, AirQuality, CO2\n")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
#global buttonA, buttonB
|
||||||
if sec == 0:
|
if sec == 0:
|
||||||
f = open(logFileName, 'a+')
|
f = open(logFileName, 'a+')
|
||||||
f.write("# Data Logging: Date, Time, Temperature, Pressure, Humidity, AirQuality, CO2\n")
|
f.write("# Data Logging: Date, Time, Temperature, Pressure, Humidity, AirQuality, CO2\n")
|
||||||
@ -30,20 +46,31 @@ while True:
|
|||||||
bme688.measureData()
|
bme688.measureData()
|
||||||
oled.clear()
|
oled.clear()
|
||||||
|
|
||||||
#oled.drawRect(4, 5, 120, 35)
|
try:
|
||||||
oled.displayText(rtc.readDateString(), 1, 25)
|
_ = buttonA
|
||||||
oled.displayText(rtc.readTimeString(), 2, 33)
|
except NameError:
|
||||||
#oled.drawLine(0, 48, 127, 48)
|
buttonA = 30
|
||||||
#oled.drawLine(0, 49, 127, 49)
|
|
||||||
oled.displayText(str(bme688.readTemperature()) + " oC", 3, 0)
|
if buttonA > 0:
|
||||||
oled.displayText(str(bme688.readHumidity()) + " %H", 3, 80)
|
oled.poweron()
|
||||||
eCO2 = bme688.readeCO2()
|
#oled.drawRect(4, 5, 120, 35)
|
||||||
oled.displayText(str(eCO2) + " CO2 ppm", 4, 0)
|
oled.displayText(rtc.readDateString(), 1, 25)
|
||||||
IAQ = bme688.getAirQualityScore()
|
oled.displayText(rtc.readTimeString(), 2, 33)
|
||||||
oled.displayText(str(IAQ) + " AQ ", 5, 0)
|
#oled.drawLine(0, 48, 127, 48)
|
||||||
mbar = bme688.readPressure()/100.0
|
#oled.drawLine(0, 49, 127, 49)
|
||||||
oled.displayText(str(mbar) + " mB ", 5, 50)
|
oled.displayText(str(bme688.readTemperature()) + " oC", 3, 0)
|
||||||
oled.show()
|
oled.displayText(str(bme688.readHumidity()) + " %H", 3, 80)
|
||||||
|
eCO2 = bme688.readeCO2()
|
||||||
|
oled.displayText(str(eCO2) + " CO2 ppm", 4, 0)
|
||||||
|
IAQ = bme688.getAirQualityScore()
|
||||||
|
oled.displayText(str(IAQ) + " AQ ", 5, 0)
|
||||||
|
mbar = bme688.readPressure()/100.0
|
||||||
|
oled.displayText(str(mbar) + " mB ", 5, 50)
|
||||||
|
oled.show()
|
||||||
|
buttonA = buttonA - 1
|
||||||
|
else:
|
||||||
|
oled.poweroff() # would really like to turn it off
|
||||||
|
#print("oled.clear");
|
||||||
|
|
||||||
if (IAQ < 100):
|
if (IAQ < 100):
|
||||||
zipleds.setLED(0, zipleds.GREEN)
|
zipleds.setLED(0, zipleds.GREEN)
|
||||||
@ -53,14 +80,28 @@ while True:
|
|||||||
zipleds.setLED(2, zipleds.GREEN)
|
zipleds.setLED(2, zipleds.GREEN)
|
||||||
else:
|
else:
|
||||||
zipleds.setLED(2, zipleds.RED)
|
zipleds.setLED(2, zipleds.RED)
|
||||||
zipleds.setBrightness(10)
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
_ = buttonB
|
||||||
|
except NameError:
|
||||||
|
buttonB = 30
|
||||||
|
|
||||||
|
if buttonB > 0:
|
||||||
|
brightness = buttonB/4
|
||||||
|
if brightness > 100:
|
||||||
|
brighness = 100
|
||||||
|
zipleds.setBrightness(brightness)
|
||||||
|
buttonB = buttonB - 1
|
||||||
|
else:
|
||||||
|
zipleds.setBrightness(0)
|
||||||
|
|
||||||
|
|
||||||
# ffs all I want is an action every minute I hate python scope shit
|
# ffs all I want is an action every minute I hate python scope shit
|
||||||
#now = rtc.readTimeString();
|
#now = rtc.readTimeString();
|
||||||
# log every minute, thats 1440 records a day
|
# log every minute, thats 1440 records a day
|
||||||
sec = sec + 1
|
sec = sec + 1
|
||||||
secmod = sec % 29
|
secmod = sec % 59
|
||||||
if (secmod) == 0:
|
if (secmod) == 0:
|
||||||
#log.setupDataFields("Date", "Time", "Temperature", "Pressure", "Humidity", "IAQ", "eCO2")
|
#log.setupDataFields("Date", "Time", "Temperature", "Pressure", "Humidity", "IAQ", "eCO2")
|
||||||
log_string = (rtc.readDateString() + ',' + \
|
log_string = (rtc.readDateString() + ',' + \
|
||||||
@ -75,6 +116,10 @@ while True:
|
|||||||
f.write(log_string)
|
f.write(log_string)
|
||||||
f.flush()
|
f.flush()
|
||||||
zipleds.setLED(1, zipleds.RED)
|
zipleds.setLED(1, zipleds.RED)
|
||||||
|
zipleds.setLED(0, zipleds.BLACK)
|
||||||
|
zipleds.setLED(2, zipleds.BLACK)
|
||||||
|
zipleds.setBrightness(20) # always show a logging flash
|
||||||
|
#print("flash");
|
||||||
elif (secmod < 10):
|
elif (secmod < 10):
|
||||||
zipleds.setLED(1, zipleds.BLUE)
|
zipleds.setLED(1, zipleds.BLUE)
|
||||||
elif (secmod > 10):
|
elif (secmod > 10):
|
||||||
@ -86,4 +131,3 @@ while True:
|
|||||||
zipleds.setLED(1, zipleds.BLACK)
|
zipleds.setLED(1, zipleds.BLACK)
|
||||||
|
|
||||||
zipleds.show()
|
zipleds.show()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user