LoginSignup
0
0

More than 1 year has passed since last update.

steppingモータ使ってみた

Last updated at Posted at 2023-02-14

はじめに

amazonで購入したこちらのsteppingモータをarduinoを使って動かしてみました.

Screenshot from 2023-02-15 02-32-39.png

使用方法

使い方についてはカスタマーQ&Aに取扱説明書のリンクがあったので,そちらを参考にしました.

配線

以下の用に配線します.

Screenshot from 2023-02-15 02-50-27.png

プログラム

下記サンプルプログラムが用意されていたので,そちらを実行します.

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がゆっくり旋回します.

IMG_7361_AdobeExpress (1).gif

参考

早く回す

  • モタドラ設定

IMG_7521.jpg

  • プログラム

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);

}
  • 動作

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0