#fijnstofsensor nog te verbinden!
import machine
import time
import MPU6050
import utime
from machine import Pin,I2C
from ssd1306 import SSD1306_I2C
from dht import DHT22
import math
i2c = I2C(0,sda = Pin(0), scl = Pin(1), freq = 400000)
i2c_mpu = I2C(1, sda=machine.Pin(14), scl=machine.Pin(13))
mpu = MPU6050.MPU6050(i2c_mpu)
mpu.wake()
i2c_oled = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1))
oled = SSD1306_I2C(128, 64, i2c_oled)
oled = SSD1306_I2C(128, 64, i2c)
dht = DHT22(Pin(15))
dht.measure()
temp = dht.temperature()
hum = dht.humidity()
gyro = mpu.read_gyro_data()
accel = mpu.read_accel_data()
temp = mpu.read_temperature()
gyro_x, gyro_y, gyro_z = gyro
accel_x, accel_y, accel_z = accel
# Read temperature from sensor
temp = temp
def read_dht22_sensor():
try:
dht.measure()
temperature = dht.temperature()
humidity = dht.humidity()
return temperature, humidity
except Exception as e:
print("Fout bij het uitlezen van de sensor:", e)
return None, None
def calculate_heat_index(temperature_celsius, humidity):
c1 = -8.78469475556
c2 = 1.61139411
c3 = 2.33854883889
c4 = -0.14611605
c5 = -0.012308094
c6 = -0.0164248277778
c7 = 0.002211732
c8 = 0.00072546
c9 = -0.000003582
heat_index = (c1 +
(c2 * temperature_celsius) +
(c3 * humidity) +
(c4 * temperature_celsius * humidity) +
(c5 * temperature_celsius ** 2) +
(c6 * humidity ** 2) +
(c7 * temperature_celsius ** 2 * humidity) +
(c8 * temperature_celsius * humidity ** 2) +
(c9 * temperature_celsius ** 2 * humidity ** 2))
return heat_index
oled.fill(0)
#oled.text(" __ ", 0, 5)
#oled.text("/ | _ _ __ ", 0, 15)
#oled.text("\__ | (/_(_|| | ", 0, 20)
#oled.text(" _ ", 0, 25)
#oled.text("|_| . __ ", 0,30)
#oled.text("| | | | ", 0, 35)
#oled.text(" _ ",0,40)
#oled.text("|_| _ _|_ ",0,47)
#oled.text("| |(_ |_ ",0,55)
oled.text("CLEAN.AIR.ACT!", 0, 10)
oled.text("2023-2024", 0, 20)
oled.text("clean-air-act.eu", 0, 30)
oled.text(">> Push button!", 5, 55)
oled.show()
def show_screen_1():
oled.fill(0)
oled.text("TEMPERATURE", 5, 10)
oled.text(str(temp) + " degrees", 5, 25)
oled.show()
def show_screen_2():
oled.fill(0)
oled.text("HUMIDITY", 5, 10)
oled.text(str(hum) + " %", 5, 25)
oled.show()
def show_screen_3():
oled.fill(0)
oled.text("FEELS LIKE", 5, 10)
oled.text(str(heat_index), 5, 25)
oled.show()
def show_screen_4()
oled.fill(0)
oled.text("Gyro X: " + str(gyro_x), 0, 0)
oled.text("Gyro Y: " + str(gyro_y), 0, 9)
oled.text("Gyro Z: " + str(gyro_z), 0, 18)
oled.text("Accel X: " + str(accel_x), 0, 27)
oled.text("Accel Y: " + str(accel_y), 0, 36)
oled.text("Accel Z: " + str(accel_z), 0, 45)
oled.text("Temp: " + str(temp), 0, 57)
oled.show()
button = machine.Pin(10, machine.Pin.IN, machine.Pin.PULL_UP) # Drukknop op pin 10
current_screen = 1 # Het huidige schermnummer
while True:
temperature, humidity = read_dht22_sensor()
if temperature is not None and humidity is not None:
heat_index = calculate_heat_index(temperature, humidity)
print(f"Temperatuur: {temperature} °C, Luchtvochtigheid: {humidity} %, Heat index: {heat_index:.2f} °C")
# Meet elke 5 seconden
if button.value() == 0: # Als de knop wordt ingedrukt
current_screen += 1 # Schakel naar het volgende scherm
if current_screen > 3: # Als het laatste scherm is bereikt, ga terug naar het eerste scherm
current_screen = 1
if current_screen == 1:
show_screen_1()
elif current_screen == 2:
show_screen_2()
elif current_screen == 3:
show_screen_3()
elif current_screen == 4:
show_screen_4()
# Wacht totdat de knop wordt losgelaten om de volgende schermwissel te voorkomen
while button.value() == 0:
utime.sleep(0.5)
pass
Loading
ssd1306
ssd1306