Microstepping not working with ESP32 and A4988

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

Please don't show such a general schematic, but exactly your schematic. Especially the voltages you supply to your devices.

Ok, sorry. Is this better?

Yes, it is. But I miss the bulk capacitor between Vmot and Gnd.
And as the ESP is a 3.3V device, Vdd and all inputs of the A4988 should be 3.3V too.

I moved your topic to a more appropriate forum category @przem11.

The Nano ESP32 category you chose is only used for discussions directly related to the Arduino Nano ESP32 board.

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

Thanks in advance for your cooperation.

Usually a 3.3 volt logic high is good enough for a 5 volt input. No problem using a 5 volt Vdd as the A4988 has no output connected to the 3.3 volt ESP.
What do You think?

Ok, capacitor added.
It is not necessary to provide 3.3V to the ESP board. Since you have a linear regulator on the board with 3.3V output, it is not recomended to put too high input voltage, 5V is enough.
And you could also use USB to power the board, of course, which provides 5V and it works as well.
Regarding A4988, you have VDD in range 3.0 - 5.5V input voltage, so 5V is ok (also checked in previous experiments).
I tried now providing 3.3v to MS inputs and microstepping is working (in another circuit I provided 5v and was working as well).
Thank you advices!

Welcome to the forum.

What was wrong ? A combination of: voltage mismatch, some noise, maybe a counterfeit A4988 ?

The A4988 works at 3.0 - 5.5V as you wrote, but the input signals has to be at least 0.7 * VDD for a valid high level.
0.7 * 5V = 3.5V. The ESP32 can not give that. Therefor I agree with MicroBahner, use the A4988 at 3.3V (VDD and all the digital signals with 3.3V).

1 Like

That was a surpricingly high level for a logic 1. But, but, datasheet apply.

Hello,
thank you for explanation, I changed voltage for VDD 3.3v and microstepping is working as well. Now logic for A4988 is only 3.3V. Reagrding voltage mismatches I cannot say now what was the reason.
But I still do not know why with 200 steps in code (by pressing button) and 1/16 step, shaft is rotating as motor would make 400 steps, as twice as needed. I think there is some issue with procedure handling RemoteXY buttons.
As a check I put simple code before RemoteXY_Handler () to see if motor will make more steps as needed and that was not the case - one full rotation with 3200 steps and 1/16 microstepping so its correct I assume.

if (flag == HIGH) {
    digitalWrite(DIR_PIN, LOW);
    for (int x = 0; x < 3200; x++) { //full revolution by 1/16 step
      digitalWrite(STEP_PIN, HIGH);
      delayMicroseconds(1000); // Adjust delay for speed control
      digitalWrite(STEP_PIN, LOW);
      delayMicroseconds(1000); // Adjust delay for speed control
    }
    flag = LOW;
}

Ok, as small update, maybe someone will find this usefull: somehow status of buttons (after tapping in mobile app) is saved twice, so that stepper motor makes one batch of steps and then once again the same (even when I am clicking very fast :wink: ). I added one line of code to try to deactivate the second status and so far works as desired:
RemoteXY.button_forward = false; --> before going to stepper motor procedure.

Have a good day everybody

1 Like

Thanks for the update.
Could it be that a message "button pressed down" and "button released" are transmitted ?
It might be worth to investigate it, to avoid surprises.

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