Help me with coding drv8825

Hi, I'm building a turntable for photo scanning.
I would need help with coding. I have a DRV8825 that controls a stepper motor
What I want to do is when i push a button, stepping motor (50BYJ46-6) spins 360 degrees but to stop x number of times to take a picture with a camera. Idea is to later implement this to a menu that i found online that i have used before in a different project and have three diffrent tabs where one stop 24 times second tab where it stop 36 times and a third stops 48 times.

Camera taking picture part i already know what to do.

Here is some code that I have started with. The result that i have now is that it moves once and not 360.

blackpower, greenpower is two mosfet that i use to cut the power(12v and 5v) from the drv8825 so when it's in idle the stepping motor doesn't get warm.

#include <AccelStepper.h>
#include "sixteen.h"

void setup()
{
  stepper.setMaxSpeed(1000);
  pinMode(blackpower, OUTPUT);
  pinMode(greenpower, OUTPUT);
}

void loop() {
  motor_sixteen();
  delay(10000);

}
#define dirPin 4
#define stepPin 3
#define motorInterfaceType 1
int blackpower = 7;
int greenpower = 8;
#include "pins.h"
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
bool    fHasLooped  = false;
void motor_sixteen() {
  if ( fHasLooped == false )
  {
    stepper.setCurrentPosition(0);
    // Run the motor forward at 200 steps/second until the motor reaches 400 steps (2 revolutions):
    while (stepper.currentPosition() != 400)
    {
      for ( int x = 0; x < 10; x++ )
      {
        stepper.setSpeed(200);
        stepper.runSpeed();
      }

      fHasLooped = true;
    }
  }
}

Here is the menu

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int upButton = 5;
int downButton = 7;
int selectButton = 6;
int menu = 1;

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.setCursor(1, 0);
  lcd.print("TURNTABLE");
  delay(5000);
  lcd.clear();
  Serial.begin(9600);
  pinMode(upButton, INPUT_PULLUP);
  pinMode(downButton, INPUT_PULLUP);
  pinMode(selectButton, INPUT_PULLUP);
  updateMenu();
}

void loop() {
  if (!digitalRead(downButton)){
    menu++;
    updateMenu();
    delay(100);
    while (!digitalRead(downButton));
  }
  if (!digitalRead(upButton)){
    menu--;
    updateMenu();
    delay(100);
    while(!digitalRead(upButton));
  }
  if (!digitalRead(selectButton)){
    executeAction();
    updateMenu();
    delay(100);
    while (!digitalRead(selectButton));
  }
}

void updateMenu() {
  switch (menu) {
    case 0:
      menu = 1;
      break;
    case 1:
      lcd.clear();
      lcd.print(">16");
      lcd.setCursor(0, 1);
      lcd.print(" 24");
      break;
    case 2:
      lcd.clear();
      lcd.print(" 24");
      lcd.setCursor(0, 1);
      lcd.print(">36");
      break;
    case 3:
      lcd.clear();
      lcd.print(" 36");
      lcd.setCursor(0, 1);
      lcd.print(">Settings");
      break;
    case 4:
      menu = 3;
      break;
  }
}

void executeAction() {
  switch (menu) {
    case 1:
      action1();
      break;
    case 2:
      action2();
      break;
    case 3:
      action3();
      break;
  case 4:
      action4();
      break;

  }
}

void action1() {
  lcd.clear();
  lcd.print(">SCAN");
  delay(2500);
  lcd.clear();
  lcd.setCursor(4, 0);
  lcd.print("SCANNING");
  delay(1000);
      
  lcd.clear();
  lcd.setCursor(6, 0);
  lcd.print("DONE");
  delay(500);
}
void action2() {
 lcd.clear();
  lcd.print(">SCAN");
  delay(2500);
  lcd.clear();
  lcd.setCursor(4, 0);
  lcd.print("SCANNING");
  delay(1000);
      
  lcd.clear();
  lcd.setCursor(6, 0);
  lcd.print("DONE");
  delay(500);
}
void action3() {
 lcd.clear();
  lcd.print(">SCAN");
  delay(2500);
  lcd.clear();
  lcd.setCursor(4, 0);
  lcd.print("SCANNING");
  delay(1000);
      
  lcd.clear();
  lcd.setCursor(6, 0);
  lcd.print("DONE");
  delay(500);
}
void action4() {
  lcd.clear();
  lcd.print(">Bluetooth");
  delay(2500);
  digitalWrite(13, HIGH);
  delay(4000);
  digitalWrite(13, LOW);
  lcd.clear();
  lcd.setCursor(6, 0);
  lcd.print("ON/OFF");
  delay(500);
}

A byj needs a uln2003 driver is it not?

it is not compatible with uln2003, it only have four wires

Sorry, I do not know the accelstepper lib.
What I do know is you do not have to cut the power from the driver. You only have to make the enable pin high. This will disable the power to the motor.

The DRV8825 is designed to drive modern 200 steps/rev bipolar motors, not the type you have. I would suggest that you buy such a modern motor in say NEMA17 size, you will find the project much easier. Though it doesn't have in-built gearing it does support microstepping which may easily give you enough resolution. You set the stepper current by adjusting a pot on the board to get enough torque but not get too hot - but steppers do run hot anyway. Not a good idea to remove power mid-way as the stepper loses accuracy, use the enable input on the driver instead.

I cannot change the motor because I use a stepping motor that already belongs to a turntable and the NEMA17 or any other stepping motor will not fit in the existing mounting hole. This stepping motor is capable of rotating a person and I don't want to lose that.

Here is an example of someone who uses drv8825 with the same motor that I have and has gotten it to work. I don't think there is a compatible issue.
https://www.instructables.com/Slider-Révopoint-POP/

I have gotten the engine to spin 360 degrees but not to make stopps on the way like I want. When it comes to the mosfet, it should not turn off the power every time it stops, but when it has gone a full turn and gone back to the menu. I have done this in another project where in a part of a sequens a 28BYJ-48 was used to spin a camera filter 90 degrees and then rotated back and returned to the menu.

Frits1956 As for accelstepper lib u don't really need to use it, on this website where i got most of the code, there is en exempel where u don't need any library, i have used both of them and they both work.

/*Example sketch to control a stepper motor with A4988/DRV8825 stepper motor driver and Arduino without a library. More info: https://www.makerguides.com */

// Define stepper motor connections and steps per revolution:
#define dirPin 2
#define stepPin 3
#define stepsPerRevolution 200

void setup() {
  // Declare pins as output:
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
}

void loop() {
  // Set the spinning direction clockwise:
  digitalWrite(dirPin, HIGH);

  // Spin the stepper motor 1 revolution slowly:
  for (int i = 0; i < stepsPerRevolution; i++) {
    // These four lines result in 1 step:
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(2000);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(2000);
  }

  delay(1000);

  // Set the spinning direction counterclockwise:
  digitalWrite(dirPin, LOW);

  // Spin the stepper motor 1 revolution quickly:
  for (int i = 0; i < stepsPerRevolution; i++) {
    // These four lines result in 1 step:
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(1000);
  }

  delay(1000);

  // Set the spinning direction clockwise:
  digitalWrite(dirPin, HIGH);

  // Spin the stepper motor 5 revolutions fast:
  for (int i = 0; i < 5 * stepsPerRevolution; i++) {
    // These four lines result in 1 step:
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(500);
  }

  delay(1000);

  // Set the spinning direction counterclockwise:
  digitalWrite(dirPin, LOW);

  //Spin the stepper motor 5 revolutions fast:
  for (int i = 0; i < 5 * stepsPerRevolution; i++) {
    // These four lines result in 1 step:
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(500);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(500);
  }

  delay(1000);
}

What I need is for someone to help me get it spinning and make stops along the way. Something similar to this but instead of an LED, it's my stepper motor.

const int greenPin = 13;
const int cameraPin = 12;
const byte buttonPin = 5;
boolean buttonState = LOW;
boolean oldbuttonState = LOW;
bool    fHasLooped  = false;
void setup()
{
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
  pinMode(cameraPin, INPUT);
  pinMode(greenPin, OUTPUT);
}

void loop() {
  

  buttonState = digitalRead(buttonPin);
   if (oldbuttonState != buttonState)
   if ( fHasLooped == false )
   { 
      if (buttonState == HIGH) // button went from off to on
      for ( int x = 0; x < 10; x++ )
      {
    digitalWrite(greenPin, HIGH);
    delay(1000);
    digitalWrite(greenPin, LOW);
    delay(100);
    digitalWrite(cameraPin, HIGH);
    delay(100);
    digitalWrite(cameraPin, LOW);
    delay(1000);        
    }
      oldbuttonState = buttonState;
      fHasLooped = true;
   }
}

The stepper seems to have a 60:1 gear reduction, but how many steps per rev? You define it as 200, but usually those old-fashioned steppers have a basic motor that is 48 or 60 steps, then you have the reduction by 60, which would make a minimum of 2880 steps/rev for 48 or 3600 for 60. 200 steps is common for modern motors.

Also, to what value have you set the current? The 8825 max current is 1.5A/phase without cooling and as supplied the current could be set to any value up to this.

I have not changed steps per rev to 200 it where from the beginning. Code that i have used comes from makerguide.com
I don't really know what what my stepping motor should have.

Mine is set to 1A and it has a heat sink on it.

My stepping motor spins a gear with 16 teeth that spins a bigger gear that has 128 teeth

Are those the internal gears? Or external to the motor assembly?

OK, so the steps/rev is 8:1 from the motor to the turntable; then whatever the internal gearing is, times the steps per rev of the motor itself. I think you will just have to do some experimentation, feeding a certain number of steps and seeing how far the 16t gear turns, adjusting the number until you get one rev.

Hi after some experimentation i have found that stepsPerRevolution is 6360

#define dirPin 4
#define stepPin 3
#define stepsPerRevolution 6360
int blackpower = 7;
int greenpower = 8;

void setup() {
  // Declare pins as output:
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(blackpower, OUTPUT);
  pinMode(greenpower, OUTPUT);
}

void loop() {
  digitalWrite(dirPin, HIGH);
  digitalWrite(blackpower, HIGH);
  digitalWrite(greenpower, HIGH);


  // Spin the stepper motor 5 revolutions fast:
 for (int i = 0; i < stepsPerRevolution; i++) {
    // These four lines result in 1 step:
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(3000);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(2000);
  }
  delay(10000);
}

Does that code work as you expect?

Now it starts from one point and ends at starting place then waits and loops.

Now that I know stepsPerRevolution, you could write a script where it takes stepsPerRevolution and divides it as many times as I want it to stop + delay then when it has done all the parts it stops.

Indeed, you could...

Do you know how, i am not a coder?