I am trying to use a Stepper Motor, A4988 and Potentiometer Speed Control who was setup
by someone else. The setup was working fine until it was unplugged and left for a few weeks and now since trying to turn it back on, it's not doing anything. I have no copy of the original code that was used.
I've found some basic code from howtomechatronics but I'm not having any luck.
// defines pins
#define stepPin 2
#define dirPin 5
int customDelay, customDelayMapped;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop() {
speedControl();
// Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
digitalWrite(stepPin, HIGH);
delayMicroseconds(customDelayMapped);
digitalWrite(stepPin, LOW);
delayMicroseconds(customDelayMapped);
}
// Custom function for reading the potentiometer and mapping its value from 300 to 3000, suitable for the custom delay value in microseconds
void speedControl() {
customDelay = analogRead(A0); // Read the potentiometer value
customDelayMapped = map(customDelay, 0, 1023, 300, 3000); // Convert the analog input from 0 to 1024, to 300 to 3000
}
The motor is powered from a 24V external power supply and when everything is turned on, the motor does not react.
It's not the schematic.
I did a search for 22185-stepper driver, came up with nothing.
What you need to do is disassemble everything and use an ohmmeter to see which points on the shield are connected to which Arduino pins.
I can see connections from Arduino digital pins 4, 5, and 7 going towards the daughter board.
You need to check which pins they connect to on the plug in driver board, and then adjust the code accordingly.
Looking at the A4988 connection diagram that I found at https://www.pololu.com/product/2128 , together with your photos, it looks to me as though Arduino digital pin 4 is connected to the step pin.
(Arduino digital pin 5 looks as though it is connected to the dir pin, which is what the code expects.)
Check whether that is the case.
If it is then you need to change
#define stepPin 2
to
`#define stepPin 4`
EDIT:
Annotated photo added.
Now that I have seen the new photo that you included in post #9, I can see that pin 7 goes to the !ENABLE pin on the A4988 driver board.
Pin 7 needs to be taken low to enable the stepper motor driver.
Try this modified code, which takes pin 7 low to enable the A4988 driver, and uses pin 4 for the stepPin.
// defines pins
#define stepPin 4
#define dirPin 5
#define enablePin 7
int customDelay, customDelayMapped;
void setup() {
// Sets the three pins as Outputs
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(enablePin, OUTPUT);
// take the enablePin LOW, to enable the A4988 driver
digitalWrite(enablePin, LOW);
}
void loop() {
speedControl();
// Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
digitalWrite(stepPin, HIGH);
delayMicroseconds(customDelayMapped);
digitalWrite(stepPin, LOW);
delayMicroseconds(customDelayMapped);
}
// Custom function for reading the potentiometer and mapping its value from 300 to 3000, suitable for the custom delay value in microseconds
void speedControl() {
customDelay = analogRead(A0); // Read the potentiometer value
customDelayMapped = map(customDelay, 0, 1023, 300, 3000); // Convert the analog input from 0 to 1024, to 300 to 3000
}
I would've thought so too, because I don't see anything that would limit its rotation. Here's a video of what it's doing and a picture of the wiring. I've since crimped all the cables but I highlight doubt that would've changed anything?
I don't see any hardware there to tell the stepper where it is. One solution in such cases is a limit switch and you have to use it to index the motor on startup.
Sorry, I misworded what I was suggesting. What I was trying to get at was that I want the motor to fully rotate as opposed to only rotating a few degrees then stopping.
From what I can see in the video it is not rotating at all, only twitching.
Did you check the wiring motor<->A4988 to have the motor coils correctly connected to the driver? Do you know which wires belong to one coil respectively?