I need a simple peace of code written that will make a stepper motor do a few things.
I am using the stepper driver TB6600 and a nema 23 stepper motor
- step counter clockwise 3200 steps
- pause 2 seconds
- step clockwise 800 steps
- pause 2 seconds
- step clockwise 800 steps
- pause 2 seconds
- step clockwise 800 steps
- pause 2 seconds
- step clockwise 800 steps
- pause 2 seconds
- repeat
ena+ pin 2
ena- pin gnd
dir+ pin 3
dir- pin gnd
pul+ pin 4
pul- pin gnd
I do need the ability to control the speed of the stepper in the code.
I do not need any interface. i just need it to run this routine over and over for testing purpose.
let me know how this goes
int PUL=4; //define Pulse pin
int DIR=3; //define Direction pin
int ENA=2; //define Enable Pin
void setup() {
pinMode (PUL, OUTPUT);
pinMode (DIR, OUTPUT);
pinMode (ENA, OUTPUT);
digitalWrite(ENA,LOW);
}
void loop() {
//take the 3200 counterclockwise
for (int i=0; i<3200; i++)
{
stepCounterClockwise();
}
delay(2000);
for (int i=0; i<800; i++)
{
stepClockwise();
}
delay(2000);
for (int i=0; i<800; i++)
{
stepClockwise();
}
delay(2000);
for (int i=0; i<800; i++)
{
stepClockwise();
}
delay(2000);
for (int i=0; i<800; i++)
{
stepClockwise();
}
delay(2000);
}
//a single revolution at shared settings takes 200 pulses
void stepClockwise()
{
digitalWrite(DIR,LOW);
digitalWrite(PUL,HIGH);
delayMicroseconds(50);
digitalWrite(PUL,LOW);
delayMicroseconds(50);
}
void stepCounterClockwise()
{
digitalWrite(DIR,HIGH);
digitalWrite(PUL,HIGH);
delayMicroseconds(50);
digitalWrite(PUL,LOW);
delayMicroseconds(50);
}