Nema 34 stepper motor

Hello

I would like to hook up my arduino board to a nema 34 stepper motor and use it to grind circular saw teeth. All is wired up ( power supply, driver, nema 34 stepper motor, arduino).

The motor should turn when button is pushed. The saw has 92 teeth, so the motor should turn 3,913 deg. per tooth.

As im new to this any advice would be great.

br.

As im new to this any advice would be great.

Get off your duff. Write some code. Show it to us. Explain what it actually does, and how that differs from what you want, if it doesn't work properly.

That's my advice.

so the motor should turn 3,913 deg. per tooth.

Do you have a clue how a stepper motor works?

Most stepper motors have 200 steps per revolution so you are going to need some gearing to match that to your 92 teeth.

If you want to locate your saw very precisely you will probably want to arrange things so that it takes many steps of the motor to advance one tooth.

Can you post a diagram showing how the motor will cause the blade to advance?

I wonder if this is a job for a stepper motor at all? Maybe some system with a retractable detent that locates each tooth would be more accurate and simpler?

...R Stepper Motor Basics Simple Stepper Code

so the motor should turn 3,913 deg. per tooth.

Use a 1.8 degree/step motor and gear it up by the ratio 3.913/1.8 or take several 1.8 degree steps, and gear that down appropriately.

Hello

All wired up, LCD, Stepper motor Nema34 + driver DQ860MA, keypad, arduino board... The rotary table is not connected. The stepper motor driver is set to 400puls/revolution.

When i set the device to turn 360deg, it doesn't move 360 deg, but it moves about 340 deg - it does not make 1 whole revolution.... it takes about 5 revolutions whole to get on the same place.

What could be wrong ? im using this code.

/*
 4x4 matrix keypad amd a 20 x 4 LCD. 
 Edit StepsPerRotation & TableRatio(# of turns for 360 degrees)in line 29
 A4988 Stepstick/Pololu driver 
 5/2/2015
 */

 #include  
 #include 
 #include 

 const byte ROWS = 4;
 const byte COLS = 4;
 char keys[ROWS][COLS] = {
 {'1','2','3','A'},
 {'4','5','6','B'},
 {'7','8','9','C'},
 {'.','0','#','D'}
 };

 byte rowPINS[ROWS] = {11,10,9,8};
 byte colPINS[COLS] = {7,6,5,4};

 Keypad kpd = Keypad(makeKeymap(keys),rowPINS,colPINS, ROWS, COLS);
 LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x20 for a 16 chars and 4 line display
                                   // SCL - A5, SDA - A4, VCC - +5, Gnd - Gnd 
 //setup vars
 const int stp = 2;               // connect pin 2 to step
 const int dir = 3;               // connect pin 3 to dir
 const int StepsPerRotation = 400; // Set Steps per rotation of stepper NOTE the driver is set to Half step
 const int TableRatio = 1;        // ratio of rotary table
 const int Multiplier = (StepsPerRotation * TableRatio)/360;  // 200*90=18000/360 = 50
 const int stepdelay = 1;
 float Degrees = 0;                // Degrees from Serial input
 float ToMove = 0;                 // Steps to move
 float bob = 0;
 int cho = 0;

 void setup()
 {
 lcd.init();      // initialize the lcd 
 pinMode(stp, OUTPUT);
 pinMode(dir, OUTPUT); 

 // Print welcome message to the LCD.
 lcd.backlight();
 lcd.print("Rotary Table Control");
 lcd.setCursor(4,2);
 lcd.print(" ");
 lcd.setCursor(3,3);
 lcd.print("updated 2016");
 delay(2000);
 lcd.init();
   cho = 0;
   char key = kpd.getKey();
   lcd.print("Enter Selection:");   
   lcd.setCursor(0,1);
   lcd.print("Degrees   = A");
   lcd.setCursor(0,2);
   lcd.print("Divisions = B");
   lcd.setCursor(0,3);
   lcd.print("JOG       = C");
   while(cho == 0)
   {
     key = kpd.getKey();
     switch (key)
     {
     case NO_KEY:
      break;
     case 'A':
       Degrees=getdegrees();
       lcd.clear();
       cho = 1;
       break; 
     case 'B':
       Degrees=getdivisions();  
       cho=2;
       break;
     case 'C':
       Degrees=getjog();
       lcd.clear();
       cho=3;
       break;
       }      // end case
     }      // end while cho=0
 }    // end setup

 void loop()      // MAIN LOOP
 {
   lcd.clear();  
   char key = kpd.getKey();
     bob = 0;
     lcd.setCursor(7,0);lcd.print("Total:  ");lcd.print(bob,2);   // total steps
     lcd.setCursor(0,3);lcd.print("FOR=A   REV=B    X=C");
   while(key != 'C')    // C will return to start menu
   {
     lcd.setCursor(0,0);lcd.print(abs(Degrees),2);lcd.print((char)223);
     key = kpd.getKey();
     if(key == 'A')            // FORWARD
       {
        bob = bob + Degrees;
        ToMove = (Degrees*Multiplier);
        digitalWrite(dir, LOW);
        printadvance();
       }
     if(key=='B')              // REVERSE
       {
        bob = bob - Degrees;  
        ToMove = (Degrees*Multiplier);
        digitalWrite(dir, HIGH);    // pin 13
        printadvance();
       }
   }      // end while not C loop
   lcd.init();
  setup();
 }      // end main VOID


float getjog()
{
  float Degrees = 0;
  float num = 0.00;
   char key = kpd.getKey();
   lcd.clear();
   lcd.setCursor(6,0);lcd.print("Jogging");
   lcd.setCursor(0,1);lcd.print("A=1 B=10 C=100 Steps");
   lcd.setCursor(0,2);lcd.print("Enter Degrees:");lcd.setCursor(0,3);lcd.print("OK = #       ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");

   while(key != '#')
   {
      switch (key)
      {
         case NO_KEY:
            break;
         case 'A':
            Degrees = 1;      
            lcd.setCursor(14,2);lcd.print(Degrees);
            break;
         case 'B':
            Degrees = 10;
            lcd.setCursor(14,2);lcd.print(Degrees);
            break;
         case 'C':
            Degrees = 100;
            lcd.setCursor(14,2);lcd.print(Degrees);
            break;
         case 'D':
          num=0.00;
          lcd.setCursor(14,2);lcd.print("     ");
          lcd.setCursor(14,2);
          break;
      }
      key = kpd.getKey();
   }
  return Degrees; 
}


float getdivisions()
{
  float Degrees = 0; 
  float num = 0.00;
   char key = kpd.getKey();
   lcd.clear();
   lcd.setCursor(0,1);lcd.print("Enter Division:");lcd.setCursor(0,3);lcd.print("OK = #       ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");
   lcd.setCursor(16,1);

   while(key != '#')
   {
      switch (key)
      {
         case NO_KEY:
            break;
            
         case '0': case '1': case '2': case '3': case '4':
         case '5': case '6': case '7': case '8': case '9':
            num = num * 10 + (key - '0');
            lcd.print(key);
            break;
        
        case 'D':
          num=0.00;
          lcd.setCursor(16,1);lcd.print("     ");
          lcd.setCursor(16,1);
          break;
      }
      Degrees = 360/num;
      key = kpd.getKey();
   }
  return Degrees;  //num;
}


float getdegrees()
{ 
   //int key = 0;
   float num = 0.00;
   float decimal = 0.00;
   float decnum = 0.00;
   int counter = 0;
   lcd.clear();
   //lcd.init();
   char key = kpd.getKey();
   lcd.setCursor(0,1);lcd.print("Enter Degrees:");lcd.setCursor(0,3);lcd.print("OK = #       ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");
   lcd.setCursor(15,1);
   bool decOffset = false;

   while(key != '#')
   {
      switch (key)
      {
         case NO_KEY:
            break;
            
         case '.':
           if(!decOffset)
           {
             decOffset = true;
           }
            lcd.print(key);
            break;   
         
         case 'D':
          num=0.00;
          lcd.setCursor(15,1);lcd.print("     ");
          lcd.setCursor(15,1);
          break;
         
         case '0': case '1': case '2': case '3': case '4':
         case '5': case '6': case '7': case '8': case '9':
         if(!decOffset)
         {
            num = num * 10 + (key - '0');
            lcd.print(key);
         }
         else if((decOffset) && (counter <= 1))
         {
            num = num * 10 + (key - '0');
            lcd.print(key);
            counter++;
         }
            break;
      }    //end case
      decnum = num / pow(10, counter);
      key = kpd.getKey();
   }    //end while not #
    return decnum;
}      // end getdegrees

 void printadvance()      // print function
   {
     lcd.setCursor(6,1);lcd.print("Moving");
     lcd.setCursor(4,2);lcd.print("Steps  ");lcd.print(ToMove,0); 
     lcd.setCursor(13,0);lcd.print(bob,2);
     rotation(ToMove,0);
     lcd.setCursor(6,1);lcd.print("      "); 
  } 

 void rotation(float tm, int d)
   { 
     for(int i = 0; i < tm; i++) 
       { 
       digitalWrite(stp, HIGH); 
       delay(stepdelay); 
       digitalWrite(stp, LOW); 
       delay(stepdelay); 
       }
   }

void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
  {
  asm volatile ("  jmp 0");  
  }

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :)

colorales: When i set the device to turn 360deg, it doesn't move 360 deg, but it moves about 340 deg - it does not make 1 whole revolution.... it takes about 5 revolutions whole to get on the same place.

What could be wrong ? im using this code.

First, as @TomGeorge has said please modify your post and use the code button so your code looks like this and is easy to copy to a text editor.

And if you are having trouble getting a motor to move the correct number of steps start with a short program that does nothing else except move the motor. Look at the links I gave you back in February.

...R

sorry.... hope its ok now......

colorales: sorry.... hope its ok now......

The code is but you have not said what results you got when you tried a simple program to move the stepper motor?

...R

Hello :slight_smile: : ) :slight_smile:

I think I have solved the problem… I have made correction to the code in two places:

Original code:

ToMove = (Degrees*Multiplier);

Corrected code:

ToMove = (Degrees*Multiplier/360);

/*
 4x4 matrix keypad amd a 20 x 4 LCD. 
 Edit StepsPerRotation & TableRatio(# of turns for 360 degrees)in line 29
 A4988 Stepstick/Pololu driver 
 5/2/2015
 */

 #include <Wire.h> 
 #include <LiquidCrystal_I2C.h>
 #include <Keypad.h>
 
 const byte ROWS = 4;
 const byte COLS = 4;
 char keys[ROWS][COLS] = {
 {'1','2','3','A'},
 {'4','5','6','B'},
 {'7','8','9','C'},
 {'.','0','#','D'}
 };

 byte rowPINS[ROWS] = {11,10,9,8};
 byte colPINS[COLS] = {7,6,5,4};

 Keypad kpd = Keypad(makeKeymap(keys),rowPINS,colPINS, ROWS, COLS);
 LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x20 for a 16 chars and 4 line display
                                   // SCL - A5, SDA - A4, VCC - +5, Gnd - Gnd 
 //setup vars
 const int stp = 2;               // connect pin 2 to step
 const int dir = 3;               // connect pin 3 to dir
 //const int StepsPerRotation = 400; // Set Steps per rotation of stepper NOTE the driver is set to Half step
 const int StepsPerRotation = 400;
 //const int TableRatio = 36;        // ratio of rotary table
 const int TableRatio = 1;
 //const int Multiplier = (StepsPerRotation * TableRatio)/360;  // 200*90=18000/360 = 50
 const int Multiplier = (StepsPerRotation * TableRatio)/1;
 const int stepdelay = 1;
 float Degrees = 0;                // Degrees from Serial input
 float ToMove = 0;                 // Steps to move
 float bob = 0;
 int cho = 0;

 void setup()
 {
 lcd.init();      // initialize the lcd 
 pinMode(stp, OUTPUT);
 pinMode(dir, OUTPUT); 

 // Print welcome message to the LCD.
 lcd.backlight();
 lcd.print("Rotary Table Control");
 lcd.setCursor(4,2);
 lcd.print(" ");
 lcd.setCursor(3,3);
 lcd.print("updated 2016");
 delay(2000);
 lcd.init();
   cho = 0;
   char key = kpd.getKey();
   lcd.print("Enter Selection:");   
   lcd.setCursor(0,1);
   lcd.print("Degrees   = A");
   lcd.setCursor(0,2);
   lcd.print("Divisions = B");
   lcd.setCursor(0,3);
   lcd.print("JOG       = C");
   while(cho == 0)
   {
     key = kpd.getKey();
     switch (key)
     {
     case NO_KEY:
      break;
     case 'A':
       Degrees=getdegrees();
       lcd.clear();
       cho = 1;
       break; 
     case 'B':
       Degrees=getdivisions();  
       cho=2;
       break;
     case 'C':
       Degrees=getjog();
       lcd.clear();
       cho=3;
       break;
       }      // end case
     }      // end while cho=0
 }    // end setup
 
 void loop()      // MAIN LOOP
 {
   lcd.clear();  
   char key = kpd.getKey();
     bob = 0;
     lcd.setCursor(7,0);lcd.print("Total:  ");lcd.print(bob,2);   // total steps
     lcd.setCursor(0,3);lcd.print("FOR=A   REV=B    X=C");
   while(key != 'C')    // C will return to start menu
   {
     lcd.setCursor(0,0);lcd.print(abs(Degrees),2);lcd.print((char)223);
     key = kpd.getKey();
     if(key == 'A')            // FORWARD
       {
        bob = bob + Degrees;
                ToMove = (Multiplier);
        digitalWrite(dir, LOW);
        printadvance();
       }
     if(key=='B')              // REVERSE
       {
        bob = bob - Degrees;  
        ToMove = (Multiplier);
        digitalWrite(dir, HIGH);    // pin 13
        printadvance();
       }
   }      // end while not C loop
   lcd.init();
  setup();
 }      // end main VOID
 

float getjog()
{
  float Degrees = 0;
  float num = 0.00;
   char key = kpd.getKey();
   lcd.clear();
   lcd.setCursor(6,0);lcd.print("Jogging");
   lcd.setCursor(0,1);lcd.print("A=1 B=10 C=100 Steps");
   lcd.setCursor(0,2);lcd.print("Enter Degrees:");lcd.setCursor(0,3);lcd.print("OK = #       ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");

   while(key != '#')
   {
      switch (key)
      {
         case NO_KEY:
            break;
         case 'A':
            Degrees = 1;      
            lcd.setCursor(14,2);lcd.print(Degrees);
            break;
         case 'B':
            Degrees = 10;
            lcd.setCursor(14,2);lcd.print(Degrees);
            break;
         case 'C':
            Degrees = 100;
            lcd.setCursor(14,2);lcd.print(Degrees);
            break;
         case 'D':
          num=0.00;
          lcd.setCursor(14,2);lcd.print("     ");
          lcd.setCursor(14,2);
          break;
      }
      key = kpd.getKey();
   }
  return Degrees; 
}

 
float getdivisions()
{
  float Degrees = 0; 
  float num = 0.00;
   char key = kpd.getKey();
   lcd.clear();
   lcd.setCursor(0,1);lcd.print("Enter Division:");lcd.setCursor(0,3);lcd.print("OK = #       ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");
   lcd.setCursor(16,1);

   while(key != '#')
   {
      switch (key)
      {
         case NO_KEY:
            break;
            
         case '0': case '1': case '2': case '3': case '4':
         case '5': case '6': case '7': case '8': case '9':
            num = num * 10 + (key - '0');
            lcd.print(key);
            break;
        
        case 'D':
          num=0.00;
          lcd.setCursor(16,1);lcd.print("     ");
          lcd.setCursor(16,1);
          break;
      }
      Degrees = 360/num;
      key = kpd.getKey();
   }
  return Degrees;  //num;
}


float getdegrees()
{ 
   //int key = 0;
   float num = 0.00;
   float decimal = 0.00;
   float decnum = 0.00;
   int counter = 0;
   lcd.clear();
   //lcd.init();
   char key = kpd.getKey();
   lcd.setCursor(0,1);lcd.print("Enter Degrees:");lcd.setCursor(0,3);lcd.print("OK = #       ");lcd.print((char)60);lcd.print((char)45);lcd.print(" D");
   lcd.setCursor(15,1);
   bool decOffset = false;

   while(key != '#')
   {
      switch (key)
      {
         case NO_KEY:
            break;
            
         case '.':
           if(!decOffset)
           {
             decOffset = true;
           }
            lcd.print(key);
            break;   
         
         case 'D':
          num=0.00;
          lcd.setCursor(15,1);lcd.print("     ");
          lcd.setCursor(15,1);
          break;
         
         case '0': case '1': case '2': case '3': case '4':
         case '5': case '6': case '7': case '8': case '9':
         if(!decOffset)
         {
            num = num * 10 + (key - '0');
            lcd.print(key);
         }
         else if((decOffset) && (counter <= 1))
         {
            num = num * 10 + (key - '0');
            lcd.print(key);
            counter++;
         }
            break;
      }    //end case
      decnum = num / pow(10, counter);
      key = kpd.getKey();
   }    //end while not #
    return decnum;
}      // end getdegrees
 
 void printadvance()      // print function
   {
     lcd.setCursor(6,1);lcd.print("Moving");
     lcd.setCursor(4,2);lcd.print("Steps  ");lcd.print(ToMove,0); 
     lcd.setCursor(13,0);lcd.print(bob,2);
     rotation(ToMove,0);
     lcd.setCursor(6,1);lcd.print("      "); 
  } 

 void rotation(float tm, int d)
   { 
     for(int i = 0; i < tm; i++) 
       { 
       digitalWrite(stp, HIGH); 
       delay(stepdelay); 
       digitalWrite(stp, LOW); 
       delay(stepdelay); 
       }
   }

void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
  {
  asm volatile ("  jmp 0");  
  }