简体   繁体   English

如何仅使用一个Arduino Uno使两个步进电机在相同的时间和相同的方向旋转?

[英]How do I get two stepper motors to rotate at the exact same time and in the same direction using only one Arduino Uno?

My current code: 我当前的代码:

    #include <Stepper.h>

    const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution


    Stepper myStepper(stepsPerRevolution, 3, 4, 5, 6);
    Stepper secondStepper(stepsPerRevolution, 8, 9, 10, 11);

    void setup() {
    // set the speed at 60 rpm:
    myStepper.setSpeed(60);
    // initialize the serial port:
    Serial.begin(9600);

    secondStepper.setSpeed(60);
    // initialize the serial port:
    Serial.begin(9600);
    }

    void loop() {
    // step one revolution  in one direction:
    Serial.println("clockwise");
    myStepper.step(stepsPerRevolution);
    Serial.println("clockwise");
    secondStepper.step(stepsPerRevolution);
    delay(500);
    }

I was working on a project involving the above code during a hackathon this past weekend, but I couldn't get the two motors to move simultaneously. 在过去的一个周末的黑客马拉松中,我正在从事一个涉及上述代码的项目,但是我无法让两个电机同时运动。 I was wondering if anyone on here knew how to do it properly so that I may be better prepared in the future. 我想知道这里的人是否知道如何正确地做,以便将来有更好的准备。

I'm using the Arduino IDE, if that matters. 如果这很重要,我正在使用Arduino IDE。

You need a non-blocking step (or start) call that starts the motion and returns immediately. 您需要一个非阻塞步骤(或开始)调用,以开始运动并立即返回。 After starting the two motions, you would then wait for an asynchronous callback from each motor indicating that the motion has completed. 在开始两个动作之后,您将等待每个电机的异步回调,指示动作已完成。 One thread per motor would work in a straightforward manner. 每个电机一个线程将以一种简单的方式工作。 The main thread would wait for both motor threads to complete before proceeding. 在继续之前,主线程将等待两个电动机线程完成。

是的,您可以并联两个电动机,以在Ramps 1.4板上控制z轴!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Arduino Uno步进电机问题 - Arduino Uno Stepper Motor Issues 同时在两个引脚上使用 arduino 音调功能 - using arduino tone function on two pin at the same time 旋转其中一个后,如何将两个对象移向相同方向? - How can I move two objects into the same direction after rotating one of them? Arduino:使用电机控制两个电机并测量行驶距离 - Arduino: Using motor to control two motors and measuring distance traveled 当您希望在 Arduino UNO 编程中同时执行不同的功能时使用什么代码/语句? - What code/statement is used when you want the different function executed at the same time in Arduino UNO programming? 如何使用ATL :: CImage同时旋转图像并使图像半透明? - How can I rotate and make the image semitransparent at the same time by using ATL::CImage? 使用 ESP8266 和 Blynk 应用程序进行实时步进电机控制 - Real Time Stepper Motors Control using ESP8266 and Blynk app 一起使用两个同名的 Arduino 库 - using two Arduino libraries with the same name together 如何修复我为 Arduino 制作的步进电机库? - How do I fix my stepper motor library that I made for Arduino? 如果我有两个成员完全相同但名称不同的结构/类,是否有任何简单的方法可以将一个转换为另一个? - If I have two structures/classes with the exact same members, but different names, is there any easy way to convert one into the other?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM