I have been having a wired Issue which I couldn't solve during the last two days :( I'm building a winding machine using a stepper. The Stepper runs fine with basic Arduino code but the stepper only vibrates strangely when using a Stepper Library such as Acellstepper or the Arduino Stepper Library. I've tried Full and Microsteps but same result.
Hardware overview:
I'm using a Bigtreetech TMC2208 driver with a 1 amp Stepper Online Nema 17 and a standard ESP32 as a brainbox. The TMC driver is configured for legacy mode (UART is also possible) and I had to swap two motor leads because for some reason the Driver has a different Coil Pinout than a standard A4988.
Wiring goes as follows:
GND - ESP GND
VIO - ESP 3v
STEP- ESP 25
DIR -ESP 26
EN - ESp GND
VM - 9v Powersupply
GND - 9v Powersupply GND
OB1,2 and OA1,2 to the stepper
This code works without issue, but I want to use a Library for acceleration and easier distance calculations.
// Motor pins
#define Step 25
#define Dir 26
#define ENCODER_PIN_A 12
#define ENCODER_PIN_B 13
volatile long pulseCount = 0;
void setup()
{ Serial.begin(9600);
pinMode(Dir, OUTPUT);
pinMode(Step, OUTPUT);
digitalWrite(Dir, LOW);
pinMode(ENCODER_PIN_A, INPUT_PULLUP);
pinMode(ENCODER_PIN_B, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(ENCODER_PIN_A), handleEncoderInterrupt, CHANGE);
}
void doMotorStep()
{
digitalWrite(Step, HIGH);
delayMicroseconds(350); //lower = faster, but louder
digitalWrite(Step, LOW);
delayMicroseconds(350);
}
void handleEncoderInterrupt() {
int encoderA = digitalRead(ENCODER_PIN_A);
int encoderB = digitalRead(ENCODER_PIN_B);
if (encoderA == HIGH && encoderB == LOW) {
pulseCount++;
} else if (encoderA == LOW && encoderB == HIGH) {
pulseCount--;
}
}
void loop()
{
doMotorStep();
}
On the other hand, this simple Accel-Stepper example only causes vibration from the stepper.
#include <AccelStepper.h>
#define stp 25
#define dir 26
// Define a stepper and the pins it will use
AccelStepper stepper(1, stp, dir);
void setup()
{
//Stepper Setup
stepper.setMaxSpeed(40);
stepper.setSpeed(20);
//stepper.move(5000);
}
void loop() {
stepper.runSpeed();
}
If someone has any suggestions where the Problem might be I would be really grateful. I've bee troubleshooting this for 2 days but got nowhere so far.