I'm messing around with a stepper motor, powering it with a driver and using an arduino uno r3 to run it. When the motor is at rest it has very small vibrations and I'm not sure if it's supposed to. They're small enough I can only hear them when the motor is close to my ear. I'm using an A4988 motor driver, Elegoo Uno R3 as the arduino, and have them hooked together using a breadboard. It also has a button I use to turn it on. The motor works just fine, it spins and whatnot with no problem, no bad noise or vibrations. The code is also here in case it's important, although I'm not sure where the problem would be in it.
#define step 4
#define dir 1
#define button 8
void setup() {
// put your setup code here, to run once:
pinMode(step, OUTPUT);
pinMode(dir, OUTPUT);
pinMode(button, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(button) == HIGH){
dynamic_rotate(10, HIGH, 350, 1500, 2);
}
}
void dynamic_rotate(float rotations, int direction, int speed, int start_speed, int accel){
//rotations, float, number of rotations you want the motor to achieve, will round to nearest STEP
//direction, word??, HIGH for forwards, LOW for reverse
//speed, int, final delay in microseconds between phases
//start_speed, int, initial delay in microseconds between phases
//accel, int, difference in delays between each time of start speed
digitalWrite(dir, direction);
delay(1000);
int cur = start_speed;
int tracker = 0;
for(int x = 0; x < lround(200*rotations); x++){
digitalWrite(step, HIGH);
delayMicroseconds(cur);
digitalWrite(step, LOW);
delayMicroseconds(cur);
tracker += 2*cur;
if (cur != speed){
if (tracker >= start_speed){
cur -= accel;
tracker = 0;
}
}
if (digitalRead(button) == HIGH){
break;
}
}
}