# The "Holy Grail" 3040L CNC (PCB Specialist)

**Project Goal:** A high-precision, desktop CNC machine optimized for PCB manufacturing (0.8mm drilling, isolation routing) and light aluminum work.  
**Architecture:** Raspberry Pi (gSender) via WiFi → **PiBot FluidNC Controller** → External Drivers → Industrial Mechanics.

---

## 1. Bill of Materials (BOM)

### Mechanical Base
*   **Frame Kit:** CNC 3040L (6061/6063 Hard aluminum alloy).
*   **Table material:** 320 * 520mm (20mm aluminum alloy T table).
*   **Engraving area：** 260*380*110mm
*   **Z-Axis Stroke：** 110mm
*   **Drive System:** 1605 Ball Screws (16mm, 5mm pitch) and HG20 Square Linear Rails on all axes.
*   **Coupling:** 3x **Plum couplings**.

![CNC 3040L Linear Rail Frame Assembly](images/CNC_3040L_Frame.png)

### Spindle & VFD
*   **Spindle:** 1.5kW, 220V, 5A, 24,000 RPM (400Hz) Water-Cooled Spindle (Diameter 80mm).
*   **VFD:** Huanyang HY01D523B (1.5kW, 220V).
*   **Collet System:** **ER11** (Upgrade to AAA-Precision collets recommended for PCB work).
*   **Water pump:** 80W, 6M lift with 8mm OD / 6mm ID piping.

![Spindle, VFD, and Submersible Pump Kit](images/Spindle_VFD_Pump.png)

### Control Electronics
*   **Controller:** [PiBot FluidNC GRBL Laser CNC Controller V4.7](https://www.pibot.com/pibot-fluidnc-grbl-cnc-controller-v4-7). 
    *   *More info:* [wiki.fluidnc.com](http://wiki.fluidnc.com/en/hardware/existing_hardware#pibot-fluidnc-grbl-cnc-controller-v47)
    *   *Schematics/PCB:* [oshwlab.com](https://oshwlab.com/pi3d14/pibot-fluidnc-grbl-cnc-controller-v4-7a)
*   **Stepper Drivers:** 3x **DM542** (Digital External Drivers).
*   **Motors:** 3x **NEMA 23** 57BYGH76 Stepper Motors (3.0A, 1.5Nm torque).
*   **Limit Sensors:** 3x **LJ12A3-4-Z/BX** (Inductive NPN NO).
*   *Note: The PiBot V4.7 features built-in RS485 module and 0-10V analog output and opto-isolated inputs, eliminating the need for separate converter modules and isolation boards.*

![PiBot FluidNC GRBL Laser CNC Controller V4.7B top](images/PiBot_Board_top.jpg)  
![PiBot FluidNC GRBL Laser CNC Controller V4.7B bottom](images/PiBot_Board_bottom.png)
### Power System (Dual PSU)
*   **Motion Power:** Mean Well **LRS-350-24** (24V, 350W) for Drivers.
*   **Logic Power:** Mean Well **MDR-20-24** (24V, 20W DIN Rail) for PiBot Board & Sensors.

### Safety & Control Box
*   **Main Switch:** Big Rotary Isolator (Cuts L & N).
*   **EMI Filter:** 250V 10A + IEC C19 Socket + T10A Fuse.
*   **Main Contactor:** 4-Pole AC Contactor (24V DC Coil).
*   **VFD Breaker:** Jotta **C10** (2-Pole DIN Rail MCB).
*   **Buttons:** Green (Start NO), Red (Stop NC), E-Stop (Mushroom NC).
### Cooling & Accessories
*   **Coolant:** Distilled Water (80%) + Automotive Antifreeze G11/G12 (20%).
*   **Flow Sensor:** **HT-30** (G1/2") wired to VFD "External Fault".
*   **Probe:** **GX12-2** Connector + Touch Plate.
*   **Laser (Optional):**
    *   **405nm (500mW):** For curing Solder Mask / Dry Film Photoresist.
    *   **Buck Converter:** 24V to 12V (if laser is 12V).
    
---

## 2. Wiring Schematics

### A. Power Flow (Input)
1.  **Wall (230V)** → **IEC Filter** → **Main Rotary Switch**.
2.  **Rotary Switch** → **Small 20W PSU** (Logic Power).
3.  **Small PSU (24V)** → **Start/Stop Buttons** → **Contactor Coil**.
4.  **Contactor (Power Contacts)** → **Big 350W PSU** & **VFD Breaker**.
5.  **VFD Breaker** → **VFD Input**.

### B. PiBot V4.7 to DM542 Drivers
The PiBot V4.7 uses 5V logic shifting for axis signals. The following diagram illustrates the **Common Ground (GND)** wiring logic used in this build.

![PiBot V4.7 to DM542 Drivers](images/PiBot_to_DM542_wiring.png)

| PiBot Axis Header | Wire Color | DM542 Input | Function |
| :--- | :--- | :--- | :--- |
| **STP** | **Green** | **PUL+** | Step Signal |
| **DIR** | **Blue**  | **DIR+** | Direction Signal |
| **EN**  | **White** | **ENA+** | Enable Signal (Optional) |
| **GND** | **Black** | **PUL- / DIR- / ENA-** | Common Ground |

### C. DM542 DIP Switches
*Settings optimized for **NEMA 23** and **High Precision PCB Work (1/16 Microstepping)**.*

**1. Current Settings (SW1 - SW3):** Target **2.84A Peak**.
*   **SW1: ON, SW2: ON, SW3: OFF** (Recommended Start).

**2. Idle Current (SW4):**
*   **SW4: OFF** (Half Current - reduces heat when the machine is idle).

**3. Microstepping (SW5 - SW8):** Target **3200 Pulse/Rev**.
*   **SW5: ON, SW6: ON, SW7: OFF, SW8: ON** (Result: **640 Steps/mm** with 1605 screw).

### D. Spindle Control (0-10V Direct)
The PiBot V4.7 includes an integrated 0-10V circuit.

**Option A: 0-10V Signal Connection (5-Core Shielded Cable)**
Locate the **10V Spindle Interface** terminal on the PiBot.

| PiBot Output | VFD Terminal | Function |
| :--- | :--- | :--- |
| **0-10V** | **VI** | Analog Voltage Control |
| **GND** | **ACM** | Analog Common |
| **out1/Fwd** | **FOR** | Forward Signal |
| **out2/Rev** | **REV** | Reverse Signal |
| **out common** | **DCM** | Digital Common |

**Option B: RS485 Implementation Detail (2-Core Shielded Twisted Pair Cable)**
It allows for digital precision (no voltage drift), real-time RPM feedback, and the ability to monitor VFD temperature and current via the FluidNC Web UI.  
To ensure zero-error communication at 24,000 RPM, the RS485 cable must be paired as follows:

1. **Signal Pair:** [RS+] and [RS-] must share a single twisted pair to maximize differential noise cancellation.
2. **Shielding:** The drain wire/braid is connected to the VFD Earth terminal (PE) only. The PiBot side of the shield is left floating (cut and insulated) to prevent ground loops.
3. VFD Config (Huanyang):
Set PD001=2 and PD002=2 for RS485 control.
Set PD163=1, PD164=1, PD165=3 for 9600 baud communication.
4. Wiring:
PiBot [A] → VFD [RS+]
PiBot [B] → VFD [RS-]
Shield → VFD PE (Earth Ground screw)

### E. Probe (GX12)
*   **Pin 1 (GND):** Alligator Clip.
*   **Pin 2 (Signal):** Touch Plate (Connect to PiBot Probe Input).
*   *Safety:* Confirm continuity from spindle bit to ground before probing.

---

## 3. Cables & Connectors

Proper shielding is critical to prevent EMI from the VFD from interfering with the limit sensors or stepper signals.

*   **Spindle:** **GX20-4** (Double shielded **TRVVP 4x1.5mm²**). *Note: High-flex, oil-resistant for drag chains.*
*   **Motors:** **GX16-4** (Double shielded **TRVVP 4x0.5mm²** for moving parts and **RVVP 4x0.5mm²** for the rest).
*   **Sensors/E-Stop:** **GX12-3/GX12-2** (Shielded **RVVP 0.3mm²**).

| TRVVP (High-Flex Drag Chain) | RVVP (Standard Shielded) |
| :---: | :---: |
| ![TRVVP Cable Section](images/TRVVP_cable.png) | ![RVVP Cable Section](images/RVVP_cable.png) |

---

## 4. FluidNC Installation & Configuration

1.  Download the latest release from [FluidNC GitHub](https://github.com/bdring/FluidNC/releases/latest).
2.  Unzip and run:
    ```bash
    ./erase.sh
    ./install-wifi.sh
    ./install-fs.sh
    ```
3.  Use `fluidterm.sh` to set your WiFi:
    ```
    $STA/SSID=MyWifiSSID
    $Sta/Password=YourPassword
    ```
4.  **Configuration:** Upload your `config.yaml` using the Web UI (usually at `192.168.1.xxx` or via `CTRL+U` in terminal).
    *   *Note:* Ensure the Pin mapping in `config.yaml` matches the PiBot V4.7 PCB silkscreen (e.g., Step pins, Dir pins, and the 0-10V pin).

---

## 5. First Run Checklist

1.  **Unlock:** Send `$X` to clear `<Alarm>`.
2.  **Sensors:** Trigger limit switches manually; verify `Pn:X/Y/Z` in console.
3.  **Spindle VFD:**
    *   Program VFD parameters (see Section 7).
    *   Check Water Flow
    *   Test `M3 S12000` for 50% speed (200Hz).
4.  **Probe:** Test contact with a multimeter/console before performing a Z-zero.

---

## 6. Complete VFD Settings List (Huanyang HY01D523B)
For **1.5kW, 220V, 400Hz** spindle:

| Parameter | Description | Setting | Notes |
| :--- | :--- | :--- | :--- |
| **PD013** | Factory Reset | **8** | Clear old data first. |
| **PD005** | Max Freq | **400.0** | |
| **PD004** | Base Freq | **400.0** | **CRITICAL:** Do not leave at 50/60. |
| **PD003** | Main Freq | **400.0** | |
| **PD011** | Min Freq | **100** | Lowest spped 6,000 RPM Safety Limit |
| **PD141** | Rated Voltage | **220** | |
| **PD142** | Rated Current | **5** | |
| **PD143** | Motor Poles | **2** | High-speed CNC spindles are 2-pole. |
| **PD144** | Rated Motor Revolution | **3000** | As calculated above (3000 @ 50Hz). |
| **PD002** | Freq Source | **1** | External Terminal (0-10V). |
| **PD001** | Commands Source | **1** | External Terminal (FOR/REV). |
| **PD070** | Analog Input | **0** | **0-10V** (Standard for PiBot). |
| **PD072** | High Analog Freq | **400.0** | Scales the knob so "Max" = 400Hz. |

Set the jumper **J1** to short pins **1** and **2** for using the external power supply (0-10V comming from the PiBot Controller). The onboard potentiometer will be disabled.

*For advanced spindle control, see [FluidNC Spindle Config Documentation](http://wiki.fluidnc.com/en/config/config_spindles).*
