|
楼主 |
发表于 2014-2-28 14:52:06
|
显示全部楼层
本帖最后由 oldbeginner 于 2014-2-28 14:53 编辑
oldbeginner 发表于 2014-2-28 14:17
第四个例子需要两个电动机,如下示意图,其实一个电机也可以,只不过把pin8 移到 pin6 ,pin9 移到 pin7 ...
如果刚买了easydriver,焊接后测试是否能用,推荐
http://www.tinyos.net.cn/?article-38.html
EasyDriver 步进电机驱动板测试笔记
测试效果:
转360度,
暂停1秒,
反转360度,
暂停1秒,
转1600个脉冲,速度5
暂停1秒
反转1600个脉冲,速度25
暂停1秒
反复。
[pre lang="arduino" line="1" file="easydriver_test"]#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)? HIGHOW;
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)? HIGHOW;
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);
}
}[/code] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|