Skip to content

pranalisree/AutoPCB

Repository files navigation

AutoPCB - AI-Powered PCB Layout Generator

AutoPCB is an AI chatbot that converts KiCad schematic files (.kicad_sch or .net) into optimized PCB layouts (.kicad_pcb) using Google's Gemini AI for intelligent footprint suggestions.

🚀 Features

  • Schematic Parsing: Supports both KiCad schematic (.kicad_sch) and netlist (.net) files
  • AI-Powered Footprint Suggestions: Uses Google Gemini AI to suggest appropriate footprints
  • Automated PCB Generation: Creates PCB layouts with components placed in optimized positions
  • RESTful API: Clean FastAPI backend with modular architecture
  • File Management: Upload schematics and download generated PCB files

🏗️ Architecture

AutoPCB/
├── main.py                 # FastAPI application entry point
├── requirements.txt        # Python dependencies
├── env.example            # Environment configuration template
├── parsers/               # Schematic parsing modules
│   ├── __init__.py
│   └── schematic_parser.py
├── ai/                    # AI integration modules
│   ├── __init__.py
│   └── gemini_client.py
├── eda/                   # EDA tools integration
│   ├── __init__.py
│   └── pcb_generator.py
├── routes/                # API route handlers
│   └── __init__.py
├── uploads/               # Uploaded schematic files
└── outputs/               # Generated PCB files

🛠️ Installation

Prerequisites

  1. KiCad Installation: Install KiCad (version 6.0+) with Python API support
  2. Python 3.8+: Ensure Python 3.8 or higher is installed
  3. Gemini API Key: Get an API key from Google AI Studio

Setup Steps

  1. Clone the repository:

    git clone <repository-url>
    cd AutoPCB
  2. Install Python dependencies:

    pip install -r requirements.txt
  3. Configure environment:

    cp env.example .env
    # Edit .env and add your Gemini API key
  4. Verify KiCad installation:

    python -c "import pcbnew; print('KiCad Python API is available')"

🚀 Usage

Starting the Server

python main.py

The API will be available at http://localhost:8000

API Endpoints

1. Upload Schematic

POST /upload
Content-Type: multipart/form-data

# Upload a .kicad_sch or .net file

2. Analyze Schematic

POST /analyze
Content-Type: application/json

{
  "file_path": "uploads/schematic.sch"
}

3. Get Footprint Suggestions

POST /suggest_footprints
Content-Type: application/json

{
  "components": [
    {
      "ref": "R1",
      "value": "10k",
      "description": "Resistor"
    }
  ]
}

4. Generate PCB

POST /generate_pcb
Content-Type: application/json

{
  "components": [...],
  "nets": [...],
  "footprint_suggestions": {
    "R1": "Resistor_SMD:R_0603"
  },
  "board_name": "my_board"
}

5. Download PCB

GET /download/{filename}

Example Workflow

  1. Upload a KiCad schematic file
  2. Analyze the schematic to extract components and nets
  3. Get AI suggestions for appropriate footprints
  4. Generate the PCB layout
  5. Download the resulting .kicad_pcb file

🔧 Configuration

Environment Variables

  • GEMINI_API_KEY: Your Google Gemini API key (required)
  • HOST: Server host (default: 0.0.0.0)
  • PORT: Server port (default: 8000)
  • UPLOAD_DIR: Directory for uploaded files (default: uploads)
  • OUTPUT_DIR: Directory for generated files (default: outputs)

KiCad Configuration

Ensure KiCad is properly installed with Python API support. The system will automatically detect and use the installed KiCad libraries.

🧪 Testing

Run the test suite:

pytest

📝 API Documentation

Once the server is running, visit:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

🔮 Future Enhancements

  • Advanced Placement Optimization: Implement sophisticated component placement algorithms
  • Interactive Chat Interface: Allow users to refine layouts through natural language
  • Multi-layer Support: Generate complex multi-layer PCB designs
  • Design Rule Checking: Integrate DRC validation
  • 3D Visualization: Add 3D board preview capabilities

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🆘 Troubleshooting

Common Issues

  1. KiCad Import Error: Ensure KiCad is installed and Python API is enabled
  2. Gemini API Error: Verify your API key is correct and has sufficient quota
  3. File Upload Issues: Check file permissions and disk space
  4. PCB Generation Fails: Verify component footprints are valid KiCad footprints

Getting Help

  • Check the API documentation at /docs
  • Review the logs for detailed error messages
  • Ensure all dependencies are properly installed

🎯 Hackathon Goals

This project was developed for HackTX 2025 with the following objectives:

  • ✅ Working prototype with core functionality
  • ✅ AI integration for intelligent footprint suggestions
  • ✅ Modular, maintainable codebase
  • ✅ RESTful API design
  • 🔄 Simple web UI (stretch goal)
  • 🔄 Advanced placement optimization (stretch goal)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published