---
title: "PCB CNC-Plotter"
tags: PCB, CNC, hackpad
---
# PCB CNC-Plotter
> [點此觀看原始內容](https://openlabtaipei.hackpad.tw/Fgt1eKIxqRq)
PCB CNC-Plotter
## 緣起
因為洗電路板很麻煩,曬電路板又很容易失敗,原本是想 DIY 一台 PCB CNC 來協助製作電路板,但是 CNC PCB 的速度太慢了,但是看到 Dirk Herrendoerfer 先生製作的 PCB CNC-Plotter 計畫,驚為天人,所以想要開始製作這個工具。
## Source
[https://github.com/dherrendoerfer/uCNC_controller/tree/master/Extras](https://github.com/dherrendoerfer/uCNC_controller/tree/master/Extras)
## 紀錄
#### 影片
[http://www.youtube.com/watch?v=P0nTmpGKBTo&list=PLotvT33qzzfLRwgobtJN5hoL4Ef7nsFFY&index=6](http://www.youtube.com/watch?v=P0nTmpGKBTo&list=PLotvT33qzzfLRwgobtJN5hoL4Ef7nsFFY&index=6)
### 簡介
[uCNC_controller 是](https://openlabtaipei.hackpad.com/fZSDPCTcDWb?src=email-line&eid=H6jaxXNOIXD#:-1301350080)一個 g-code 解碼控制器的應用程式,它是用於 Arduino 的平台上。它解碼 g-code的命令並且從而去控制 unipolar 步進馬達(3)、一些數位輸出(2)、伺服馬達(1)。
### 照片
[Nick Kavalieris 製作的版本](https://plus.google.com/photos/106587142561420065858/albums/5965825456202767073?sort=1)。
## 列印過程
列印過程:
使用 eagle 畫好電路板
點選 cam job ,在 output 的 device 中,選擇 HPGL。在 pen 的 diameter 中,輸入0.4mm。
儲存
## 軟體
#### 在 Arduino nano w. ATMEGA328P 上的腳位設定
------------>--------------------------------------------
- Stepper 1: 8,9,10,11
- Stepper 2: 4,5,6,7
- Stepper 3: A5,A4,A3,A2 (digital out 19,18,17,16)
- 12V out 1: 2
- 12V out 2: 3
- Laser out: 13
- Servo out: 12
- Unused : A0,A1,A6,A7 (A6 and A7 cannot be used as output)
## 硬體
#### 材料:
- step motor: 28YBJ-48([pt3影片](https://www.youtube.com/watch?v=kcXlak7RNV0&list=PLotvT33qzzfLRwgobtJN5hoL4Ef7nsFFY#t=495) 8:24)
- Driver IC: ULN2004A 6-15V([從影片10:51提到](https://www.youtube.com/watch?v=QPSfblHRvac))
- ULN2003A 5V
- Arduino nano
- 電容、78xx IC(可能是7805 for step motor)
- [電路板](https://www.youtube.com/watch?v=kcXlak7RNV0&list=PLotvT33qzzfLRwgobtJN5hoL4Ef7nsFFY#t=495)(8:01)
- 5mm 光軸
- 6*5 mm 銅管
- [staedtler 0.4 mm 油性筆](http://www.staedtler.com/en/products/markers-refill-ink/universal-pens/lumocolor-permanent-pen-313-permanent-universal-pen-s/#id=35&tx_solr[q]=Lumocolor%20%C2%AE%20permanent%20pen%20313)
- nylon string rated at >50N
- 伺服馬達(數位式)
You need 2x ULN2003 or 2004, one 7805 regulator, two capacitors. The power regulator goes into the upper left. If you want to use the laser you also need a mosfet and a resistor. If someone is a master at eagle I would really love to have a component layer for the .brd?
#### 零件清單:
| 5V版本 (Vin 7~12V) | 6~15V版本(Vin 12~20V) | | 備註 |
| --- | --- | --- | --- |
| ULN2003A x2 | ULN2004A x2 | | |
| 8x2 IC座 x2 | 8x2 IC座 x2 | | |
| LM7805 | LM78xx | 視馬達電壓選用 | |
| 100uF 16v電容x2 | 100uF 25v電容x2 | | |
| 杜邦(公)x很多 | 杜邦(公)x很多 | | |
| JST 5pin x3 | JST 5pin x3 | 5線步進馬達 | |
| Molex 2pin x1 | Molex 2pin x1 | 雷射雕刻供電 | |
| JUMMPER x2 | JUMMPER x2 | | |
[uCNC controller 電路板(UNO版)](https://drive.google.com/folderview?id=0B6urxfrrbfsXVXRmZ3NTcnM3aDA&usp=sharing)阿助設計。 PS: 還沒洗出來測試

## 文件
#### 裝置特定的 g code 命令
&0:calibratePattern
&1: slackPattern
&2:slackPattern2
&99:輸出硬體設定
M150:設定 Z 軸模式
[g code](http://reprap.org/wiki/G-code) 使用資料
#### 模式
定義模式,透過可以寫程修改狀態的控制器,來如何使用步進馬達、伺服馬達和雷射驅動。
模式0:步進馬達 1 是 X 軸
步進馬達 2 是 Y 軸
步進馬達 3 是 Z 軸
伺服馬達是主軸轉速
雷射是由主軸驅動
模式1:步進馬達 1 是 X 軸
步進馬達 2 是 Y 軸
步進馬達 3 是 Y 軸
伺服馬達是 Z 軸 (down for Z<0)
雷射是 Z 軸 (on for Z<0)
模式2:步進馬達 1 是 X 軸
步進馬達 2 是 Y 軸
步進馬達 3 是 Y 軸
伺服馬達是 Z 軸 (+90 to -90)
雷射是由主軸驅動
模式3:步進馬達 1 是 X 軸
步進馬達 2 是 Y 軸
步進馬達 3 是 Y 軸
伺服馬達是工具
雷射是 Z 軸 (on for Z<0)
範例:
M150 S2 ;設定為模式 2
#### 繪製電路圖使用流程
1. 使用 eagle 設計電路圖。
2. 選擇 file > cam processor ,把 device 選項為 hpgl ,diameter 為 0.4,匯出檔案。
3. 使用[Hp2xx](http://www.gnu.org/software/hp2xx/) ,轉成 nc gcode。
4. 打開 [ardGcodeWriter.py](https://docs.google.com/file/d/0B1DQmCDF0I3kWDhXZGlGLXVEaWs/edit)。
5. 讀入檔案。
6. 列印。
另一種獲得 nc g code 的方法,建立一個 [Gerber](http://zh.wikipedia.org/wiki/Gerber) 檔案,然後使用 gerber2gcode 得到。
hp2xx -m nc -t <input file>
NOTE: hp2xx must be compiled with nc support.?
#### 硬體安裝
尼龍線與馬達
The nylon is wound around the steppers 3 times - that is ok for the needed friction to move, but if you run into the ends, it won't damage anything. If the stepper rod is too smooth you can apply a thin layer of plasticote or thin glue and let that dry completely. A touch up with a file or metal brush would also do the trick.?
### 檔案結構
1. uCNC_controller:主程式
2. nCNC_builtin:
3. uCNC_gcode:
資訊經過轉換後
4. uCNC_motor:
馬達輸出的處理
5. uCNC_prase:解析
6. uCNC_stepper:步進
7. uCNC.h:
### 問題
- 雖然有找到程式碼、電路板圖與3D檔案,但是不知道要用到哪些電子零件。
> 已解決,請見上方的零件清單。
> [name=鄭鴻旗]
- 3D 檔案有破面,列印出來的物件很薄,有點怪怪的。
> 決定重劃,因為修補時間過長。
> [name=鄭鴻旗]
- 使用哪種油性筆?(雄獅奇異筆,筆劃 1mm ,筆桿上圓直徑 11.3mm,下圓直徑10.8mm)
- 步進馬達只會同一方向旋轉。
> ㄚ,鴻旗你的問題不知道和我之前遇到的有沒有一樣,我之前也是用那顆步進馬達透過 uln2003 驅動,這顆馬達消耗的電流算蠻小的,我是用 Arduino 裏面現成的步進馬達函數庫,發生了兩個狀況,(1)扭力很低還會抖動 (2) 永遠只有正轉,無法逆轉。後來用示波器看了一下驅動波形的順序,(暗幹一聲 TMD)(鉛筆壹)
> [name=鄭鴻旗]
> 被這顆步進馬達婊了,驅動的波形順序有誤,解法有兩個,可以更改其中兩條線的順序或是修改步進馬達的函數程式。因為差異在 2相和 1-2相驅動的問題。原作者如果不是用這顆馬達不會遇到這個問題。
> [name=鄭鴻旗]
> (鉛筆壹)
> [name=鄭鴻旗]
> Arduino 的 stepper 函數用的驅動是2相激磁,順序是 1010-0110-0101-1001 因為 28BYJ-48 是 1-2相激磁,要改成 1100-0110-0011-1001 這樣的順序才能正逆轉。不想改函式庫程式就改接線順序。
> [name=鄭鴻旗]
> (鉛筆壹)
> [name=鄭鴻旗]
> 如果要用 1-2 相激磁增加一個驅動方式 1000-1100-0100-0110-0010-0011-0001-1001 這樣就可以,用 1-2 相激磁可以把步進角度再縮小一半,轉一圈的總步數為2相激磁的兩倍。
> [name=鄭鴻旗]
> (鉛筆壹)
> [name=鄭鴻旗]
> 如果 uln2003 驅動板上面有四顆 led 燈號,寫一小段程式,每一秒前進一步,就可以看出激磁的順序了,那個燈號是拿來 debug 用可不是亮好看的。
> [name=鄭鴻旗]
> (鉛筆壹)
> [name=鄭鴻旗]
> 謝謝鉛筆壹兄提醒,我後來把腳位變動,現在可以控制步進馬達正反轉了。腳位改為 Stepper myStepper1(stepsPerRevolution, 8,10,11,9); Stepper myStepper2(stepsPerRevolution, 4,6,7,5);
> [name=鄭鴻旗]
> (紅旗)
> [name=鄭鴻旗]
- 可以送 g-code 去控制 x, y 馬達移動,但是抓不到要領去控制 Z 軸的伺服馬達
> int motorMode = 1; 改成模式 1
> [name=鄭鴻旗]
- 輸入&0, &1 命令,只回得到 ok,沒有其他訊息。
> 把 註解取消掉
> [name=鄭鴻旗]
> /\* Development functions - broken code*/
> [name=鄭鴻旗]
> [#define](https://openlabtaipei.hackpad.tw/ep/search/?q=%23define&via=Fgt1eKIxqRq) BUILTIN 1
> [name=鄭鴻旗]
## 改進
1. [魚線專用絞盤](http://www.thingiverse.com/thing:34116) (3D 列印出來後比對,不適合使用),原本的設計是直接把魚線繞在步進馬達的轉軸上,但是覺得應該有更好的方式安裝與運作,所以增加這部份。
2. 改成皮帶帶動的方式?
> 不列入,因為會增加製作成本。
> [name=鄭鴻旗]
3. 筆桿機構部份改進,因為在台灣容易買到的油性筆與原作者所使用的不同,所以必須改變設計。
> [http://www.thingiverse.com/thing:378820](http://www.thingiverse.com/thing:378820) 曾德益所設計的版本。
> [name=鄭鴻旗]
4. 筆得加上彈簧頂住,下筆的時候就可以下超過行程,彈簧也會起緩衝作用,遇上 pcb 不平也能安穩抵住,pcb 就不用像雕刻那樣要用雙面膠從背部固定,只需要在外側用膠帶貼一下即可。(鉛筆壹)
5. 加上可讀記憶卡的 lcd 控制器,來離線列印電路板,不用在列印的過程中一直電腦連線。
> A. PIN腳應該會不夠用,加SD卡要犧牲一組步進馬達(使用10,11,12,13),Z軸應該只能用SERVO,或拿來當雷雕機。
> [name=鄭鴻旗]
> B. ULN2003A可換成ULN2803A直接控制2顆馬達。
> [name=鄭鴻旗]
> C.LCD要走I2C or 不用LCD固定檔名放在SD卡,開機直接讀。
> [name=鄭鴻旗]
> (以上是阿助提到需要變動的部份)
> [name=鄭鴻旗]
6. 遠端送墨或是像鋼筆用的卡式墨匣。
7. 可換式筆尖:印久了筆尖會開花,以前筆式繪圖機的筆好像有陶瓷筆尖,印久了比較不會開花,或是下筆控制程式有加減速功能。
3d 列印零件改進

[http://www.thingiverse.com/thing:725706](http://www.thingiverse.com/thing:725706)

[http://www.thingiverse.com/thing:950749](http://www.thingiverse.com/thing:950749)

[http://www.thingiverse.com/thing:18678](http://www.thingiverse.com/thing:18678)
[Enlarged Rostock Carriage V1.2 for 12mm smooth rod](http://www.thingiverse.com/thing:80425/#files)
檢討-2014-9-10
## 參考資料
#### 夾筆的機構
[http://www.thingiverse.com/thing:24435](http://www.thingiverse.com/thing:24435)
[http://www.thingiverse.com/thing:5288](http://www.thingiverse.com/thing:5288)
[http://www.thingiverse.com/thing:3593](http://www.thingiverse.com/thing:3593)
[http://www.thingiverse.com/thing:47696](http://www.thingiverse.com/thing:47696)
[http://www.thingiverse.com/thing:10992](http://www.thingiverse.com/thing:10992) (彈簧)
[http://www.thingiverse.com/thing:47696](http://www.thingiverse.com/thing:47696)
[http://www.thingiverse.com/thing:31983](http://www.thingiverse.com/thing:31983)
[http://www.thingiverse.com/thing:230152](http://www.thingiverse.com/thing:230152) (使用教學)
[http://reprap.org/wiki/Plotting](http://reprap.org/wiki/Plotting)
結構
[http://www.thingiverse.com/thing:182675](http://www.thingiverse.com/thing:182675)
[http://www.thingiverse.com/thing:30961](http://www.thingiverse.com/thing:30961)
[https://256.makerslocal.org/wiki/index.php/Makers\_mantis\_cnc](https://256.makerslocal.org/wiki/index.php/Makers_mantis_cnc)
[http://www.thingiverse.com/thing:6115](http://www.thingiverse.com/thing:6115)
[http://www.thingiverse.com/thing:344996](http://www.thingiverse.com/thing:344996)
[http://www.thingiverse.com/thing:945156](http://www.thingiverse.com/thing:945156)
[http://www.thingiverse.com/thing:18678](http://www.thingiverse.com/thing:18678)
相似計畫
[http://junkplusarduino.blogspot.tw/p/svg-image-plotter.html](http://junkplusarduino.blogspot.tw/p/svg-image-plotter.html)
[http://www.instructables.com/id/X-Y-Plotter-1/](http://www.instructables.com/id/X-Y-Plotter-1/)
軟體
[https://docs.google.com/file/d/0B1DQmCDF0I3kcUxraTJITWpPV0E/edit](https://docs.google.com/file/d/0B1DQmCDF0I3kcUxraTJITWpPV0E/edit)
硬體
[sg90 伺服馬達 datasheet](https://www.censa.mx/imgs/prods/18022004/docs/doc1-1401817609.pdf)
[28byj-48 datasheet](http://robocraft.ru/files/datasheet/28BYJ-48.pdf)