***********************
从淘宝上买了光驱式激光雕刻机DIY,目前还没有能力装上。相比安装要求,配套教程确实不够详细。虽然不需要知道原理,只知道步骤也可以完成雕刻机安装,但是步骤不清楚,另外自己对arduino和easydriver也不是很熟悉,所以难上加难。
为了不半途而废,所以打算边学基础边实践,最终完成对激光雕刻机的理解和实践。
***********************
选择easydriver作为起点,是因为它式连接 arduino 和 步进电机的 关键核心。
机械坊已经有两个例子,
*******
http://www.51hei.com/bbs/dpj-47861-1.html
微型CNC制作基于开源项目GRBL
这个例子就是最终要完成的,只是觉得该例子对于基础差的不够详细,而且步骤有跳跃,一上来就按照该教程失败率较高。
*******
http://www.51hei.com/bbs/dpj-47860-1.html
arduino当Gcode解释程序(CNC)
这个例子虽然有用,但对新手来说更不完整,新手无从下手。
********
直接找到easydriver的老家,
http://schmalzhaus.com/EasyDrive ... DriverExamples.html
果然提供新手的例子(并推荐进阶可以参考blogspot 上面的turorial,遗憾的是打不开,不知道是不是与长城有关)
第一个例子是 设置,怎样连线
***************************************
Example 1: Basic Arduino setup
上面的示意图可以使用 Arduino设计助手来画,刚刚才搜到。
为什么这样连接,需要看easydriver 示意图
从上图可以看出,步进电机是4根线,选择2相4线类型,淘宝上非常多。接线顺序示意图很清晰很简单。
这里有个事项,easydriver的排针是没有焊接上,需要玩家自己焊接,这时就有两种选择:
1、仿照上面的示意图(使用面包板)
2、不使用面包板
需要仔细看,就是排针的方向,排针焊接在正面,就是使用面板板;焊接在反面,就不用面包板。
步进电机需要单独供电,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)
只有安装了上面的库,才可以运行例子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 库。
- #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 步进电机驱动板测试笔记
测试效果:
转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?
|