from machine import Pin, I2C
from mpu6050 import MPU6050
import time
import numpy as np
from tinyml_model import predict_gesture # Edge Impulse generated model
# Initialize MPU6050
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
mpu = MPU6050(i2c)
# Function to collect data from MPU6050
def get_sensor_data():
accel = mpu.accel
return np.array([accel.x, accel.y, accel.z])
# Main loop for gesture recognition
while True:
try:
data = get_sensor_data()
gesture = predict_gesture(data) # Run inference on collected data
if gesture == "wave":
print("Wave gesture detected!")
elif gesture == "swipe":
print("Swipe gesture detected!")
else:
print("No gesture detected")
time.sleep(0.5) # Delay to avoid rapid re-inference
except Exception as e:
print("Error:", e)
time.sleep(1)
from machine import Pin, I2C
from mpu6050 import MPU6050
import time
import numpy as np
from tinyml_model import predict_gesture # Edge Impulse generated model
# Initialize MPU6050
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
mpu = MPU6050(i2c)
# Function to collect data from MPU6050
def get_sensor_data():
accel = mpu.accel
return np.array([accel.x, accel.y, accel.z])
# Main loop for gesture recognition
while True:
try:
data = get_sensor_data()
gesture = predict_gesture(data) # Run inference on collected data
if gesture == "wave":
print("Wave gesture detected!")
elif gesture == "swipe":
print("Swipe gesture detected!")
else:
print("No gesture detected")
time.sleep(0.5) # Delay to avoid rapid re-inference
except Exception as e:
print("Error:", e)
time.sleep(1)