This project is a low-cost, DIY Automated Optical Inspection (AOI) system for PCBs, focused on detecting soldering errors, missing/mismatched components (e.g., 0402 passives, 0.5mm pitch ICs), and generating root-cause reports for process tuning (stencil printing, component placement, reflow soldering). It uses computer vision with OpenCV, adaptive lighting for contrast optimization, and Raspberry Pi Pico for hardware control. The system is designed for small batches (up to 100 boards) and supports various solder mask colors via adaptive RGB tuning.
Key features:
- Defect detection with multi-modal pipeline (alignment, YOLO, OCR).
- SN/QR recognition and reporting.
- Gerber/BOM/placement parsing for design-aware inspection.
- Adaptive RGB lighting and polarizer for glare reduction and contrast (fine-tuned to solder mask).
- Root-cause analysis for manufacturing improvements.
- Production-ready modular architecture with Windows executable support.
- Standalone executable - no Python installation required for operators.
- Download: Get
AOI_Inspector.exefrom releases - Create Golden Sample:
golden_sample.bat PROJECT_NAME BATCH_ID COM10 - Inspect Boards:
inspect_board.bat PROJECT_NAME BATCH_ID SN001 top COM10
See working_code/README.md for detailed usage.
# Clone repository
git clone <repo_url>
cd AOI/working_code
# Install dependencies
pip install -r requirements.txt
# Run inspection
python Main_AOI.py --mode inspect --project PROJECT --batch BATCH_ID --sn SN001
# Build Windows executable
.\build_exe.ps1AOI/
├── working_code/ # ⭐ PRODUCTION CODE (modular)
│ ├── Main_AOI.py # Entry point with CLI
│ ├── hardware_controller.py # Camera & Pico control
│ ├── gerber_parser.py # KiCad file parser
│ ├── vision_utils.py # Computer vision utilities
│ ├── defect_detector.py # Multi-modal inspection
│ ├── calibration.py # Golden sample creation
│ ├── report_generator.py # JSON/CSV reporting
│ ├── build_exe.ps1 # Windows build script
│ ├── BUILD_DEPLOY.md # Deployment guide
│ └── README.md # Usage documentation
├── aoi_inspector1.py # Legacy monolithic version (reference)
├── root_cause_analyzer.py # Batch defect analysis
├── AOI_WORKFLOW.md # Detailed algorithm documentation
└── README.md # This file
Use working_code/ for production - modular, testable, with Windows executable support.
-
Camera: OBSBOT Meet 2 4K USB webcam (45x36x22mm, ~40g, f/1.8 lens). Mount on a tripod 50-100mm above the PCB stage for macro view.
-
Lighting: 3x WS2812 RGB LED rings (66mm outer diameter, 24 LEDs each, 5V, ~1.4A max). Configuration:
- Top ring: Centered around camera lens for uniform illumination.
- Left ring: 30mm above PCB edge, tilted 45° inward, ~100mm from center.
- Right ring: Mirror of left, for cross-lighting.
- Dimensions: Each ring 66mm dia., 2.75mm LED spacing; chain on single data pin.
- Power: External 5V supply; connect GND/5V/data (GP0 on Pico).
-
Motorized Polarizer: 28BYJ-48 stepper motor (ULN2003 driver) with 60mm diameter wheel holding 50x50mm linear polarizer sheet (slots for 0°/45°/90°). Dimensions: Stepper 28mm dia., 19mm height; wheel 60mm dia., 120° steps.
- Wiring: IN1-4 to GP1-4 (Pico), enable to GP5, 5V/GND to driver.
-
Microcontroller: Raspberry Pi Pico (~$5).
-
PC: Windows laptop for running Python scripts, connected via USB to Pico and camera.
-
Other: Tripod/jig for stationary positioning (3D-printable frame ~200x200mm base), USB-C cable, 5V power supply.
Overall setup with PC:
Light configuration with dimensions:
-
Python: 3.8.x (download from python.org).
- Installation: Run the installer, check "Add Python 3.8 to PATH", install for all users.
-
Dependencies: Install via
pip install -r working_code/requirements.txt(see file in repo). -
MicroPython: v1.19.1 for Pico (download UF2 from micropython.org).
-
IDE: Thonny for Pico programming (thonny.org).
-
PyInstaller (for building exe):
pip install pyinstaller
- Download executable: Get
AOI_Inspector.exefrom releases (no Python needed) - Install hardware:
- Flash Pico with
working_code/Pi_pico_code/pico_aoi_control.py - Connect camera and Pico to PC via USB
- Flash Pico with
- Run golden sample creation:
golden_sample.bat PROJECT BATCH_ID COM10 - Run inspections:
inspect_board.bat PROJECT BATCH_ID SN001 top COM10
- Clone Repo:
git clone <repo_url>or download ZIP. - Install Python 3.8: Run installer, add to PATH.
- Install Deps:
cd AOI/working_code,pip install -r requirements.txt. - Setup Pico: Flash MicroPython 1.19.1 UF2 (hold BOOTSEL, copy UF2 to RPI-RP2 drive).
- Program Pico: Open Thonny, connect Pico, open
working_code/Pi_pico_code/pico_aoi_control.py, save asmain.pyon Pico.
- Camera: Mount OBSBOT Meet 2 on tripod, 50-100mm above PCB. Connect to PC USB.
- Lights: Chain 3 WS2812 rings (top around camera, left/right tilted 45°). Connect data to GP0, GND/5V external.
- Polar Filter: Attach stepper to 60mm wheel with polarizer sheet. Mount on camera lens barrel. Connect to ULN2003, then to Pico GP1-5.
- PCB Stage: Flat surface/jig for PCBs; align fiducials under camera.
- PC Connection: Pico USB to PC (serial COM port), camera USB.
Modular Python version (working_code/):
cd working_code
# Create golden sample
python Main_AOI.py --mode golden --project PROJECT_NAME --batch BATCH_ID --serial-port COM10
# Inspect board
python Main_AOI.py --mode inspect --project PROJECT_NAME --batch BATCH_ID --sn SN001 --side top --serial-port COM10
# Show help
python Main_AOI.py --helpWindows executable (no Python needed):
REM Create golden sample
golden_sample.bat PROJECT_NAME BATCH_ID COM10
REM Inspect boards
inspect_board.bat PROJECT_NAME BATCH_ID SN001 top COM10See working_code/README.md for complete documentation.
Monolithic version (aoi_inspector1.py):
- Update paths in
aoi_inspector1.py(golden images, Gerber, BOM, pos). - Run
python aoi_inspector1.pyfor inspection (calibrates on golden, inspects boards). - Use
python root_cause_analyzer.pyfor batch reports.
cd working_code
.\build_exe.ps1Output: dist/AOI_Inspector.exe (~150-200 MB standalone executable)
See working_code/BUILD_DEPLOY.md for deployment guide.
- Pico not responding? Check COM port (Windows: Device Manager, Linux:
ls /dev/ttyACM*), verify 5V supply to LEDs. - Low contrast? Re-run golden sample calibration with better lighting conditions.
- Import errors? Use virtual environment:
python -m venv venv,venv\Scripts\activate,pip install -r working_code/requirements.txt. - Camera not found? Try different camera index:
--camera 1or check USB connection. - YOLO not working? Optional dependency - install with
pip install ultralyticsor run without ML detection. - Build fails? See working_code/BUILD_DEPLOY.md troubleshooting section.
- working_code/README.md: Complete usage guide for modular code
- working_code/BUILD_DEPLOY.md: Windows executable build & deployment
- AOI_WORKFLOW.md: Detailed algorithm and workflow documentation
- .github/copilot-instructions.md: AI assistant guidance and architecture
For questions or issues:
- Check documentation in
working_code/directory - Review workflow in
AOI_WORKFLOW.md - Open an issue on GitHub with error logs and system info