Skip to content

RolandWa/AOI

Repository files navigation

DIY AOI PCB Inspection System

Overview

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.

Quick Start

For Operators (No Python Required)

  1. Download: Get AOI_Inspector.exe from releases
  2. Create Golden Sample: golden_sample.bat PROJECT_NAME BATCH_ID COM10
  3. Inspect Boards: inspect_board.bat PROJECT_NAME BATCH_ID SN001 top COM10

See working_code/README.md for detailed usage.

For Developers

# 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.ps1

Project Structure

AOI/
├── 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.

Requirements

Hardware

  • 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:

Software

  • 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

Installation

For Operators (Production Use)

  1. Download executable: Get AOI_Inspector.exe from releases (no Python needed)
  2. Install hardware:
    • Flash Pico with working_code/Pi_pico_code/pico_aoi_control.py
    • Connect camera and Pico to PC via USB
  3. Run golden sample creation: golden_sample.bat PROJECT BATCH_ID COM10
  4. Run inspections: inspect_board.bat PROJECT BATCH_ID SN001 top COM10

For Developers

  1. Clone Repo: git clone <repo_url> or download ZIP.
  2. Install Python 3.8: Run installer, add to PATH.
  3. Install Deps: cd AOI/working_code, pip install -r requirements.txt.
  4. Setup Pico: Flash MicroPython 1.19.1 UF2 (hold BOOTSEL, copy UF2 to RPI-RP2 drive).
  5. Program Pico: Open Thonny, connect Pico, open working_code/Pi_pico_code/pico_aoi_control.py, save as main.py on Pico.

Hardware Setup

  1. Camera: Mount OBSBOT Meet 2 on tripod, 50-100mm above PCB. Connect to PC USB.
  2. Lights: Chain 3 WS2812 rings (top around camera, left/right tilted 45°). Connect data to GP0, GND/5V external.
  3. Polar Filter: Attach stepper to 60mm wheel with polarizer sheet. Mount on camera lens barrel. Connect to ULN2003, then to Pico GP1-5.
  4. PCB Stage: Flat surface/jig for PCBs; align fiducials under camera.
  5. PC Connection: Pico USB to PC (serial COM port), camera USB.

Running the System

Using Production Code (Recommended)

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 --help

Windows 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 COM10

See working_code/README.md for complete documentation.

Using Legacy Code (Reference Only)

Monolithic version (aoi_inspector1.py):

  1. Update paths in aoi_inspector1.py (golden images, Gerber, BOM, pos).
  2. Run python aoi_inspector1.py for inspection (calibrates on golden, inspects boards).
  3. Use python root_cause_analyzer.py for batch reports.

Building Windows Executable

cd working_code
.\build_exe.ps1

Output: dist/AOI_Inspector.exe (~150-200 MB standalone executable)

See working_code/BUILD_DEPLOY.md for deployment guide.

Troubleshooting

  • 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 1 or check USB connection.
  • YOLO not working? Optional dependency - install with pip install ultralytics or run without ML detection.
  • Build fails? See working_code/BUILD_DEPLOY.md troubleshooting section.

Documentation

Support

For questions or issues:

  1. Check documentation in working_code/ directory
  2. Review workflow in AOI_WORKFLOW.md
  3. Open an issue on GitHub with error logs and system info

About

AOI for PCBA board

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors