Hello everybody,
i have some issue mit microstepping of A4988. Namely, i want to control stepper motor (42shdc3025-24b from 3d printer) with ESP32, A4988 and RemoteXY app through bluetooth. I wanted to use microstepping 1/16 by connecting all MS outputs to +5v. The application seems to work, but motor makes always 2 rotations instead of 1 independent on connection of MS - the same operation when MSs are connected to GND or 5v. For one revolution I use 200 steps (with 1,8° rotation per step). I tried with new A4988, but no change in operation. Circuit and code are shown below. I supply motor with 12v.
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP32CORE_BLE
#include <BLEDevice.h>
// RemoteXY connection settings
#define REMOTEXY_BLUETOOTH_NAME "RemoteXY"
#include <RemoteXY.h>
// RemoteXY GUI configuration
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] = // 43 bytes
{ 255,2,0,0,0,36,0,17,0,0,0,4,1,106,200,1,1,2,0,1,
30,29,50,50,0,2,31,226,173,161,0,1,31,101,48,48,0,2,31,226,
173,163,0 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
uint8_t button_forward; // =1 if button pressed, else =0
uint8_t button_backward; // =1 if button pressed, else =0
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#define DIR_PIN 12
#define STEP_PIN 14
void setup()
{
RemoteXY_Init ();
pinMode(DIR_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
// TODO your setup code
}
void stepMotor(int dir) {
digitalWrite(DIR_PIN, dir);
for (int x = 0; x < 200; x++) {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(1000); // Adjust delay for speed control
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(1000); // Adjust delay for speed control
}
}
void loop()
{
RemoteXY_Handler ();
if (RemoteXY.button_forward) {
stepMotor(HIGH); // Move forward
}
if (RemoteXY.button_backward) {
stepMotor(LOW); // Move backward
}
}
I would appreciate for hints how to solve this issue. One question: should motor make only some part of revolution when microstepping is set given the same amount of steps in for loop?
Best regards