步进电机调试——20171108

今天主要调试了步进电机,x轴,y轴方向向前,向后,向左,向右运动,因为不知道步进电机走完x轴,y轴方向距离大概需要多少步,所以一直测试,一直试,一直试,先试x轴方向,先测试将X轴方向参数设置为1时x轴运动方向,再测试将x轴方向参数设置为0时x轴运动方向,然后测试从头至尾将x轴方向走完大概需要多少步,最后测试结果是,x轴方向参数设置为1时,x轴向前运动,x轴方向参数设置为0时,x轴向后运动;x轴步进数设置为6500时较为合适;同理,同样的方法测试y轴,y轴方向参数设置为1时向右运动,相反,为0时向左运动;同样的方法测试y轴方向步数为6500时较为合适;x轴测试程序:

int Xstep=3;
int Xdir=4;

void setup()
{
 pinMode(Xstep,OUTPUT);
 pinMode(Xdir,OUTPUT);
}

int moveX(int stepNum;int xdir)
{
  digitalRead(Xdir,xdir);
  for(x=0;x<stepNum;x++)
  {
   digitalWrite(Xstep,HIGH);
   delayMicroseconds(800);
   digitalWrite(Xstep,LOW);
   delayMicroseconds(800);
  }
  delay(1000);
}

void loop()
{
 moveX(6500,1);
 delay(2000);
 moveX(6500,0);
 delay(2000);
}

同样的方法调试y方向

int Ystep=9;
int Ydir=5;

void setup()
{
 pinMode(Ystep,OUTPUT);
 pinMode(Ydir,OUTPUT);
}

int moveY(int stepNum,int ydir)
{
 digitalRead(Ydir,ydir);
 for(y=0;y<stepNum,y++)
 {
  digitalWrite(Ystep,HIGH);
  delayMicroseconds(800);
  digitalWrite(Ystep,LOW);
  delayMicroseconds(800);
 }
 delay(1000);
}

void loop()
{
 moveY(6500,1);
 delay(2000);
 moveY(6500,0);
 delay(2000);
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值