This project enables controlling a servo-driven robotic arm (or similar device) connected to a Raspberry Pi using natural language commands processed by Google's Gemini AI. It leverages the Model Context Protocol (MCP) for standardized communication between the client application and the server running on the Raspberry Pi.
- Features
- System Requirements
- Architecture Overview
- Project Structure
- Hardware Setup
- Software Installation
- Configuration
- Usage Guide
- API Documentation
- Troubleshooting
- Development
- Contributing
- License
- Natural Language Control: Issue commands in plain English (e.g., "Wave the arm", "Move servo 1 to 45 degrees")
- AI-Powered Translation: Google Gemini AI converts natural language to precise servo commands
- Real-time Control: Direct servo motor control with customizable timing and positioning
- Multi-Servo Support: Control up to 6 servos simultaneously on GPIO pins 17, 27, 22, 23, 24, 25
- Safety Features: Built-in angle limits and validation for specific servo configurations
- MCP Protocol: Standardized communication protocol for AI-tool interaction
- Cross-Platform Client: Tkinter-based GUI that runs on Windows, macOS, and Linux
- Async Architecture: Non-blocking operations for responsive user interface
- Error Handling: Comprehensive error reporting and status monitoring
- Logging System: Detailed operation logs for debugging and monitoring
- Modern GUI: Dark-themed interface with intuitive controls
- Real-time Status: Live status updates and command execution feedback
- Command History: Log of all commands and responses
- Connection Management: Easy server IP and port configuration
wednesday.1.mp4
- Model: Raspberry Pi 4B (recommended) or Raspberry Pi 3B+
- RAM: Minimum 2GB, 4GB recommended
- Storage: MicroSD card (16GB+, Class 10)
- GPIO: Access to GPIO pins for servo connections
- Power: 5V 3A power supply (official Raspberry Pi power supply recommended)
- Type: Standard hobby servos (SG90, MG996R, or similar)
- Voltage: 4.8V-6V operation
- Signal: PWM control (50Hz, 1-2ms pulse width)
- Quantity: Up to 6 servos supported
- Breadboard/PCB: For connections and power distribution
- Jumper Wires: Male-to-male and male-to-female
- External Power Supply: 5V-6V for servos (separate from Pi power)
- Capacitors: 1000Β΅F capacitors for servo power stabilization (recommended)
- Operating System: Windows 10+, macOS 10.14+, or Linux (Ubuntu 18.04+)
- Python: Version 3.11 or higher
- Internet: Required for Gemini AI API access
- Network: Local network access to Raspberry Pi
- OS: Raspberry Pi OS (Bullseye or newer)
- Python: Version 3.11 (typically pre-installed)
- pigpio: Daemon for precise GPIO control
- Network: WiFi or Ethernet connection
The system consists of two main components communicating via the Model Context Protocol:
βββββββββββββββββββ HTTP/MCP βββββββββββββββββββ
β β βββββββββββββββΊ β β
β Client App β β Raspberry Pi β
β (Your PC) β βββββββββββββββ β Server β
β β JSON/MCP β β
βββββββββββββββββββ βββββββββββββββββββ
β β
β β
βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ
β Gemini AI β β Servo Motors β
β (Google) β β (Hardware) β
βββββββββββββββββββ βββββββββββββββββββ
- User Input: Natural language command entered in GUI
- AI Processing: Gemini AI converts text to structured servo commands
- MCP Communication: Client sends commands to Pi server via MCP protocol
- Hardware Control: Server executes commands using pigpio library
- Feedback: Status and results returned to client
The Model Context Protocol provides:
- Standardized Tool Definition: Server exposes
execute_servo_commandstool - Type Safety: Structured JSON schema for command validation
- Error Handling: Standardized error reporting and status codes
- Discoverability: Client can query available tools and their schemas
wednesday/
βββ client/ # Client application
β βββ wednesday_app.py # Main GUI application (429 lines)
β βββ requirements.txt # Python dependencies
β βββ dot_env_example # Environment file template
β βββ .env # API keys (create from template)
βββ server/ # Raspberry Pi server
β βββ server.py # MCP server implementation (110 lines)
β βββ requirements.txt # Python dependencies
βββ README.md # This documentation
βββ LICENSE # MIT License
βββ docs/ # Additional documentation (optional)
βββ hardware_setup.md # Detailed hardware instructions
βββ api_reference.md # API documentation
βββ troubleshooting.md # Common issues and solutions
wednesday_app.py: Main application with Tkinter GUI, Gemini integration, and MCP clientrequirements.txt: Dependencies includinggoogle-generativeai,mcp[cli],python-dotenv.env: Configuration file containing Gemini API key
server.py: FastMCP server with servo control logic and safety featuresrequirements.txt: Dependencies includingmcp[cli],pigpio,fastmcp
The server is configured to control servos on the following GPIO pins:
| GPIO Pin | Description | Angle Limit | Typical Use |
|---|---|---|---|
| 17 | Servo 1 | 0-45Β° | Base rotation (limited) |
| 27 | Servo 2 | 0-45Β° | Shoulder joint (limited) |
| 22 | Servo 3 | 0-45Β° | Elbow joint (limited) |
| 23 | Servo 4 | 0-180Β° | Wrist rotation |
| 24 | Servo 5 | 0-180Β° | Wrist tilt |
| 25 | Servo 6 | 0-180Β° | Gripper/end effector |
Raspberry Pi Servo Motors
βββββββββββββββ βββββββββββββββ
β GPIO 17 βββββΌβββββββββββββββββΌβββ Signal β Servo 1
β GPIO 27 βββββΌβββββββββββββββββΌβββ Signal β Servo 2
β GPIO 22 βββββΌβββββββββββββββββΌβββ Signal β Servo 3
β GPIO 23 βββββΌβββββββββββββββββΌβββ Signal β Servo 4
β GPIO 24 βββββΌβββββββββββββββββΌβββ Signal β Servo 5
β GPIO 25 βββββΌβββββββββββββββββΌβββ Signal β Servo 6
β 5V ββββββββββΌβββββββββββββββββΌβββ VCC β (All servos)
β GND βββββββββΌβββββββββββββββββΌβββ GND β (All servos)
βββββββββββββββ βββββββββββββββ
-
Power Distribution:
- Use a separate 5V-6V power supply for servos
- Connect servo VCC to external power supply positive
- Connect servo GND to both external power supply negative AND Raspberry Pi GND
- This prevents power draw issues on the Pi
-
Signal Connections:
- Connect each servo signal wire to its designated GPIO pin
- Use jumper wires or a custom PCB for clean connections
- Ensure solid connections to prevent signal interference
-
Mechanical Assembly:
- Mount servos according to your robotic arm design
- Ensure servo horns are properly aligned
- Test mechanical range of motion before applying power
-
Update System:
sudo apt update && sudo apt upgrade -y -
Install pigpio:
sudo apt install pigpio python3-pigpio -y sudo systemctl enable pigpiod sudo systemctl start pigpiod -
Clone Repository:
git clone https://github.com/yourusername/wednesday.git cd wednesday/server -
Install Python Dependencies:
pip3 install -r requirements.txt
-
Test pigpio Installation:
python3 -c "import pigpio; pi = pigpio.pi(); print(f'pigpio version: {pi.get_pigpio_version()}')" -
Run Server:
python3 server.py
-
Prerequisites:
- Python 3.11 installed
- pip package manager
- Internet connection
-
Clone Repository:
git clone https://github.com/yourusername/wednesday.git cd wednesday/client -
Create Virtual Environment (recommended):
python -m venv venv # On Windows: venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
-
Install Dependencies:
pip install -r requirements.txt
-
Configure Environment:
cp dot_env_example .env # Edit .env file and add your Gemini API key -
Run Client:
python wednesday_app.py
-
Get API Key:
- Visit Google AI Studio
- Create a new API key
- Copy the key for configuration
-
Configure Client:
# Edit client/.env file GEMINI_API_KEY="your_actual_api_key_here"
The server configuration is defined in server/server.py:
# Pin Configuration
ALLOWED_PINS = {17, 27, 22, 23, 24, 25}
PINS_WITH_ANGLE_CAP = {17, 27, 22}
MAX_ANGLE_FOR_CAPPED_PINS = 45.0
# Servo Parameters
MIN_PULSE_WIDTH = 500 # microseconds
MAX_PULSE_WIDTH = 2500 # microseconds
MIN_ANGLE = 0.0 # degrees
MAX_ANGLE = 180.0 # degrees-
Find Raspberry Pi IP:
# On Raspberry Pi: hostname -I # Or check router's admin panel
-
Configure Client:
- Open client application
- Enter Raspberry Pi IP address
- Default port: 8011
# On Raspberry Pi (if firewall is enabled):
sudo ufw allow 8011/tcpThe system understands natural language commands. Here are examples:
"Move servo 1 to 30 degrees""Set arm position to 45 degrees""Rotate base to 90 degrees"
"Wave the arm"β Multiple servos moving in sequence"Open and close gripper"β Servo 6 movement pattern"Move to home position"β All servos to 0 degrees
"Move servo 1 to 30 and servo 2 to 45 degrees""Set all servos to 90 degrees""Move servos 1, 2, and 3 to 30, 45, and 60 degrees"
-
Connect to Server:
- Enter Raspberry Pi IP address
- Verify port (default: 8011)
- Check connection status
-
Send Commands:
- Type natural language command
- Click "Send Command to Pi"
- Monitor status and log output
-
Monitor Results:
- Watch status updates
- Review command execution logs
- Check for error messages
The Gemini AI converts natural language to JSON commands:
[
{
"pin": 17,
"angle": 30.0,
"duration_ms": 500
},
{
"pin": 23,
"angle": 90.0,
"duration_ms": 1000
}
]- pin: GPIO pin number (17, 27, 22, 23, 24, 25)
- angle: Target angle in degrees (0-180, some pins limited to 0-45)
- duration_ms: Hold time in milliseconds (default: 500)
Executes a batch of servo movements.
Parameters:
commands(list[dict]): Array of servo command objects
Command Object:
{
"pin": int, # GPIO pin (17,27,22,23,24,25)
"angle": float, # Angle in degrees (0-180)
"duration_ms": int # Optional: hold duration (default 500ms)
}Response:
[
{
"pin": int,
"status": str, # "ok" or "error"
"message": str # Status description
}
]Main application class managing GUI and MCP communication.
Key Methods:
submit_text_action_async(): Process user commandsget_gemini_instructions(): Convert text to servo commandssend_commands_to_pi_mcp(): Execute commands on Pi
| Code | Description | Solution |
|---|---|---|
invalid_pin |
Invalid GPIO pin | Use pins 17,27,22,23,24,25 |
invalid_angle |
Angle out of range | Use 0-180Β° (0-45Β° for pins 17,27,22) |
pigpio_error |
Hardware communication error | Check pigpiod service |
connection_error |
Network communication failed | Verify IP address and network |
Problem: "Failed to connect to pigpio daemon"
# Solution:
sudo systemctl start pigpiod
sudo systemctl enable pigpiodProblem: "Port 8011 already in use"
# Solution:
sudo netstat -tlnp | grep 8011
sudo kill <process_id>Problem: Servos not responding
- Check wiring connections
- Verify servo power supply
- Test individual servos
- Check GPIO pin assignments
Problem: "GEMINI_API_KEY not found"
- Verify
.envfile exists in client directory - Check API key format and validity
- Ensure no extra spaces or quotes
Problem: "Connection refused"
- Verify Raspberry Pi IP address
- Check if server is running
- Test network connectivity:
ping <pi_ip> - Verify firewall settings
Problem: GUI freezes
- Check async loop functionality
- Restart application
- Verify Python version compatibility
Enable debug logging in server:
# Add to server.py
import logging
logging.basicConfig(level=logging.DEBUG)Enable verbose client logging:
# In wednesday_app.py, modify log_message calls
self.log_message(f"DEBUG: {debug_info}", level="DEBUG")- Increase pigpio sampling rate
- Optimize servo update frequency
- Use hardware PWM for critical servos
- Use wired connection for Pi
- Optimize MCP message size
- Implement command queuing
MCP is an open protocol designed to standardize how AI models and applications (like our client) interact with external tools and services (like our Raspberry Pi server).
-
Standardized Tool Usage: The server exposes its servo control functionality as an MCP "tool". The client can discover and call this tool using a standard MCP mechanism, rather than custom API calls.
-
Type Safety: MCP provides structured schemas for tool definitions, ensuring type safety and validation of commands.
-
Decoupling: The client doesn't need to know the fine-grained details of how the server implements servo control. It only needs to understand the MCP tool's interface (name, arguments, expected output).
-
Interoperability: While this project uses a custom client and server, MCP enables different AI agents and tools to work together more easily.
-
Error Handling: Standardized error reporting and status codes across the protocol.
In this project, the mcp Python library (specifically mcp[cli]) is used on both the client and server to implement this protocol:
- Server: Uses
FastMCPto expose servo control tools - Client: Uses
streamablehttp_clientto communicate with MCP servers - Protocol: HTTP transport layer for communication
- Format: JSON-structured messages with defined schemas
-
Extend Command Schema:
# Add new command types to Gemini prompt NEW_COMMANDS = { "sequence": "Execute predefined movement sequence", "calibrate": "Calibrate servo positions", "speed": "Control movement speed" }
-
Update Server Logic:
# In server.py, extend execute_servo_commands if cmd.get("type") == "sequence": await execute_sequence(cmd.get("sequence_name"))
-
Extend Pin Configuration:
ALLOWED_PINS = {17, 27, 22, 23, 24, 25, 26, 19} # Add new pins
-
Add Hardware-Specific Limits:
PIN_LIMITS = { 17: (0, 45), # Base rotation 26: (30, 150), # New servo with custom range }
Create test files for core functionality:
# tests/test_servo_commands.py
import pytest
from server import execute_servo_commands
@pytest.mark.asyncio
async def test_valid_servo_command():
commands = [{"pin": 17, "angle": 30, "duration_ms": 500}]
results = await execute_servo_commands(commands)
assert results[0]["status"] == "ok"Test MCP communication:
# tests/test_mcp_integration.py
async def test_mcp_tool_execution():
# Test MCP client-server communication
passFollow PEP 8 guidelines:
# Install development tools
pip install black flake8 mypy
# Format code
black *.py
# Check style
flake8 *.py
# Type checking
mypy *.py- Fork the Repository
- Create Feature Branch:
git checkout -b feature/new-feature
- Make Changes following code style guidelines
- Add Tests for new functionality
- Submit Pull Request
- Hardware Support: Add support for different servo types
- UI Improvements: Enhance the client interface
- Command Extensions: Add new natural language commands
- Documentation: Improve guides and tutorials
- Testing: Expand test coverage
- Performance: Optimize servo control timing
# Setup development environment
git clone https://github.com/yourusername/wednesday.git
cd wednesday
# Install development dependencies
pip install -r requirements-dev.txt
# Run tests
pytest tests/
# Run linting
flake8 client/ server/This project is licensed under the MIT License - see the LICENSE file for details.
- Google Gemini AI: For natural language processing capabilities
- Model Context Protocol: For standardized AI-tool communication
- pigpio Library: For precise Raspberry Pi GPIO control
- Tkinter: For cross-platform GUI framework
- Open Source Community: For tools and libraries that made this project possible
Happy Robotics! π€
Built with β€οΈ by the Wednesday Team



