How to control 18 different stepper motors individually

I am building a gimball for a project which needs to acurately change position in yaw,pitch and roll. For this i am using 4-phase stepper motors. This one: 28BYJ-48 Stepper Motor with ULN2003 Driver.

The company already has multiple arduino mega's and uno's laying around, and want me to use them. So is it possible to connect the 18 motors(4 wires which need pins) to the arduino Mega with a shield or another accessory? or is it maybe possible to use multiple arduino's on one serial port and code? I need to be able to use each motor seperately, and each motor gives back feedback after changing positions or when it starts moving. The motors move by input from the user via the serial port and also return the messages via the serial port.

Other options are also welcome

The motors don't provide feedback. What sort of feedback do you have in mind?

For control of yaw, pitch and roll angles using a gimbal mount, in principle you need just three motors. Why eighteen?

You're right they don't provide feedback themselves, but they save theri starting positions as 0. And calculate the user input(in degrees) to steps and after it has completed that amount of steps the code prints how many degrees it is at that moment.

And for why i am using 18 motor: For one gimbal i need 3 motors to control yaw, pitch and roll. But for this project I need to control 6 gimballs, because the system of the company has 6 different sensors that need to be controlled.

So this was my test code to controll 1 stepper motor(I also have one to control 3 at a time, but am still working on the 18 motors one)

#include <AccelStepper.h>

#define MotorInterfaceType 4

AccelStepper myStepper(MotorInterfaceType, 8, 10, 9, 11);

float currPosDeg = 0.0;
const float STEPS_PER_REVOLUTION = 2048.0; // Steps per revolution
const float DEGREES_PER_STEP = 360.0 / STEPS_PER_REVOLUTION; // Degrees per step

void setup() {
  Serial.begin(9600);
  myStepper.setMaxSpeed(1000.0);
  myStepper.setAcceleration(50.0);
  myStepper.moveTo(0.0);
  Serial.println("Status Sensor1,Roll: Online");
}

void loop() {

  if (Serial.available() > 0) {
    String input = Serial.readString();
    float newPosDeg = input.toFloat();
    moveToDegree(newPosDeg);
    currPosDeg = newPosDeg;
    resetMotor(currPosDeg);
    positie();
  }

  myStepper.run();

}

void moveToDegree(float newPosDeg) {
  float newPosSteps = newPosDeg / DEGREES_PER_STEP;
  myStepper.moveTo(newPosSteps);
  while (myStepper.distanceToGo() != 0) {
    myStepper.run();
  }

}

void positie(){
  if(currPosDeg > 0){
  Serial.print("Platform hangs ");
  Serial.print(currPosDeg);
  Serial.println(" degrees to the right");
  }
  else if(currPosDeg < 0){
  Serial.print("Platform leunt ");
  Serial.print(currPosDeg);
  Serial.println(" degrees to the left");
  }
  else if(currPosDeg==0){
  Serial.print("Platform hangs ");
  Serial.print(currPosDeg);
  Serial.println(" degrees, so platform is horizontal");
  }
}

void resetMotor(float initialPosDeg) {
  float initialPosSteps = initialPosDeg / DEGREES_PER_STEP;
  myStepper.moveTo(initialPosSteps);
  while (myStepper.distanceToGo() != 0) {
    myStepper.run();
  }
}

Just glancing at the code you posted, I wonder how, physically, your program knows where position0.0 is located? You make no attempt to position the stepper at a known 0.0 location.
The second is trying to position a stepper motor at a fractional step is not going to work.

1 Like

The motors simply respond to step commands from the Arduino, or if the output shafts are mechanically overloaded, perhaps do not respond at all.

To know the current output shaft angle of each motor, either "homing" at startup, or an absolute shaft encoder is required.

I suggest to start by getting just one gimbal working with three motors.

1 Like

So, there isn't exactly a fancy measurement system involved here. I'm working with a stepper motor from AliExpress, nothing too fancy with encoders or the like. My idea was to manually set the gimbal to its starting position the first time around. Then, whenever it moves, I have it record how many steps it takes to move a certain number of degrees. I figure out this step count by using the reduction ratio of the motor's gearbox, which I found from this link (https://lastminuteengineers.com/28byj48-stepper-motor-arduino-tutorial/?utm_content=cmp-true). Basically, I calculate the number of steps the motor needs to take for each degree of movement and then instruct the motor to move that precise number of steps.

In terms of the code, my plan was to align the motors manually before the first use so that the Yaw, Pitch, and Roll are all straight. Then, when the system is turned on, it records this starting position as 0 and logs every subsequent input it receives. The angle input is then converted into steps using the previously determined reduction ratios. When the user wants to stop using the gimbal, they input 'STOP', which returns the motors to the 0 position (the starting positions from the beginning of the test), and then they can power it down.

I'll admit, it's a pretty basic and imperfect approach, but it's the best solution I could come up with at the time. And during testing with some weight and just one motor, it performed greatly. It accurately reached the desired position within 0.1 degrees and smoothly returned to 0 degrees when given the stop command or given the input of 0-degrees

Video(With a primitive heavy test gimbal):
gimball (1)
.

@jremington
Hey there, sorry for the delay in getting back to you. Last week, I had a meeting at my company, and this question about how i know the motors angle came up there too. They were wondering if i would be using an encoder ring in the motor to figure it out or something else.

Right now, I'm in the process of sketching out some concepts in CAD so that I can have a physical gimbal to experiment with. After hearing their feedback and questions, I'm thinking it might be best to start from scratch. My plan is to begin by locking in the gimbal concept and finding a stepper motor with an encoder or other option that are out there. The idea behind this is that they want the gimbal to be able to determine its angle and then communicate that information back to the main computer.

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