Hello,
i am trying to run a nema 17 stepper motor with a cnc shield, arduino uno and a4998 driver. I have identified the coil pairs to be black + green and red +blue. they have been connected to pins 1a/b and 2a/b of the driver. This can be reviewed in this picture:
The power source of the shield is 12V/4a and i also tried 24v/4a. The arduino is run via usb. The potentiometer is set to 1V. I tried running several programs such as:
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int stepCount = 0; // number of steps the motor has taken
void setup() {
// nothing to do inside the setup
}
void loop() {
// read the sensor value:
int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
// set the motor speed:
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution / 100);
}
}
I have exchanged every single component as well and the motor only vibrates and does not turn as intended. Any Suggestions?
Apart from other possible errors the setSpeed() may garble the stepper position, so that it repeats the same steps (state 0, state 1) with every step(). What if you make it 4 steps with every iteration?
Try this modified simple stepper code. I added setting up the enable pin (necessary with the CNC shield) and set the pins to be compatible with the CNC shield Uno pins for the X axis motor. The code should step the motor 1000 steps CW, pause and then step 1000 steps CCW. Tested with my Uno and CNC shield (same as yours).
// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// this version uses delay() to manage timing
byte directionPin = 5;
byte stepPin = 2;
byte enablePin = 8; // must enable steppers.
int numberOfSteps = 1000;
byte ledPin = 13;
int pulseWidthMicros = 20; // microseconds
int millisbetweenSteps = 10; // milliseconds - or try 1000 for slower steps
void setup() {
Serial.begin(115200);
Serial.println("Starting StepperTest");
digitalWrite(ledPin, LOW);
delay(2000);
pinMode(directionPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode (enablePin, OUTPUT);
digitalWrite(enablePin, LOW);
digitalWrite(directionPin, HIGH);
for(int n = 0; n < numberOfSteps; n++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(pulseWidthMicros); // this line is probably unnecessary
digitalWrite(stepPin, LOW);
delay(millisbetweenSteps);
digitalWrite(ledPin, !digitalRead(ledPin));
}
delay(2000);
digitalWrite(directionPin, LOW);
for(int n = 0; n < numberOfSteps; n++) {
digitalWrite(stepPin, HIGH);
// delayMicroseconds(pulseWidthMicros); // probably not needed
digitalWrite(stepPin, LOW);
delay(millisbetweenSteps);
digitalWrite(ledPin, !digitalRead(ledPin));
}
}
void loop() {
}
groundFungus:
Try this modified simple stepper code. I added setting up the enable pin (necessary with the CNC shield) and set the pins to be compatible with the CNC shield Uno pins for the X axis motor. The code should step the motor 1000 steps CW, pause and then step 1000 steps CCW. Tested with my Uno and CNC shield (same as yours).
Unfortunatly still nothing is moving. What else can I check?
take one pair of wires from one coil
take them off the output of the driver board.
reverse them
if wire 1 is on terminal a
wire 2 on terminal b
move wire 1 to terminal b
and put wire 2 on terminal a
do not touch the other coil / wires
test
===============
a high pitched sound is often missing steps.
make sure you can turn your motor easily with just your fingers
make sure your ramp speed is slow enough
make sure you are at 1/2 or 1 or 1/4 step,
do not try to micro step at this testing stage.
So an update: when i connect the power source the motor sometimes moves a few step. however after that it stops again sometimes clicking, sometimes just high pitched sound. When disconnecting and connecting repeatedly and quickly it moves even more. Does this indicate anything?
pmaxd:
So an update: when i connect the power source the motor sometimes moves a few step. however after that it stops again sometimes clicking, sometimes just high pitched sound. When disconnecting and connecting repeatedly and quickly it moves even more. Does this indicate anything?
It worked!!! I am not certain, what the mistake was. I switched back to a previously used cnc shield and tried the 24V powersource again and now its turning.... Thank you everybody