Enthernet Code
Enthernet Code
DIIDevHeads IoT Integration Server
Created by Enthernet Code on 7/30/2024 in #firmware-and-baremetal
How to Fix "OSError: [Errno 5] EIO" in STM32 Water Quality Monitoring System?
Here's my code
import machine
import time
from lcd import LCD
from ds18x20 import DS18X20
from onewire import OneWire
import tensorflow as tf

ow = OneWire(machine.Pin(12))
ds = DS18X20(ow)

def read_temperature():
roms = ds.scan()
ds.convert_temp()
time.sleep_ms(750)
for rom in roms:
return ds.read_temp(rom)

def read_ph():
return 7.0

def read_turbidity():
return 100

lcd = LCD(i2c_addr=0x27, i2c_bus=1)

def display_data(ph, turbidity, temperature):
lcd.clear()
lcd.putstr(f'PH: {ph:.2f}\n')
lcd.putstr(f'Turb: {turbidity:.2f} NTU\n')
lcd.putstr(f'Temp: {temperature:.2f} C')

interpreter = tf.lite.Interpreter(model_path="water_quality_predictor.tflite")
interpreter.allocate_tensors()

input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

def predict_water_quality(ph, turbidity, temperature):
interpreter.set_tensor(input_details[0]['index'], [[ph, turbidity, temperature]])
interpreter.invoke()
prediction = interpreter.get_tensor(output_details[0]['index'])
return prediction[0][0]

while True:
temperature = read_temperature()
ph = read_ph()
turbidity = read_turbidity()

if temperature is not None and ph is not None and turbidity is not None:
quality = predict_water_quality(ph, turbidity, temperature)
print(f"Water Quality Index: {quality}")
display_data(ph, turbidity, temperature)

time.sleep(5)

import machine
import time
from lcd import LCD
from ds18x20 import DS18X20
from onewire import OneWire
import tensorflow as tf

ow = OneWire(machine.Pin(12))
ds = DS18X20(ow)

def read_temperature():
roms = ds.scan()
ds.convert_temp()
time.sleep_ms(750)
for rom in roms:
return ds.read_temp(rom)

def read_ph():
return 7.0

def read_turbidity():
return 100

lcd = LCD(i2c_addr=0x27, i2c_bus=1)

def display_data(ph, turbidity, temperature):
lcd.clear()
lcd.putstr(f'PH: {ph:.2f}\n')
lcd.putstr(f'Turb: {turbidity:.2f} NTU\n')
lcd.putstr(f'Temp: {temperature:.2f} C')

interpreter = tf.lite.Interpreter(model_path="water_quality_predictor.tflite")
interpreter.allocate_tensors()

input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

def predict_water_quality(ph, turbidity, temperature):
interpreter.set_tensor(input_details[0]['index'], [[ph, turbidity, temperature]])
interpreter.invoke()
prediction = interpreter.get_tensor(output_details[0]['index'])
return prediction[0][0]

while True:
temperature = read_temperature()
ph = read_ph()
turbidity = read_turbidity()

if temperature is not None and ph is not None and turbidity is not None:
quality = predict_water_quality(ph, turbidity, temperature)
print(f"Water Quality Index: {quality}")
display_data(ph, turbidity, temperature)

time.sleep(5)

6 replies