はじめに
amazonで購入したこちらのsteppingモータをarduinoを使って動かしてみました.
使用方法
使い方についてはカスタマーQ&Aに取扱説明書のリンクがあったので,そちらを参考にしました.
配線
以下の用に配線します.
プログラム
下記サンプルプログラムが用意されていたので,そちらを実行します.
code.txt
#include <Arduino.h>
/*
TB6600 module connected with the ARDUINO:
EN +, DIR + : PUL + (total Yang connection mode)
EN- 5
DIR- 6
PUL- 7
*/
int EN = 5;
int DIR = 6;
int PUL = 7;
boolean dir = true;
void setup()
{
pinMode(EN,OUTPUT);
pinMode(DIR,OUTPUT);
pinMode(PUL,OUTPUT);
}
void clockwiseRotation(unsigned char rotationspeed) //
{
digitalWrite(DIR,LOW);
digitalWrite(EN,HIGH);
digitalWrite(PUL,LOW);
delay(rotationspeed);
digitalWrite(PUL,HIGH);
delay(rotationspeed);
}
void negativeRotation(unsigned char rotationspeed)
{
digitalWrite(DIR,HIGH);
digitalWrite(EN,HIGH);
digitalWrite(PUL,LOW);
delay(rotationspeed);
digitalWrite(PUL,HIGH);
delay(rotationspeed);
}
/*
Multiple_Of_45_Degrees:Stepper motor rotation multiples of 45 degrees;
Speed:Adjust the speed of stepper motor
*/
void stepByStepClockwiseRotation(unsigned int Multiple_Of_45_Degrees,unsigned int Speed) //+45.
{
unsigned int n=0;
for(n = 0;n < 50 * Multiple_Of_45_Degrees;n++)
{
clockwiseRotation(Speed); //The Speed value, the greater the stepper motor rotate Speed is slow
}
dir = true;
}
void stepByStepNegativeRotation(unsigned int Multiple_Of_45_Degrees,unsigned int Speed) //-45.
{
unsigned int n=0;
for(n = 0;n < 50 * Multiple_Of_45_Degrees ;n++)
{
negativeRotation(Speed);
}
dir = false;
}
void loop()
{
//clockwiseRotation();
if(dir)
{
delay(5000);
stepByStepNegativeRotation(35,5);
delay(1000);
}
else
{
stepByStepClockwiseRotation(35,5) ;
delay(1000);
}
}
実行結果
stepperがゆっくり旋回します.
参考
早く回す
- モタドラ設定
- プログラム
int step_pin = 7;
int dir_pin = 6;
int relay_pin = 5;
void setup()
{
pinMode(step_pin, OUTPUT);
pinMode(dir_pin, OUTPUT);
pinMode(relay_pin, OUTPUT);
digitalWrite(dir_pin, HIGH);
digitalWrite(relay_pin, LOW);
Serial.begin( 9600 );
}
void spinMotor(int direction, int num){
digitalWrite(relay_pin, HIGH);
if(direction == 0){
digitalWrite(dir_pin, LOW);
}else{
digitalWrite(dir_pin, HIGH);
}
for(int i=0;i<num;i++)
{
digitalWrite(step_pin, HIGH);
delayMicroseconds(30);
digitalWrite(step_pin, LOW);
delayMicroseconds(30);
}
digitalWrite(relay_pin, LOW);
}
void loop()
{
spinMotor(0,200*32);
delay(3000);
spinMotor(1,200*32);
delay(3000);
}
- 動作