I am at the moment trying to make a stepper motor move, but having problems doing so.
I am interfacing it through a control board, which takes the input Step, Dir, En, and 5V.
I am providing those inputs signal from an arduino, but can't get the damn thing to move. all it does it move a step forward and backwards, like it being stuck or and tries to wiggle out of something.. What could the reason be..
The code i am running om my arduino is this:
#include "stepper_motor.h"
int max_step = 200;
stepper_motor::stepper_motor()
{
pinMode(BUILTIN_LED,OUTPUT);
pinMode(step_pin,OUTPUT);
pinMode(dir_pin,OUTPUT);
pinMode(en_pin,OUTPUT);
alive_bool = true;
position_bool = false;
step_count = 0;
}
void stepper_motor::step_pwm()
{
if(position_bool==true)
{
//Dir pin low
digitalWrite(step_pin, LOW);
digitalWrite(dir_pin,LOW);
digitalWrite(en_pin,LOW);
delay(0.005);
digitalWrite(step_pin, LOW);
digitalWrite(dir_pin,LOW);
digitalWrite(en_pin,HIGH);
delay(0.005);
int step = 0;
while(step < max_step)
{
digitalWrite(step_pin,HIGH);
delay(1);
digitalWrite(step_pin,LOW);
delay(1);
}
//digitalWrite(en_pin,LOW);
//position_bool = false;
}
else
{
//Dir pin high
delay(1000);
digitalWrite(step_pin, LOW);
digitalWrite(dir_pin,LOW);
digitalWrite(en_pin,LOW);
delay(0.005);
digitalWrite(step_pin, LOW);
digitalWrite(dir_pin,LOW);
digitalWrite(en_pin,HIGH);
delay(0.005);
digitalWrite(step_pin, LOW);
digitalWrite(dir_pin,HIGH);
digitalWrite(en_pin,HIGH);
int step = 0;
while(step < max_step)
{
digitalWrite(step_pin,HIGH);
delay(1);
digitalWrite(step_pin,LOW);
delay(1);
}
//digitalWrite(en_pin,LOW);
//position_bool = true;
}
}
h. file
/* Class: stepper_motor
* Info: contains the setup, and primary interface to control
* the stepper motor
*
* stepper_motor(): constructor - setup the connection to the control board
* void step_pwm(): Moves the tilt - uses the bool to determine the direction.
* bool alive_bool: Is either high (1) or low (0), used for the alive void.
*/
#ifndef stepper_motor_h
#define stepper_motor_h
#include "Arduino.h"
#include "pins_arduino.h"
#define step_pin D1
#define dir_pin D2
#define en_pin D3
class stepper_motor
{
public:
stepper_motor();
void alive();
void init_communication();
void step_pwm();
private:
bool alive_bool;
bool position_bool;
};
#endif
pins_arduino.h is available here https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/variants/standard/pins_arduino.h
And this is how it is connected.
See attachment.