skruglewicz
Published

KitchenMind: - Now Powered by Unihiker K10

This project presents a comprehensive environmental monitoring station leveraging the DFRobot UNIHIKER K10 as the central processing hub.

IntermediateProtip5 hours16
KitchenMind: - Now Powered by Unihiker K10

Things used in this project

Hardware components

DFRobot unihiker K10
×1

Story

Read more

Schematics

Diagram

schematic diagram representing the connections and main system blocks in your Unihiker K10 environmental monitoring project code:

detailed wiring/pinout schematic using Mermaid that matches your code and hardware setup

Pinout Details:

DHT22: Connect Data pin to K10 GPIO21, power and ground to 3V3/GND.

MQ-135: Connect analog output to K10 A0, VCC/GND to device.

BH1750: Connect SDA/SCL to K10’s I2C pins, power to 3V3/GND.

Buzzer: Connect control wire to GPIO23, VCC/GND to device.

Camera & Touchscreen: Use K10's built-in modules.

MicroSD: Use onboard slot for CSV data logging.

Code

Starter MicroPython implementation

MicroPython
This is a MicroPython script for the Unihiker K10, which implements a Smart Environmental Monitoring Station. The script uses built-in libraries and modules specifically compatible with the K10—like PinPong and unihiker—to read a variety of environmental sensors, perform basic AI vision with the onboard camera, display data and alerts on the touchscreen, and log everything for later reference.

How do you use it?

Connect your sensors and camera to the correct pins on the Unihiker K10.

Example sensors: DHT22 (temperature/humidity), MQ-135 (air quality), BH1750 (light), and more.

The K10 camera supports image capture and object detection routines.

Upload this MicroPython script to the Unihiker K10 (usually as main.py).

Power on the K10 and run the script; it automatically reads sensor values and camera data in a loop.

View real-time results on the K10’s touchscreen UI, which shows temperature, humidity, air quality, light levels, AI vision results, and alerts if any sensor readings go above preset thresholds.

Listen for alerts—for example, the buzzer turns on if temperature or air quality go beyond certain limits.

Data is logged for review in a CSV file on the device for historical analysis.

Modify and expand: You can easily adapt the script for additional sensors or more advanced AI vision features by using the documented K10 MicroPython APIs.

In summary:
It's a plug-and-play base for running an advanced sensor station with vision and local UI on K10, designed for easy extension, reliable logging, and straightforward real-world deployment.
# Smart Environmental Monitoring Station with Unihiker K10 — MicroPython Example

from unihiker import GUI
from pinpong.board import Board, DigitalPin, AnalogPin
from pinpong.extension.unihiker import Camera, Buzzer, WiFi

import time
import csv

# ==== SYSTEM AND UI INIT ====

Board("UNIHIKER").begin()
gui = GUI()

# Touchscreen dimensions for K10 (adjust for your model)
SCREEN_WIDTH, SCREEN_HEIGHT = 240, 320

# Create data display labels for UI
data_labels = {
    'temperature': gui.label(text='Temp:', x=10, y=20, font_size=20),
    'humidity': gui.label(text='Humidity:', x=10, y=50, font_size=20),
    'air_quality': gui.label(text='Air Quality:', x=10, y=80, font_size=20),
    'light': gui.label(text='Light:', x=10, y=110, font_size=20),
    'vision': gui.label(text='Vision:', x=10, y=140, font_size=20),
    'alert': gui.label(text='', x=10, y=200, font_size=22, color='red')
}

# ==== SENSOR INIT ====

# Example: DHT22 sensor on GPIO Pin 21
try:
    from pinpong.libs.dfrobot_dht import DHT
    dht = DHT(pin=21, sensor_type="DHT22")
except:
    dht = None  # Fallback for demo

# MQ-135 Air Quality on Analog A0
mq135 = AnalogPin(A0)

# BH1750 Light sensor via I2C (address default 0x23)
try:
    from pinpong.libs.dfrobot_bh1750 import BH1750
    bh1750 = BH1750()
except:
    bh1750 = None

# Camera and Vision module for K10
camera = Camera()

# Buzzer for alerts
buzzer = Buzzer(pin=23)  # Use correct pin for your wiring

# ==== DATA LOGGING ====
csv_file = '/home/unihiker/env_log.csv'

def log_data_to_csv(row):
    with open(csv_file, 'a', newline='') as csvfile:
        writer = csv.writer(csvfile)
        writer.writerow(row)

# ==== MAIN MONITORING LOOP ====

def vision_inference():
    # Replace with K10-supported inference (see DFRobot docs)
    # For demo, just dummy output
    img = camera.capture()
    detected = camera.detect_objects()  # Returns list of labels
    if detected:
        return f"Detected: {', '.join(detected)}"
    else:
        return "No objects"

def get_sensor_data():
    # Read all sensors
    temp, hum = None, None
    if dht:
        dht.read()
        temp = dht.temperature
        hum = dht.humidity

    air_quality = mq135.read()
    lux = bh1750.read_light() if bh1750 else None

    return temp, hum, air_quality, lux

def update_ui(temp, hum, air_quality, lux, vision_str, alert_str):
    data_labels['temperature'].text = f"Temp: {temp} °C" if temp else "Temp: N/A"
    data_labels['humidity'].text = f"Humidity: {hum}%" if hum else "Humidity: N/A"
    data_labels['air_quality'].text = f"Air Quality: {air_quality}" if air_quality else "Air Quality: N/A"
    data_labels['light'].text = f"Light: {lux} lx" if lux else "Light: N/A"
    data_labels['vision'].text = vision_str
    data_labels['alert'].text = alert_str

def check_alerts(temp, hum, air_quality, lux):
    # Simple example: Trigger on thresholds
    if temp and temp > 30:
        buzzer.on()
        return "High Temperature Alert!"
    if air_quality and air_quality > 300:
        buzzer.on()
        return "Air Quality Alert!"
    buzzer.off()
    return ""

while True:
    temp, hum, air_quality, lux = get_sensor_data()
    vision_str = vision_inference()
    alert_str = check_alerts(temp, hum, air_quality, lux)
    update_ui(temp, hum, air_quality, lux, vision_str, alert_str)

    # Data log: [timestamp, temp, hum, air_quality, lux, vision detection]
    log_row = [time.time(), temp, hum, air_quality, lux, vision_str]
    log_data_to_csv(log_row)

    time.sleep(5)  # Update interval

# ==== END OF SCRIPT ====

Credits

skruglewicz
37 projects • 19 followers
I am now a retired Senior Software Engineer with a Bachelor’s of Science Degree in Computer Science from Boston University.

Comments