2014年8月7日 星期四

DIY BananaPi Laser Engraver

在網路上發現一個很有趣的 DIY project

A Raspberry Pi controlled mini CNC Laser engraver

簡單的說就是拆兩部CD-RW光碟機的零件來作二軸CNC雷射雕刻機,以 Raspberry Pi 來做控制主機.

早在2011就已經有這種DIY,以Arduino作為控制主機.

激光雕刻机:废旧光驱的涅槃之路

由於這個 DIY project 實在是非常棒的機電整合實例,所以我決定自己動手做一台.

0.危險

千萬不可眼睛直視鐳射光,會造成視網模不可回復的傷害 !!!

1.硬體

兩部CD-RW光碟機.
Banana Pi
  會選擇這塊板子是因為手上剛好有一片,最重要的是硬體部份幾乎與Raspberry Pi 完全相容.
步進馬達驅動器,網路上或光華商場都買得到.
Laser diode 驅動電路相關零件,光華商場也都買得到.

2.軟體

Raspbian for Banana Pi 這是系統的OS (Linux - Debian)

以下兩個link是不同版本的 Laser Engraver 控制軟體,我目前用第二個版本.
https://github.com/iandouglas96/engravR
http://hostcode.sourceforge.net/p/raspberrypi-cnc-laser-engraver

Inkscape extension - 這是PC上的向量繪圖軟體Inkscape的外掛,用來將圖形轉換成G-code.
Laser Engraver 控制軟體就是依照G-code的指令來跑.
http://www.slackersdelight.com/instructables/laserengraver.zip

3.組裝

相關的原理及細節就不再多作描述.以下只做額外補充.

Laser Driver 原作者的電路圖有誤, E3055 (MJE3055) 的腳位標示不正確.
下圖為正確版本


Laser Driver 完成後記得調整 100 ohm 可變電阻得到合適的電流(我目前是 200mA)

步進馬達驅動器與Banana Pi pin腳位的接線

L9110S

A-1A --- 16
A-1B --- 12
B-1A --- 10
B-1B --- 8

L9110S

A-1A --- 22
A-1B --- 18
B-1A --- 24
B-1B --- 26

若馬達需要反向可由軟體控制.

Laser Driver control 腳位 3

另外,步進馬達及雷射頭需外部供電,我是用兩顆NCR18650串連供電給雷射頭,降壓至5V給L9110S. 工作時的耗電流約2A,所以散熱部份需注意.

4.軟體設定

安裝 Raspbian for Banana Pi

ssh 登入 Banana Pi
預設的 username : pi
預設的 password : bananapi

下載以下檔案

Bipolar_Stepper_Motor_Class.py
Motor_control.py
Gcode_executer.py
spiral.nc
grid.nc

其中的.nc檔就是G-code

修改 Gcode_executer.py 這裡用sprial.nc會刻出一個螺旋圖案

filename='spiral.nc'; #file name of the G code commands

GPIO.setmode(GPIO.BOARD)

MX=Bipolar_Stepper_Motor(22,18,24,26);     #pin number for a1,a2,b1,b2.  a1 and a2 form coil A; b1 and b2 form coil B

MY=Bipolar_Stepper_Motor(10,8,12,16);

Laser_switch=3;

5.執行

sudo python Gcode_executer.py

就這樣CNC Laser Engraver就動起來囉.










2014年4月8日 星期二

Linux touchscreen with tslib

Linux touchscreen 的工作分為兩大部份

1.Touchscreen driver
  通常透過SPI interface與Touchscreen A/D controller取得座標及觸控事件/壓力.
  我手邊的device是TI TSC2046 A/D controller. 座標及觸控壓力資料為12bits.
  User space則透過input device讀取資料,例如 /dev/input/event0.

2.Touchscreen library
  User space讀取到touchscreen 的資料還需要經過處理才能使用,
  例如轉換為銀幕的座標位置,濾除錯誤的資料(noise)等. 
  tslib這個library已經有這些模組功能.
  透過tslib, Graphic user interface 可以取得相對應座標的touchscreen 動作完成UI反應.

tslib

取得tslib
git clone https://github.com/kergoth/tslib.git

編譯

cd tslib

./autogen.sh

CC=mipsel-linux-uclibc-gcc AR=mipsel-linux-uclibc-ar ./configure --host=mipsel-linux --target=mipsel-linux --prefix=/usr/local/MIPSEL_UCLIBC --cache-file=/dev/null

make
make install

tslib在target的安裝位置

/phone/lib/libts-1.0.so.0.0.0
/phone/lib/ts/dejitter.so  
/phone/lib/ts/input.so    
/phone/lib/ts/linear.so    
/phone/lib/ts/pthres.so    
/phone/lib/ts/variance.so
/phone/etc/ts.conf
/phone/bin/ts_calibrate
/phone/bin/ts_print

tslib 模組

1.Variance filter - 過濾隨機的噪音資料.
2.Dejitter - 平均化X及Y軸的資料.
3.Linear - 轉換touchscreen座標至銀幕座標.

tslib ts.conf 內容

# Uncomment if you wish to use the linux input layer event interface
module_raw input

# Uncomment if you're using a Sharp Zaurus SL-5500/SL-5000d
# module_raw collie

# Uncomment if you're using a Sharp Zaurus SL-C700/C750/C760/C860
# module_raw corgi

# Uncomment if you're using a device with a UCB1200/1300/1400 TS interface
# module_raw ucb1x00

# Uncomment if you're using an HP iPaq h3600 or similar
# module_raw h3600

# Uncomment if you're using a Hitachi Webpad
# module_raw mk712

# Uncomment if you're using an IBM Arctic II
# module_raw arctic2

module pthres pmin=1
module variance delta=30
module dejitter delta=100
module linear

tslib 環境變數

tslib根據以下的環境變數取得模組及設定檔案(ts.conf / pointercal), ㄧ定要正確設定.

export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_CONFFILE=/phone/etc/ts.conf
export TSLIB_PLUGINDIR=/phone/lib/ts
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_CALIBFILE=/phone/etc/pointercal 

tslib 校正(ts_calibrate)

執行 /phone/bin/ts_calibrate
依 左上, 右上, 右下, 左下, 中間 的順序觸控 touchscreen 就完成校正.
校正資料會儲存在/phone/etc/pointercal 

tslib 測試(ts_print)

執行 ts_print 會讀取/phone/etc/pointercal, 在 console 上顯示目前觸控的銀幕座標