Contents
PCB (Printed Circuit Board) is well known as ‘the mother’ of all electronic products, ranging from electronic modules created by hobbyists to a turnkey professional product from a world-class manufacturer. A PCB can be printed by us at home (DIY) or by a PCB maker specialist in a factory. Depending on the complexity of its layout and functionality, a PCB could be single, double, or even multiple-layered.
A PCB typically consists of two main things: an isolated board and the conductive part (copper). The board is mainly made from Pertinax (FR2) or fiber resin glass (FR4). The first material is usually thinner and looks ‘modest’ than the thicker and ‘fancy’ one, thanks to its glossy and transparent material. The copper part is where the layout design will be printed. So, here is the ‘problem’ that comes. The PCB layout usually contains paths and pads that connect all electronic components inside.
This research is intended to build an automatic drilling machine without depending on a drill file (*.nc). Previously, we might have created the file while designing a PCB, and then taken time to set up the CNC before drilling. That is normal for drilling one PCB only. But, can you imagine if many PCBs with different designs must be drilled, especially on a tight schedule? Because every PCB change takes time for CNC configuration, this job will need extra time and may affect your schedule. So, building an automatic drilling machine is the answer. Since we want to remove the drill file dependency and reduce the CNC’s setup time, the machine should be able to detect pads before drilling. How to do that? The answer is using a camera powered by computer vision. The camera will perform as digital ‘eyes’, capturing visual surroundings and sending them to an AI-powered CPU. Here we go, our AI journey has begun. Let’s get started.
Prerequisite of PCB Pads Detection Using YOLOv8
To start our research, let’s prepare the materials such as a laptop (I use a Python-ready laptop), a camera, and a CNC machine. Since we want to observe detailed objects (pads), we need a USB webcam with a super-fine macro lens or a USB microscope. Here is my hardware setup.
- A laptop (I want to utilize its CPU), powered by Windows 11 as OS, Python as main scripting, OpenCV as Computer Vision library, and YOLOv8 nano as chosen algorithm. To install Python 3.xx and OpenCV on your Windows laptop, please refer to this article “install Python on Windows” and this article “install OpenCV on Windows“.
- A USB microscope for pad detailing observation.
- A mini CNC 3018 with minor modifications for its appearance
I assume that your CNC is ready to go, so we will focus on setting up the software.
Set up YOLOv8 nano for PCB Pads Detection
As an overview, our experiment mainly involves 5 steps: populating the dataset, labelling the dataset, training the dataset, creating a model, and then inferring PCB’s pads detection. You can repeat these steps for optimization, but it’s just an option. Here is what I’ve done at this point
- Populating the PCB dataset
Capturing pictures of as many PCBs as possible using the same inference camera. Don’t use the smartphone camera (or others) if you use the USB microscope as the inference camera. Consider that if you plan to infer with image resolution 640×640, you should capture images for the dataset with the same resolution. Below are examples of the dataset. Suggested prepared more than 200 images as the dataset for maximal impact, but I just collected 30 images for my first experiment. - Labelling the dataset
After populating the dataset, you must label the images for classification with annotation tools (CVAT, LabelImg, Roboflow, etc). For your convenience, I recommend Roboflow as your annotation tool. It’s free and has rich AI features. Let’s go to the official website, roboflow.com. Just sign in (or sign up if you haven’t registered yet), then upload your dataset in your ‘New Project’
Create a label/annotation for all of your images
Select YOLOv8 data format and choose the option ‘Download zip to computer’ - Training the dataset
You can train the dataset on your laptop or in the cloud, such as Google Colab, JupyterLab, Kaggle Kernels, etc. Google Collab provides free GPUs and TPUs, JupyterLab offers a user-friendly and already familiar environment, Jupyter Notebook, while Kaggle Kernels gives us a large community for sharing and asking. But, wrapping up all the online features, we can also train the dataset on our laptop under certain limitations, depending on its specifications. Here we go. First of all, install all necessary libraries.pip install ultralytics opencv-python numpy torch torchvision torchaudio
pip install roboflow
- Creating a model for PCB detection using YOLOv8 nano
- Inferring PCB’s pads detection
Why do we choose yolo, next tutorial, video tutorial? TBD
a Technopreneur – writer – Enthusiastic about learning AI, IoT, Robotics, Raspberry Pi, Arduino, ESP8266, Delphi, Python, Javascript, PHP, etc. Founder of startup Indomaker.com