【arduino】A4988驱动

Arduino uno *1
A4988            *1
42步进电机    *1
面包板            *1
9V外接电源    *1

导线               若干




step 1:接线
【arduino】A4988驱动
关于接线更详细的相关资料:http://fritzing.org/projects/a4988-single-stepper-test/


MS1 , MS2 , MS3 跳线说明:(例子里是低电平,悬空或接地线,使用全步进模式)

分别是全步进,1/2步进,1/4步进,1/8步进,1/16步进模式。

步进电机走一步是1.8度,一圈就是200步。例如使用1/16步进,则需要走3200步才等于一圈。

【arduino】A4988驱动



step 2:测试程序程序
[objc] view plain copy
  1. int x;  
  2.   
  3.   
  4. void setup()  
  5. {  
  6.   pinMode(6,OUTPUT); // Enable  
  7.   pinMode(5,OUTPUT); // Step  
  8.   pinMode(4,OUTPUT); // Dir  
  9.   digitalWrite(6,LOW); // Set Enable low  
  10. }  
  11.   
  12.   
  13. void loop()  
  14. {  
  15.     
  16.   digitalWrite(4,HIGH); // Set Dir high  
  17.     
  18.   for(x = 0; x < 200; x++) // Loop 200 times  
  19.   {  
  20.       digitalWrite(5,HIGH); // Output high  
  21.       delayMicroseconds(800); // Wait 1/2 a ms  
  22.       digitalWrite(5,LOW); // Output low  
  23.       delayMicroseconds(800); // Wait 1/2 a ms  
  24.     }  
  25.   delay(1000); // pause one second  
  26.     
  27.   digitalWrite(4,LOW); // Set Dir low  
  28.     
  29.   for(x = 0; x < 200; x++) // Loop 2000 times  
  30.   {  
  31.       digitalWrite(5,HIGH); // Output high  
  32.       delayMicroseconds(800); // Wait 1/2 a ms  
  33.       digitalWrite(5,LOW); // Output low  
  34.       delayMicroseconds(800); // Wait 1/2 a ms  
  35.     }  
  36.     delay(1000); // pause one second  
  37. }  


ps后记学习:


*脚6(-en) 低电平为启动电机(enable),貌似也可以不接,试过一样能运行.但如果要控制电机的启动关闭还是要用上

*脚4(-dir) 用高低电平控制方向.

*脚5(-step) 用高低电平驱动电机转动.注意中间间隔等待的微秒值,如果太快会导致电机有声响不转动.