arduino驅動步進電機


https://learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/install-software

1安裝庫

 

 

Adafruit_Motor_Shield_V2

 

 

2控制直流電機

 

 

您還必須提供5-12VDC為電動機供電。有兩種方法可以做到這一點

您可以通過直流桶式插孔為Arduino供電,並在下面的綠色電源LED旁邊插入顯示為高黑色手柄的VIN跳線。

您可以通過DC Barrel插孔或 USB端口為Arduino供電。然后通過5-12VDC電機電源端子端口,綠色電源LED旁邊的雙端子塊為屏蔽供電,並卸下VIN跳​​線

 

確認電機已正確連接並且電源LED點亮后,我們可以上載代碼。

在IDE中,加載File-> Examples-> Adafruit_MotorShield-> DCMotorTest

您應該看到並聽到DC電動機打開並前后移動的情況,並附上紙條或膠帶作為“標志”,可以幫助您直觀地查看運動情況。你看不到運動

 

 

步進電機測試

您也可以測試帶屏蔽罩的步進電機連接。屏蔽層可以運行單極(5線和6線)和雙極(4線)步進器。它不能與其他任何數量的電線一起運行步進器!單極或雙極電機的代碼相同,接線略有不同。

將屏蔽層插入Arduino,並將步進電機連接到電機端口2- 與DC電機不同,接線順序很簡單。連接到頂部的兩個終端端口(線圈1)和底部的兩個終端端口(線圈2)。

    • 如果您使用的是雙極電機,請不要連接到中間引腳(GND)。
    • 如果使用5線制單極​​電機,則將公共線連接到GND。
    • 如果您使用具有6線制的單極電機,則可以將兩根“中心線圈線”連接到GND

 

 

 

 

 確認電機已正確連接並且電源LED點亮后,我們可以上載代碼。

在IDE中,加載File-> Examples-> Adafruit_MotorShield-> StepperTest,

您應該看到並聽到步進電機打開並前后移動的情況,並附上紙或膠帶作為“標志”,可以幫助您直觀地查看運動情況。您看不到運動。有四種移動步進器的方法,它們具有變化的速度,轉矩和平滑度折衷。此示例代碼將演示所有四個。

 

 

/* 
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control

For use with the Adafruit Motor Shield v2 
---->	http://www.adafruit.com/products/1438
*/


#include <Wire.h>
#include <Adafruit_MotorShield.h>

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Connect a stepper motor with 200 steps per revolution (1.8 degree)
// to motor port #2 (M3 and M4)
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);


void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Stepper test!");

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  myMotor->setSpeed(10);  // 10 rpm   
}

void loop() {
  Serial.println("Single coil steps");
  myMotor->step(100, FORWARD, SINGLE); 
  myMotor->step(100, BACKWARD, SINGLE); 

  Serial.println("Double coil steps");
  myMotor->step(100, FORWARD, DOUBLE); 
  myMotor->step(100, BACKWARD, DOUBLE);
  
  Serial.println("Interleave coil steps");
  myMotor->step(100, FORWARD, INTERLEAVE); 
  myMotor->step(100, BACKWARD, INTERLEAVE); 
  
  Serial.println("Microstep steps");
  myMotor->step(50, FORWARD, MICROSTEP); 
  myMotor->step(50, BACKWARD, MICROSTEP);
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM