4stepmotor with arduino and Accelstepper

Hello, I want to control 4 stepper motors simultaneously using the DM332T driver. I want them to move back and forth between the same positions. First, I'm not sure if I have connected the driver and Arduino correctly. I have connected them according to the diagram below

and also i need to connect 5v to OPTO, if i need to 4 OPTO to 5V How can i make it?

11111

#include <AccelStepper.h>
#include <MultiStepper.h>

// 스테퍼 드라이버 핀 설정
#define PUL_PIN_1 2
#define DIR_PIN_1 3
#define PUL_PIN_2 4
#define DIR_PIN_2 5
#define PUL_PIN_3 6
#define DIR_PIN_3 7
#define PUL_PIN_4 8
#define DIR_PIN_4 9

// 스테퍼 객체 생성
AccelStepper stepper1(AccelStepper::DRIVER, PUL_PIN_1, DIR_PIN_1);
AccelStepper stepper2(AccelStepper::DRIVER, PUL_PIN_2, DIR_PIN_2);
AccelStepper stepper3(AccelStepper::DRIVER, PUL_PIN_3, DIR_PIN_3);
AccelStepper stepper4(AccelStepper::DRIVER, PUL_PIN_4, DIR_PIN_4);

// 멀티스테퍼 객체 생성
MultiStepper multiStepper;

void setup() {
  // 각 스테퍼의 속도와 가속도 설정
  stepper1.setMaxSpeed(1000.0);
  stepper1.setAcceleration(100.0);
  stepper1.setSpeed(200);  // 스테퍼1의 이동 속도 설정

  stepper2.setMaxSpeed(1000.0);
  stepper2.setAcceleration(100.0);
  stepper2.setSpeed(200);  // 스테퍼2의 이동 속도 설정

  stepper3.setMaxSpeed(1000.0);
  stepper3.setAcceleration(100.0);
  stepper3.setSpeed(200);  // 스테퍼3의 이동 속도 설정

  stepper4.setMaxSpeed(1000.0);
  stepper4.setAcceleration(100.0);
  stepper4.setSpeed(200);  // 스테퍼4의 이동 속도 설정

  // 멀티스테퍼에 스테퍼 추가
  multiStepper.addStepper(stepper1);
  multiStepper.addStepper(stepper2);
  multiStepper.addStepper(stepper3);
  multiStepper.addStepper(stepper4);
}

void loop() {
  // 왕복 운동을 위한 이동 거리와 방향 설정
  long forwardDistance = 1000;  // 정방향 이동 거리
  long backwardDistance = -1000;  // 역방향 이동 거리

  // 멀티스테퍼로 동시에 이동
  long targetPositions[] = {forwardDistance, forwardDistance, forwardDistance, forwardDistance};
  multiStepper.moveTo(targetPositions);  // 모든 모터를 정방향으로 이동
  while (multiStepper.run()) {}  // 모든 모터가 목표 위치로 도달할 때까지 대기

  delay(10000);  // 10초 대기

  // 멀티스테퍼로 동시에 역방향 이동
  long targetPositions2[] = {backwardDistance, backwardDistance, backwardDistance, backwardDistance};
  multiStepper.moveTo(targetPositions2);  // 모든 모터를 역방향으로 이동
  while (multiStepper.run()) {}  // 모든 모터가 목표 위치로 도달할 때까지 대기

  delay(10000);  // 10초 대기
}

I moved your topic to an appropriate forum category @isant.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

You need a GND connection between the drivers and the controller. I hope You use one driver for each stepper.

1 Like

just right now my connection , i tried 1Opto connection with 5V. but it it not a function as well caus i try right now from 2 Driver Opto to 5V. Now is function. but i still have a confuse.

how can i connect GND ?

  • should i from Drive p2 to Arnuino Gnd Connection ?

Sorry, my mistake. The +5 to the driver is feeding it. PUL and DIR are activated by an active LOW signal. Please use schematics. Pictures are practically useless.

The orange wire looks like it is in GND.
uno.jpeg

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.