import machine
import time
import ssd1306
from ccs811 import CCS811
from hdc1080 import HDC1080
from bmp280 import BMP280
import tensorflow as tf
i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
ccs811 = CCS811(i2c)
hdc1080 = HDC1080(i2c)
bmp280 = BMP280(i2c)
def read_sensor_data():
try:
co2, tvoc = ccs811.read_data()
temperature = hdc1080.read_temperature()
humidity = hdc1080.read_humidity()
pressure = bmp280.read_pressure()
return co2, tvoc, temperature, humidity, pressure
except OSError as e:
print('Failed to read sensor:', e)
return None, None, None, None, None
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
def display_data(aqi):
oled.fill(0)
oled.text(f'AQI: {aqi}', 0, 0)
oled.show()
interpreter = tf.lite.Interpreter(model_path="aqi_predictor.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
def predict_aqi(co2, tvoc, temperature, humidity, pressure):
import machine
import time
import ssd1306
from ccs811 import CCS811
from hdc1080 import HDC1080
from bmp280 import BMP280
import tensorflow as tf
i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
ccs811 = CCS811(i2c)
hdc1080 = HDC1080(i2c)
bmp280 = BMP280(i2c)
def read_sensor_data():
try:
co2, tvoc = ccs811.read_data()
temperature = hdc1080.read_temperature()
humidity = hdc1080.read_humidity()
pressure = bmp280.read_pressure()
return co2, tvoc, temperature, humidity, pressure
except OSError as e:
print('Failed to read sensor:', e)
return None, None, None, None, None
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
def display_data(aqi):
oled.fill(0)
oled.text(f'AQI: {aqi}', 0, 0)
oled.show()
interpreter = tf.lite.Interpreter(model_path="aqi_predictor.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
def predict_aqi(co2, tvoc, temperature, humidity, pressure):