zoukankan      html  css  js  c++  java
  • arduino无驱动运行8毫米的超迷你微型两相四线步进电机

    原文视频:

    https://www.youtube.com/watch?v=xEjfAWV3WWU

     

     

    在淘宝淘了一些超迷你的步进电机,但是店家并不提供详细资料,经过一番搜索,终于获得信息如下:

    名称:8mm微型步进电机 小型2相4线步进马达

    英文名称:Abovehill 8mm Micro Stepper Motor 2-Phase 4-Wire DC 5-6V with Connection line +gear

    【相电阻】40欧姆

    【步距角】18°

    【重量】5.8克

    1. 这是一款精密8毫米微型步进电机,广泛应用于数码相机等数码产品中

    2. 适用于5-6V 电压,驱动电流为0.12 a,短路电流为0.14 a

    3. 每对电机由两台电机捆绑,输出轴长度分别为4毫米和3.5毫米,都装有齿轮

    4. 电机直径: 8毫米,电机高度: 8.2毫米,输出轴直径: 1.5毫米,齿轮外径: 2.2毫米

    5.长轴电机连接线定义: (蓝色: a + ,黑色: a-。红色: b + ,白色: b -)短轴电机连接线定义: (紫色: a + ,黄色: a-。橙色: b + ,绿色: b -)

    arduino接线:

    A+   ->    D5

    A-    ->    D4

    B+    ->   D3

    B-     ->   D2

    arduino代码:

    版本一:基本版 - 不使用库

    #define in_A_1 2
    #define in_A_2 3
    #define in_B_1 4
    #define in_B_2 5
    
    int currentStep = 0;
     
    void setup()
    {
        pinMode(in_A_1, OUTPUT);
        pinMode(in_A_2, OUTPUT);
        pinMode(in_B_1, OUTPUT);
        pinMode(in_B_2, OUTPUT);
    }
    unsigned int time_delay = 200;
    
    void step1(){
        //A+,B+
        digitalWrite(in_A_1, 1);
        digitalWrite(in_A_2, 0);
        digitalWrite(in_B_1, 1);
        digitalWrite(in_B_2, 0);
        delay(time_delay);
    }
    
    void step2(){
        //A+,B-
        digitalWrite(in_A_1, 1);
        digitalWrite(in_A_2, 0);
        digitalWrite(in_B_1, 0);
        digitalWrite(in_B_2, 1);
        delay(time_delay);
    }
    
    void step3(){
        //A-,B-
        digitalWrite(in_A_1, 0);
        digitalWrite(in_A_2, 1);
        digitalWrite(in_B_1, 0);
        digitalWrite(in_B_2, 1);
        delay(time_delay);
    }
    
    void step4(){
        //A-,B+
        digitalWrite(in_A_1, 0);
        digitalWrite(in_A_2, 1);
        digitalWrite(in_B_1, 1);
        digitalWrite(in_B_2, 0);
        delay(time_delay);
    }
    
    void tickClock(){
      currentStep++;
      if( currentStep >= 4 ){
        currentStep = 0;
      }
      int cycle = currentStep % 4;
      if( cycle == 0 ){
        step1();
      } else if( cycle == 1 ){
        step2();
      } else if( cycle == 2 ){
        step3();
      } else if( cycle == 3 ){
        step4();
      }
    }
    
    void counter_tickClock(){
      currentStep--;
      if( currentStep < 0 ){
        currentStep = 3;
      }
      int cycle = currentStep % 4;
      if( cycle == 0 ){
        step1();
      } else if( cycle == 1 ){
        step2();
      } else if( cycle == 2 ){
        step3();
      } else if( cycle == 3 ){
        step4();
      }
    }
    
    void clockwise(long st){
      long i = 0;
      while( i < st ){
        //step1
        step1();
        //step2
        step2();
        //step3
        step3();
        //step4
        step4();
        i++;
      }
    }
    
    void counter_clockwise(long st){
      long i = 0;
      while( i < st ){
        //step1
        step1();
        //step4
        step4();
        //step3
        step3();
        //step2
        step2();
        i++;
      }
    }
    void loop()
    {
        //clockwise(18);//counter_clockwise(18);
       // tickClock();
        counter_tickClock();
    }

     版本二: 调用Stepper库  - 使用arduino Stepper库

    #include <Stepper.h>
    
    const int stepsPerRevolution = 48;  // 根据电动机步数更改此值
                                        
    Stepper myStepper(stepsPerRevolution, 2,3,4,5);            
    
    int stepCount = 0;         //已经走的步数
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      if (stepCount < stepsPerRevolution) {  
        myStepper.step(1);
        Serial.print("steps:" );
        Serial.println(stepCount);
        stepCount++;
        delay(500);
      }
    }

    版本三:调用AccelStepper库

    #include <AccelStepper.h>
    
    #define HALF4WIRE 8
    
    // Motor pin definitions
    #define motorPin1  2     // A1 
    #define motorPin2  3     // A2 
    #define motorPin3  4     // B1 
    #define motorPin4  5     // B2 
    
    // Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48
    //AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
    
    AccelStepper stepper1 (HALF4WIRE, motorPin1, motorPin2, motorPin3, motorPin4, true);
    
    void setup() {
      stepper1.setMaxSpeed(1200.0);
      stepper1.setAcceleration(100.0);
      stepper1.setSpeed(100);
      stepper1.moveTo(12000); //250 full rotations @ 48 steps each = 12,000 steps
    
    }//--(end setup )---
    
    void loop() {
    
      //Change direction when the stepper reaches the target position
      if (stepper1.distanceToGo() == 0) {
        stepper1.moveTo(-stepper1.currentPosition());
        delay(500);
      }
      stepper1.run();
    }
  • 相关阅读:
    【ElasticSearch】异常错误
    【CentOS7】系统设置
    【Ubuntu 18.04.03_64】系统配置
    【MySql】语法学习
    【ElasticSearch】聚合使用学习
    【Spring Boot】Spring Security登陆异常出路
    【ElasticSearch】查询使用学习
    Spring boot X-Frame-Options 异常 a frame because it set 'X-Frame-Options' to 'deny'
    【Thymeleaf】使用学习
    【MySql】日期时间
  • 原文地址:https://www.cnblogs.com/meetrice/p/14176110.html
Copyright © 2011-2022 走看看