***********************
從淘寶上買了光驅式激光雕刻機DIY,目前還沒有能力裝上。相比安裝要求,配套教程確實不夠詳細。雖然不需要知道原理,只知道步驟也可以完成雕刻機安裝,但是步驟不清楚,另外自己對arduino和easydriver也不是很熟悉,所以難上加難。
為了不半途而廢,所以打算邊學基礎邊實踐,最終完成對激光雕刻機的理解和實踐。
***********************
選擇easydriver作為起點,是因為它式連接 arduino 和 步進電機的 關鍵核心。
機械坊已經有兩個例子,
*******
http://www.zg4o1577.cn/bbs/dpj-47861-1.html
微型CNC制作基于開源項目GRBL
這個例子就是最終要完成的,只是覺得該例子對于基礎差的不夠詳細,而且步驟有跳躍,一上來就按照該教程失敗率較高。
*******
http://www.zg4o1577.cn/bbs/dpj-47860-1.html
arduino當Gcode解釋程序(CNC)
這個例子雖然有用,但對新手來說更不完整,新手無從下手。
********
直接找到easydriver的老家,
http://schmalzhaus.com/EasyDrive ... DriverExamples.html
果然提供新手的例子(并推薦進階可以參考blogspot 上面的turorial,遺憾的是打不開,不知道是不是與長城有關)
第一個例子是 設置,怎樣連線
***************************************
Example 1: Basic Arduino setup
101913v5bca93m5c55zd99.png (63.29 KB, 下載次數: 166)
下載附件
2016-4-9 22:53 上傳
上面的示意圖可以使用 Arduino設計助手來畫,剛剛才搜到。
為什么這樣連接,需要看easydriver 示意圖
102042czv9e6r1jkkkpsy1.png (239.2 KB, 下載次數: 150)
下載附件
2016-4-9 22:53 上傳
從上圖可以看出,步進電機是4根線,選擇2相4線類型,淘寶上非常多。接線順序示意圖很清晰很簡單。
這里有個事項,easydriver的排針是沒有焊接上,需要玩家自己焊接,這時就有兩種選擇:
1、仿照上面的示意圖(使用面包板)
102626qo2cd87v3yvvyqc8.jpg (199.25 KB, 下載次數: 144)
下載附件
2016-4-9 22:53 上傳
2、不使用面包板
102742ooi6tiuv4v6iikzn.jpg (42.4 KB, 下載次數: 145)
下載附件
2016-4-9 22:53 上傳
需要仔細看,就是排針的方向,排針焊接在正面,就是使用面板板;焊接在反面,就不用面包板。
步進電機需要單獨供電,6~30v。
******************************************
例子1的目的在于連線,代碼反而很簡單,
void setup() {
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
}
void loop() {
digitalWrite(9, HIGH);
delay(1);
digitalWrite(9, LOW);
delay(1);
}
pin8 是方向控制,pin9是脈沖控制,內容解釋可以看原文,這里不翻譯了。
除了這里
Well, with the STEP signal 1ms high and 1ms low, each complete pulse will take 2ms of time. Since there are 1000ms in 1 second, then 1000/2 = 500 microsteps/second.
脈沖信號是 1ms 高電平 1ms 低電平,所以一個完整的脈沖是 2ms。1秒 等于 1000ms,所以 1秒 / 2ms = 500 次脈沖 / 秒。
這樣第一例子就完成了。
例子1的測試效果并不是很好,可能與我使用的步進電機有關,我是淘寶上買的12元一只的,個頭比單片機配套的那種大很多。最大的問題是發熱。
例子2
- int Distance = 0; // Record the number of steps we've taken
-
- void setup() {
-
- pinMode(8, OUTPUT);
-
- pinMode(9, OUTPUT);
-
- digitalWrite(8, LOW);
-
- digitalWrite(9, LOW);
-
- }
-
-
- void loop() {
-
- digitalWrite(9, HIGH);
-
- delayMicroseconds(100);
-
- digitalWrite(9, LOW);
-
- delayMicroseconds(100);
-
- Distance = Distance + 1; // record this step
-
- // Check to see if we are at the end of our move
-
- if (Distance == 3600)
-
- {
-
- // We are! Reverse direction (invert DIR signal)
-
- if (digitalRead(8) == LOW)
-
- {
-
- digitalWrite(8, HIGH);
-
- }
-
- else
-
- {
-
- digitalWrite(8, LOW);
-
- }
-
- // Reset our distance back to zero since we're
-
- // starting a new move
-
- Distance = 0;
- // Now pause for half a second
- delay(500);
- }
- }
復制代碼
代碼清晰簡潔,沒有算法和繞彎,就像看說明書一樣。
這段代碼的執行效果比較好,正轉一下(3600個脈沖)然后反轉。
問題也是,半分鐘easydriver就有些燙了,感覺不能適應功率稍微大一些的電機。下一個筆記試試TB6560。
*******************************
找到問題:easydriver 發燙
后面例子都不需要更換電路圖
第三個例子使用了一個庫,需要另外安裝(非常簡單,下載AccelStepper庫,然后放到 arduino安裝目錄Arduinolibraries 下就可以了
AccelStepper-1.39.zip
(73.9 KB, 下載次數: 23)
2016-4-9 22:49 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
只有安裝了上面的庫,才可以運行例子3
- #include
-
-
- // Define a stepper and the pins it will use
-
- AccelStepper stepper(1, 9, 8);
-
-
- int pos = 3600;
-
-
- void setup()
-
- {
-
- stepper.setMaxSpeed(3000);
-
- stepper.setAcceleration(1000);
-
- }
-
-
- void loop()
-
- {
-
- if (stepper.distanceToGo() == 0)
-
- {
-
- delay(500);
-
- pos = -pos;
-
- stepper.moveTo(pos);
-
- }
-
- stepper.run();
-
- }
復制代碼
上面的代碼暫時不打算仔細研究,
如果要深入理解的話,可以到 http://www.airspayce.com/mikem/arduino/AccelStepper/index.html
上看例子。
****************************
在使用時,發現如果電機不固定,根據牛頓作用力反作用力定理,轉到效果不佳。
另外查到使用電機步距角是 3.75度,轉一圈96步,所以轉的圈數比描述的多一倍(例子使用1.8 度)。
因為自己焊接水平不到家,所以使用時出現由于 easydriver 焊接不好而產生的故障,多準備幾個互相校準還是有用的。
第四個例子需要兩個電動機,如下示意圖,其實一個電機也可以,只不過把pin8 移到 pin6 ,pin9 移到 pin7 ;就可以作出,更簡單。
例子4和例子3 都需要 AccelStepper 庫。
141457mpjl646ayhxwyerw.png (75.41 KB, 下載次數: 161)
下載附件
2016-4-9 22:53 上傳
- #include
-
-
- // Define two steppers and the pins they will use
-
- AccelStepper stepper1(1, 9, 8);
-
- AccelStepper stepper2(1, 7, 6);
-
-
- int pos1 = 3600;
-
- int pos2 = 5678;
-
-
- void setup()
-
- {
-
- stepper1.setMaxSpeed(3000);
-
- stepper1.setAcceleration(1000);
-
- stepper2.setMaxSpeed(2000);
-
- stepper2.setAcceleration(800);
-
- }
-
-
- void loop()
-
- {
-
- if (stepper1.distanceToGo() == 0)
-
- {
-
- pos1 = -pos1;
-
- stepper1.moveTo(pos1);
-
- }
-
- if (stepper2.distanceToGo() == 0)
-
- {
-
- pos2 = -pos2;
-
- stepper2.moveTo(pos2);
-
- }
-
- stepper1.run();
-
- stepper2.run();
-
- }
復制代碼
懶得解釋。
*************************
這樣,基礎的幾個例子就看完了。
如果剛買了easydriver,焊接后測試是否能用,推薦
http://www.tinyos.net.cn/?article-38.html
EasyDriver 步進電機驅動板測試筆記
144825rj8xl4gwddozvvyd.jpg (203.94 KB, 下載次數: 152)
下載附件
2016-4-9 22:53 上傳
測試效果:
轉360度,
暫停1秒,
反轉360度,
暫停1秒,
轉1600個脈沖,速度5
暫停1秒
反轉1600個脈沖,速度25
暫停1秒
反復。
- #define DIR_PIN 2
- #define STEP_PIN 3
-
- void setup() {
- pinMode(DIR_PIN, OUTPUT);
- pinMode(STEP_PIN, OUTPUT);
- }
-
- void loop(){
-
- //rotate a specific number of degrees
- rotateDeg(360, 1);
- delay(1000);
-
- rotateDeg(-360, .1); //reverse
- delay(1000);
-
- //rotate a specific number of microsteps (8 microsteps per step)
- //a 200 step stepper would take 1600 micro steps for one full revolution
- rotate(1600, .5);
- delay(1000);
-
- rotate(-1600, .25); //reverse
- delay(1000);
- }
-
- void rotate(int steps, float speed){
- //rotate a specific number of microsteps (8 microsteps per step) - (negitive for reverse movement)
- //speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
- int dir = (steps > 0)? HIGH:LOW;
- steps = abs(steps);
-
- digitalWrite(DIR_PIN,dir);
-
- float usDelay = (1/speed) * 70;
-
- for(int i=0; i < steps; i++){
- digitalWrite(STEP_PIN, HIGH);
- delayMicroseconds(usDelay);
-
- digitalWrite(STEP_PIN, LOW);
- delayMicroseconds(usDelay);
- }
- }
-
- void rotateDeg(float deg, float speed){
- //rotate a specific number of degrees (negitive for reverse movement)
- //speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger
- int dir = (deg > 0)? HIGH:LOW;
- digitalWrite(DIR_PIN,dir);
-
- int steps = abs(deg)*(1/0.225);
- float usDelay = (1/speed) * 70;
-
- for(int i=0; i < steps; i++){
- digitalWrite(STEP_PIN, HIGH);
- delayMicroseconds(usDelay);
-
- digitalWrite(STEP_PIN, LOW);
- delayMicroseconds(usDelay);
- }
- }
復制代碼
easydriver 常見問題 (http://schmalzhaus.com/EasyDriver/)
只把問題列出來,如果有類似的,則用上面的鏈接打開再看。
Q1) My motor says it can only take 2.1V at 2A. Will the EasyDriver (running from up to 30V) blow up my motor or damage it in any way?
Q2) So shouldn't I run the power to the EasyDriver at the voltage that my motor is rated for? (i.e. 2.1V as per the above example)
Q3) How much current does my power supply need to produce?
Q4) So why does my bench power supply show 12V at 400mA when I know my motor should be drawing 750mA/phase (1.5A total)? Huh smarty pants?
Q5) How do I adjust the current limit?
Q5.1) What kind of stepper motors can I use EasyDriver with?
Q6) Why does EasyDriver get so hot?
Q7) What hardware/software can I use to test my EasyDriver?
Q8) How do I connect my EasyDriver up?
Q9) My Easy Driver's labels don't match what I see in the picture. Why not? And how do I know which way to turn the current adjustment pot?
Q10) Man, this is a lot of work to just use the A3967 chip. Can't I just solder down a bunch of A3967s on my own board design and save a ton of money?
Q11) The datasheet for the driver chip shows that the motor connects to pins OUT1A, OUT1B, OUT2A and OUT2B, and the diagram in the datasheet has one coil connected across OUT1A and OUT1B, and the other across OUT2A and OUT2B. But the Easy Driver only has A, A, B, B for motor connections, and it looks like one coil should be connected across the two A pins and the other across the two B pins. What's up with that?
Q12) So what's the deal with microsteps? How do I set what number of microsteps are used?
Q13) Help! I think my Easy Driver is not working like it should. How can I know if it's become damaged?
Q14) But Brian, can't you give us some real world numbers for power consumption and heat and stuff like that?
Q15) So I see that the EasyDriver has a pin labeled 5V. What is it for?
|