• 概要
  • ステッピングモーター用ドライバの操作を学ぶためにArduinoUNOにST820を使ってみました。

  • 前提
    • Arduino UNO
    • Arduino IDE
    • ステッピングモータの原理

  • 配線
  • 1B:青
    2B:赤
    2A:緑
    1A:栗
    注意事項:モーターの配線を間違えるとST820は壊れてしまうようです。

  • プログラム
  • ST820.ino
    // ピン定義。
    #define PIN_MS0 13
    #define PIN_MS1 12
    #define PIN_MS2 11
    #define PIN_EN 10
    #define PIN_STEP 9
    #define PIN_DIR 8
    #define PIN_RST 7
    #define stepsPerRevolution 200  //1ステップ1.8度の場合
    #define microstep 256
    #define reductionratio  720     //減速比
    #define DELAY 1
    //#define DELAY 2000
    /*
     * MS2 MS1 MS0
     * 0   0   0    full step
     * 0   0   1    1/2 step
     * 0   1   0    1/4 step
     * 0   1   1    1/8 step
     * 1   0   0    1/16 step
     * 1   0   1    1/32 step
     * 1   1   0    1/128 step
     * 1   1   1    1/256 step
     */
    
    void setup() {
      // put your setup code here, to run once:
      pinMode(PIN_EN, OUTPUT);
      pinMode(PIN_STEP, OUTPUT);
      pinMode(PIN_DIR, OUTPUT);
    
      delay(500);
      digitalWrite(PIN_MS0, HIGH);
      digitalWrite(PIN_MS1, HIGH);
      digitalWrite(PIN_MS2, HIGH);
      digitalWrite(PIN_EN, HIGH);
      digitalWrite(PIN_DIR, LOW);
      digitalWrite(PIN_RST, HIGH);
      Serial.begin(9600);
      delay(500);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      Serial.println("時計回り");
      digitalWrite(PIN_DIR, LOW);
      for (int i = 0; i < stepsPerRevolution; i++) {
        for (int j = 0; j < reductionratio; j++) {
          for (int k = 0; k < microstep; k++) {
            digitalWrite(PIN_STEP, HIGH);
            delayMicroseconds(DELAY);
            digitalWrite(PIN_STEP, LOW);
            delayMicroseconds(DELAY);
          }
        }
      }
      delay(1000);
      Serial.println("反時計回り");
      digitalWrite(PIN_DIR, HIGH);
      for (int i = 0; i < stepsPerRevolution; i++) {
        for (int j = 0; j < reductionratio; j++) {
          for (int k = 0; k < microstep; k++) {
            digitalWrite(PIN_STEP, HIGH);
            delayMicroseconds(DELAY);
            digitalWrite(PIN_STEP, LOW);
            delayMicroseconds(DELAY);
          }
        }
      }
      delay(1000);
    }

  • 実行

  • 使用した部品
    • 本体
    • 17HS2408S-PG, Ratio 100:1
    • 制御

  • 更新履歴
  • 2022.12.12 作成