skruglewicz
Published

Design Document - Kitchen Smart Inventory Assistant

The Kitchen Smart Inventory Assistant integrates advanced features to streamline kitchen management and reduce waste

IntermediateFull instructions providedOver 2 days2,362

Things used in this project

Hardware components

UNIHIKER - IoT Python Programming Single Board Computer with Touchscreen
DFRobot UNIHIKER - IoT Python Programming Single Board Computer with Touchscreen
The UNIHIKER provides a touchscreen interface for inventory visualization, recipe suggestions, and reminders for items nearing expiration
×1
Seeed Studio SenseCap Watcher
The SenseCap Watcher's camera identifies food items and packaging, logging them into a digital inventory while assisting with recycling by recognizing material types
×1
BBC micro:bit board
BBC micro:bit board
The micro:bit monitors environmental conditions like temperature and humidity, ensuring optimal storage and alerting users to potential issues through its LED matrix
×1

Story

Read more

Code

Pseudo Code - functionality and relationships between the three main components

Python
This pseudo code demonstrates the core functionality and relationships between the three main components of the Kitchen Smart Inventory Assistant, following the class diagrams' structure and maintaining the system's modular architecture
class UniHiker:
    def __init__(self):
        self.inventory = {}
        self.alerts = []
        self.watcher = None
        self.microbit = None
        
    def process_image(self, image):
        """Process image data from watcher"""
        items = self.identify_items(image)
        self.update_inventory(items)
        
    def process_voice_command(self, command):
        """Handle voice commands"""
        command_type = self.parse_command(command)
        self.execute_command(command_type)
        
    def check_environment(self):
        """Monitor environmental data"""
        temp, humidity = self.microbit.get_readings()
        if self.check_thresholds(temp, humidity):
            self.generate_alert()
            
    def update_display(self):
        """Update touchscreen interface"""
        self.show_inventory()
        self.show_alerts()
        
    def main_loop(self):
        """Main control loop"""
        while True:
            self.process_watcher_data()
            self.process_microbit_data()
            self.update_display()

class SenseCAPWatcher:
    def __init__(self):
        self.camera = Camera()
        self.microphone = Microphone()
        self.speaker = Speaker()
        self.wifi_module = WiFiModule()
        
    def capture_image(self):
        """Capture image using camera"""
        return self.camera.take_photo()
        
    def identify_items(self, image):
        """Process image using AI recognition"""
        return self.ai_processor.recognize(image)
        
    def get_voice_command(self):
        """Get voice input from microphone"""
        return self.microphone.listen()
        
    def provide_feedback(self, message):
        """Output feedback through speaker"""
        self.speaker.play(message)

class MicroBit:
    def __init__(self, serial_port, baud_rate):
        self.serial_port = serial_port
        self.baud_rate = baud_rate
        self.led_matrix = LEDMatrix()
        self.sensors = Sensors()
        
    def read_sensors(self):
        """Read temperature and humidity data"""
        return self.sensors.get_readings()
        
    def display_alert(self, message):
        """Show alert on LED matrix"""
        self.led_matrix.display(message)
        
    def check_conditions(self):
        """Verify environmental conditions"""
        temp, humidity = self.read_sensors()
        return self.validate_readings(temp, humidity)

Pseudo Code - Possible Implementation 1

Python
Example pseudo code implementation showing a system where each device handles its specialized tasks while communicating with the central Unihiker hub
1. The SenseCap Watcher continuously monitors for:
- New items being added (via camera)
- Voice commands from users
- Sends data to Unihiker via WiFi
2. The BBC micro:bit constantly:
- Monitors temperature and humidity
- Sends environmental data to Unihiker via UART
- Displays alerts on its LED matrix when needed
3. The Unihiker (central hub):
- Processes incoming image and voice data
- Updates inventory based on recognized items
- Checks environmental conditions
- Updates the touchscreen display
- Generates alerts when needed
# Running on SenseCap Watcher
class SenseCAPWatcher:
    def __init__(self):
        self.camera = Camera()
        self.microphone = Microphone()
        self.wifi = WiFiModule()
        
    def capture_and_send(self):
        while True:
            if image := self.camera.capture():
                self.wifi.send_to_unihiker(image)
            if voice := self.microphone.listen():
                self.wifi.send_to_unihiker(voice)
            time.sleep(0.1)

# Running on BBC micro:bit
class MicroBit:
    def __init__(self):
        self.temp_sensor = TemperatureSensor()
        self.humid_sensor = HumiditySensor()
        self.uart = UARTConnection()
        
    def monitor_and_send(self):
        while True:
            temp = self.temp_sensor.read()
            humidity = self.humid_sensor.read()
            data = {"temp": temp, "humidity": humidity}
            self.uart.send_to_unihiker(data)
            time.sleep(1)

# Running on Unihiker (Central Hub)
class UniHiker:
    def __init__(self):
        self.inventory = {}
        self.wifi = WiFiModule()
        self.uart = UARTConnection()
        self.display = TouchScreen()
        
    def main_loop(self):
        while True:
            # Handle Watcher data
            if watcher_data := self.wifi.receive():
                if "image" in watcher_data:
                    items = self.process_image(watcher_data["image"])
                    self.update_inventory(items)
                elif "voice" in watcher_data:
                    self.process_voice_command(watcher_data["voice"])
            
            # Handle micro:bit data
            if sensor_data := self.uart.receive():
                if self.check_conditions(sensor_data):
                    self.generate_alert("Storage conditions need attention!")
            
            # Update display
            self.display.show_inventory(self.inventory)
            time.sleep(0.1)

Pseudo Code - Possible Implementation 2

Python
Here's a pseudo code implementation showing how the three classes collaborate in a real-world kitchen scenario:

This implementation shows:
- How each device operates independently
- Data flow between devices
- Error handling and continuous monitoring
- Real-time processing and updates
- Integration of all system components

Each device runs its own main loop while maintaining communication with the others, creating a comprehensive kitchen management system.
# Real-world scenario example:
"""
1. User brings groceries into kitchen
2. SenseCap Watcher:
   - Captures images of new items
   - Processes voice command "Add milk and eggs"
   - Sends data to Unihiker

3. BBC micro:bit:
   - Continuously monitors temperature and humidity
   - Sends environmental data to Unihiker
   - Displays alerts on LED matrix if conditions exceed thresholds

4. Unihiker:
   - Processes incoming data from both devices
   - Updates inventory with new items
   - Checks environmental conditions
   - Updates display with current status
   - Generates alerts if needed
"""


# Device 1: Unihiker (Central Hub)
class UniHiker:
    def __init__(self):
        self.watcher = SenseCAPWatcher()
        self.microbit = MicroBit('/dev/ttyACM0', 115200)
        self.inventory = {}
        self.alerts = []
        
    def main_loop(self):
        while True:
            try:
                # Process SenseCap Watcher data
                if image_data := self.watcher.get_image_data():
                    items = self.process_image(image_data)
                    self.update_inventory(items)
                
                if voice_data := self.watcher.get_voice_data():
                    self.handle_voice_command(voice_data)
                
                # Process MicroBit environmental data
                env_data = self.microbit.get_readings()
                self.check_conditions(env_data)
                
                # Update display
                self.update_display()
                time.sleep(0.1)
                
            except Exception as e:
                self.alerts.append(f"Error: {str(e)}")

# Device 2: SenseCap Watcher
class SenseCAPWatcher:
    def __init__(self):
        self.camera = Camera()
        self.microphone = Microphone()
        self.wifi = WiFiConnection()
        
    def run(self):
        while True:
            try:
                # Capture and process image
                if image := self.camera.capture():
                    items = self.process_image(image)
                    self.send_to_unihiker({
                        'type': 'image_data',
                        'items': items
                    })
                
                # Process voice commands
                if audio := self.microphone.listen():
                    command = self.process_voice(audio)
                    self.send_to_unihiker({
                        'type': 'voice_data',
                        'command': command
                    })
                    
                time.sleep(0.1)
                
            except Exception as e:
                print(f"Watcher Error: {str(e)}")

# Device 3: BBC micro:bit
class MicroBit:
    def __init__(self, serial_port, baud_rate):
        self.serial = SerialConnection(serial_port, baud_rate)
        self.temp_sensor = TemperatureSensor()
        self.humidity_sensor = HumiditySensor()
        
    def run(self):
        while True:
            try:
                # Read sensor data
                temp = self.temp_sensor.read()
                humidity = self.humidity_sensor.read()
                
                # Send to Unihiker via UART
                data = {
                    'temperature': temp,
                    'humidity': humidity,
                    'timestamp': time.time()
                }
                self.serial.send(json.dumps(data))
                
                # Check for alerts
                if temp > 25 or humidity > 60:
                    self.display_alert()
                    
                time.sleep(1)
                
            except Exception as e:
                print(f"MicroBit Error: {str(e)}")

# Example usage for each device:

# On Unihiker:
def run_unihiker():
    hub = UniHiker()
    hub.main_loop()

# On SenseCap Watcher:
def run_watcher():
    watcher = SenseCAPWatcher()
    watcher.run()

# On BBC micro:bit:
def run_microbit():
    microbit = MicroBit('/dev/ttyACM0', 115200)
    microbit.run()

Credits

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

Comments

Please log in or sign up to comment.