Arduino和L298N控制步进电机

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

Arduino和L298N控制步进电机看了别人的程序,却不能让步进电机正常运转,经过查找原因,发现是接线问题,根据两相四线步进电机的四拍工作方式,其各相通电顺序为:(A-AB-B-BA’-A’-A’B’-B’-B’A)。接线方式别的资料都有,可以去找,我是分别接到8、9(一相),10、11(另一相),这样程序需要进行适当修改。当然,我仅仅是为了测试步进电机好坏,可以看到速度的变化。如果实际运行,还要完善程序。程序中(digitalWrite(Pin2,LOW);digitalWrite(Pin3,HIGH);)定义为A;(digitalWrite(Pin0,LOW);digitalWrite(Pin1,HIGH);)定义为B,A’和B’相反就可以。程序如下(程序修改于网上找到的程序):intPin0=8;intPin1=9;intPin2=10;intPin3=11;int_step=0;booleandir=false;//正反转intstepperSpeed=1;//电机转速,1ms一步voidsetup(){pinMode(Pin0,OUTPUT);pinMode(Pin1,OUTPUT);pinMode(Pin2,OUTPUT);pinMode(Pin3,OUTPUT);}voidloop(){switch(_step){case0:stepperSpeed++;digitalWrite(Pin0,LOW);digitalWrite(Pin1,LOW);digitalWrite(Pin2,LOW);digitalWrite(Pin3,HIGH);//32Abreak;case1:digitalWrite(Pin0,LOW);digitalWrite(Pin1,HIGH);//10BdigitalWrite(Pin2,LOW);digitalWrite(Pin3,HIGH);break;case2:digitalWrite(Pin0,LOW);digitalWrite(Pin1,HIGH);digitalWrite(Pin2,LOW);digitalWrite(Pin3,LOW);break;case3:digitalWrite(Pin0,LOW);digitalWrite(Pin1,HIGH);digitalWrite(Pin2,HIGH);digitalWrite(Pin3,LOW);break;case4:digitalWrite(Pin0,LOW);digitalWrite(Pin1,LOW);digitalWrite(Pin2,HIGH);digitalWrite(Pin3,LOW);break;case5:digitalWrite(Pin0,HIGH);digitalWrite(Pin1,LOW);digitalWrite(Pin2,HIGH);digitalWrite(Pin3,LOW);break;case6:digitalWrite(Pin0,HIGH);digitalWrite(Pin1,LOW);digitalWrite(Pin2,LOW);digitalWrite(Pin3,LOW);break;case7:digitalWrite(Pin0,HIGH);digitalWrite(Pin1,LOW);digitalWrite(Pin2,LOW);digitalWrite(Pin3,HIGH);break;default:digitalWrite(Pin0,LOW);digitalWrite(Pin1,LOW);digitalWrite(Pin2,LOW);digitalWrite(Pin3,LOW);break;}if(dir){_step++;}else{_step--;}if(_step7){_step=0;}if(_step0){_step=7;}delay(stepperSpeed);}

1 / 4
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功