accelstepper

98 views
Skip to first unread message

Alfito Desmon

unread,
Jun 3, 2024, 3:53:13 AMJun 3
to accelstepper
hello fiend i am user stepper motor 28byj , i have project robot using 2 two stepper that controlled by mit app inventor , so on this interface there are button connect and dis connect , and button forward and reverse so in my trouble now is i confuse to code two stepper if i press button forward two stepper will go simultenously, so this forum what i have to do in this code, please

Jim Larson

unread,
Jun 4, 2024, 1:32:11 AMJun 4
to accelstepper
Please post your code so we can see what's happening.

             -jim

Alfito Desmon

unread,
Jun 5, 2024, 7:39:36 AMJun 5
to accels...@googlegroups.com
#include <AccelStepper.h>

#include "BluetoothSerial.h"

BluetoothSerial SerialBT;
#define HALFSTEP 8

#define motorPin1  32     // IN1 on the ULN2003 driver 1
#define motorPin2  33     // IN2 on the ULN2003 driver 1
#define motorPin3  25     // IN3 on the ULN2003 driver 1
#define motorPin4  26     // IN4 on the ULN2003 driver 1

#define motorPin5  17     // IN1 on the ULN2003 driver 2
#define motorPin6  21     // IN2 on the ULN2003 driver 2
#define motorPin7  16    // IN3 on the ULN2003 driver 2
#define motorPin8  27    // IN4 on the ULN2003 driver 2

const float STEPS_PER_REV = 32;
const float GEAR_RED = 64;
const float STEPS_PER_OUT_REV = STEPS_PER_REV * GEAR_RED;

AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
AccelStepper stepper2(HALFSTEP, motorPin5, motorPin7, motorPin6, motorPin8);
int StepsRequired;
int stepperSpeed = 1000;

void setup() {
SerialBT.begin("ESP32-Bluetooth");
Serial.begin(115200); // Untuk debugging melalui Serial Monitor

}

void loop() {
  if (SerialBT.available()){
      char c = SerialBT.read();
      if (c == 'a'){
        moveForward();
        Serial.println('a');
      } else if (c == 'b'){
        turnLeft();
        Serial.println('b');
      } //else if (c == 'c'){
        //turnRight();
        //Serial.println('c');
      //}
  }

}


void moveForward() {
 
    StepsRequired = STEPS_PER_OUT_REV *  240/360;  // 360 degrees
    stepper1.setMaxSpeed(1000.0);
    stepper1.move(StepsRequired);
    stepper1.setSpeed(stepperSpeed);

    stepper2.setMaxSpeed(1000.0);
    stepper2.move(-StepsRequired);
    stepper2.setSpeed(stepperSpeed);

    // Wait for both steppers to reach the target position
    while (stepper1.distanceToGo() != 0 && stepper2.distanceToGo() != 0) {
      stepper1.runSpeedToPosition();
      stepper2.runSpeedToPosition();
    }

}

void turnLeft() {
    StepsRequired = STEPS_PER_OUT_REV * 300/360;  // 360 degrees
    stepper1.setMaxSpeed(1000.0);
    stepper1.move(StepsRequired);
    stepper1.setSpeed(stepperSpeed);

    stepper2.setMaxSpeed(1000.0);
    stepper2.move(StepsRequired);
    stepper2.setSpeed(stepperSpeed);

    // Wait for both steppers to reach the target position
    while (stepper1.distanceToGo() != 0 && stepper2.distanceToGo() != 0) {
      stepper1.runSpeedToPosition();
      stepper2.runSpeedToPosition();
    }
     StepsRequired = STEPS_PER_OUT_REV * 220 / 360;  // 360 degrees
    stepper1.setMaxSpeed(1000.0);
    stepper1.move(StepsRequired);
    stepper1.setSpeed(stepperSpeed);

    stepper2.setMaxSpeed(1000.0);
    stepper2.move(-StepsRequired);
    stepper2.setSpeed(stepperSpeed);

    // Wait for both steppers to reach the target position
    while (stepper1.distanceToGo() != 0 && stepper2.distanceToGo() != 0) {
      stepper1.runSpeedToPosition();
      stepper2.runSpeedToPosition();
  }
}

this is my code sir i have trouble when press button forward only stepper 1 move and stepper 2 don t move but LED driver on stepper 2 B and D the light is on but A and C dont the light is off why this happen sir, please

--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/accelstepper/cd96ef52-60be-4115-9fd2-aab17c4c6f39n%40googlegroups.com.

Jim Larson

unread,
Jun 5, 2024, 2:15:49 PMJun 5
to accelstepper
If stepper1 is moving and stepper2 is not, you may want to carefully check you wiring. If it looks ok, then try commenting out the stepper1 calls and just call stepper2 functions. You should be able to make stepper2 move.

There may be other problems in you code, but stepper2 should move if you press FORWARD.

               -jim

Alfito Desmon

unread,
Jun 5, 2024, 10:42:29 PMJun 5
to accels...@googlegroups.com
oke thank you sir but i have question can i get more speed of stepper motor 28byj-48, actually i only get default Max speed 1000 

Reply all
Reply to author
Forward
0 new messages