Clear all

Stepperonline motor  

New Member
Joined: 1 year ago
Posts: 3
Topic starter  

Hello All. I got this nema 34 stepper motor. It works pretty nice, But I'm having two issues I can't figure out. When I enable it, there is a delay of about a second before it actually starts. I know it's not the enable signal because I piggybacked some LED's onto the inputs and it is immediate. The 2nd issue is that when I start and or stop it, the limits change by about an 1/8 of a revolution. I originally had it controlled by a VB pgm from a laptop, but have since changed to one of those Nextion HMI's. I've included my sketch and a link to a video of it in operation. I've also ordered to programming cable for tuning the drive, but coming from china who knows when it'll arrive. On a final note. My main buck converter burned up and when it did it sent 60 VDC to the Arduino and the 2nd buck converter, but the 2nd one burned closed, not open so it looks like my Nextion is still good. SO, I have new Buck converters ordered and should be here next week. If anyone has an Idea about the delay or the set points changing, I would be happy to try them. Thanks.


//Declare pin functions on Redboard
#define stp 2
#define dir 3
#define EN 6


//Declare variables for functions
char input;
//bool zero=false;
bool onetime=false;
//int target=3000;
int ontime =16099;// range NEMA34, 16099 to 1.6
int offtime =2.5;
int posSP =200;
int negSP =-200;
int current =0;
bool rotation= true;
bool enabled=false;
bool oscillate=false;

void setup() {
// put your setup code here, to run once:
pinMode(stp, OUTPUT);
pinMode(dir, OUTPUT);
pinMode(EN, OUTPUT);

// resetEDPins(); //Set step, direction, microstep and enable pins to default states
Serial.begin(9600); //Open Serial connection for debugging

digitalWrite(dir, HIGH); //Pull direction pin "High, Positive,CW"
digitalWrite(EN, HIGH); //Enable

// Main Loop*************************************************************************************************************************************************************************************************************************************************************

void loop()
static unsigned long lasttime = 0;
const long interval = 10;
unsigned long now = millis();
//if ((now - lasttime > interval)&&(enabled==true)) }



input =; //Read user input and trigger appropriate function

// characters used ......................0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D ,L ,U , Z

if (input =='0')
{digitalWrite(EN,HIGH);//high = disabled
(enabled =(false));

if(input =='1')
{digitalWrite(EN,LOW);//low = enabled
(enabled =(true));
if (input =='2')
{digitalWrite(dir,HIGH);// positive

if(input =='3')
{digitalWrite(dir,LOW);// negative

// Fast speed decrease
if((input =='4')&&(ontime<15777))//NEMA= 15777
{ontime= int(ontime+(ontime*.25));


// Fast speed increase
if((input =='5')&&(ontime > 10))
{ontime= int(ontime -(ontime/5));

//Maintained speed decrease
if((input =='8')&&(ontime<15777))//NEMA= 15777
{ontime= int(ontime+(ontime*.25));


//Maintained speed increase

if((input =='9')&&(ontime > 10))
{ontime= int(ontime -(ontime/5));

if(input =='A')//VB jog button mouse down
{digitalWrite(EN,LOW);//}//low = enabled

if (input =='B')// VB jog button mouse up
{digitalWrite(EN,HIGH);//}//high = disabled

if (input =='C')// over ride positive set point limit

if (input =='D')// over ride negative set point limit

if (input =='Z')// set zero at current position

if (input =='U')// set upper limit at current position

if (input =='L')// set lower limit at current position

if (input =='O')//Oscillate
if (oscillate==false)
else if (oscillate==true)
//PLUS 100
if((input =='6')&&(ontime<16998))//NEMA= 16998
{ontime= (ontime +100);

//MINUS 100
if((input =='7')&(ontime > 199))
{ontime= (ontime -100);



//run motor**************************************************************************************************************************************************************************************************************************************************
if ((oscillate==true)&&(negSP==current))
{ rotation=(true);
else if ((oscillate==true)&&(posSP==current))

{digitalWrite(stp,HIGH); //Trigger one step forward


if ((current==posSP)&&(rotation==true))
{digitalWrite(EN,HIGH);//}//high = disabled
(enabled =(false));}
else if ((enabled==true)&&(rotation==true))


else if ((current==negSP)&&(rotation==false))
{digitalWrite(EN,HIGH);//}//high = disabled
(enabled =(false));}
if ((enabled==true)&&(rotation==false))

digitalWrite(stp,LOW); //Pull step pin low so it can be triggered again