How manushyaaa/knob works
Project type and purpose
• This is a hardware-plus-software full-stack embedded control system.
• Purpose: provide a rotary-encoder “knob” device (Arduino + OLED) that sends events over USB serial to a host PC. A Python service listens, translates those events into system actions (volume, brightness), HTTP calls (WLED), or Spotify Web API calls, and sends display updates back to the Arduino.
File structure
• Top-level:
• README.md – project overview and usage
• get_device_info.py – helper to discover Arduino’s USB VID/PID
• v10/
– Arduino/knob_v1dot9.ino – firmware running on the Arduino MCU
– knob_v1dot9.py – main Python script that implements the controller logic
– productionF.pyw – Windows GUI wrapper (alternate entry point)
• No separate “frontend/backend” folders, but clear separation: one “frontend” on the device (Arduino+OLED) and one “backend” on the PC (Python service).
Insights from the README
• Hardware components: rotary encoder, push buttons, OLED screen, Arduino board
• Python dependencies: requests, serial, spotipy, pynput, screen_brightness_control
• Modes: Volume, Brightness, Spotify, WLED
• Bidirectional serial communication: events → Python → actions; time/mode/status → Arduino OLED
Main components
A. Hardware Device (Embedded Frontend)
• Rotary Encoder & Buttons
• OLED Display (Adafruit SSD1306)
• Arduino MCU (knob_v1dot9.ino)
B. Host PC Service (Backend)
• Serial Communication Module (pyserial)
• Command Mapping & Mode Manager
• Action Modules:
• System Volume Control (pynput or OS API)
• Screen Brightness Control (screen_brightness_control)
• Spotify Controller (spotipy → Spotify Web API)
• WLED Controller (requests → WLED HTTP API)
• Time & Status Updater (sends current time/mode back over serial)
C. External Services & Subsystems
• Operating System Audio Subsystem
• Operating System Display Subsystem
• Spotify Web API (external)
• WLED HTTP API (local/remote)
Relationships & data flows
1. User rotates encoder or presses button → Arduino firmware reads change
2. Arduino sends event message (e.g., “MODE=2, DIR=+1”) via USB serial → Python service
3. Python parses message → updates internal mode or executes corresponding action module
4. Action module call:
• OS volume/brightness API → adjusts system
• HTTP request → WLED controller
• Spotify Web API call → control music
5. Periodically (or on mode switch), Python queries system clock → sends formatted time/status via serial → Arduino updates OLED
Architectural patterns & principles
• Event-driven architecture: hardware events drive software actions
• Separation of concerns: embedded firmware vs. host service
• Modular design: each action (volume, brightness, Spotify, WLED) is a separate module
• Config-driven: a dictionary in the Python script holds VID/PID and service credentials