Code to control linear motion using NEMA 17 and belt pulley

I am using NEMA 17 stepper motor and TMC2208 driver. Previously I was dealing with rotational motion using this code, which was doing fine. I can change the speed however I want. The code (for 0.4 rpm) :

#include <MobaTools.h>

const byte stepPin = 2;
const byte dirPin = 5;
const byte enablePin = 8;

const unsigned int motorStepsPerRev = 200;
const unsigned int microstepMultiplier = 16;
const unsigned int STEPS_REVOLUTION = motorStepsPerRev * microstepMultiplier;

const unsigned int STEPS_0_4steps_PER_Second = motorStepsPerRev * microstepMultiplier * 4; // (0.4 rev/second = 4 rev/ ten_seconds)

MoToStepper stepper( STEPS_REVOLUTION, STEPDIR );

void setup()
{
   Serial.begin(115200);

   stepper.attach( stepPin, dirPin );
   stepper.attachEnable(enablePin, 5, 0);
   //stepper.setSpeed(4);  // = 0.4 RPM  speed in rpm /10
   //stepper.setSpeedSteps(12800);  // the number is steps per TEN seconds (not steps per 1 second)
   stepper..setSpeedSteps(STEPS_0_4steps_PER_Second);
   stepper.setRampLen(32);
   stepper.setZero();   
}

void loop()
{
   stepper.rotate(1);  // turn CW 4e4
}

But now I need a linear motion, which I am doing using belt-pulley. (I am using GT2 gear which has 20 teeth and 2 mm pitch.) I need 300-500 mm/min linear motion. I have developed some equation to use the code above, but I am not sure that will do it.
Have anyone worked on rotational to linear motion using belt-pulley?
Can you help me with a code by which I can get the desired speed I want?

Thanks in advance.

Since the belt is in contact with the edge of the pulley, the linear velocity of the belt equal to the linear velocity of the pulley rim.

v = radius*2*PI*(rotations/second)

Look up "rolling motion" for the details.

Sure. Many devices use a fastener on the belt to transmit linear motion.

This means 40mm/rev or 40mm/3200steps in your case (1/16 microstepping). So 400mm/min is 32000 steps/min or about 533steps/sec.

1 Like

Yes! Matched with my calculation!
Thank you for the confirmation.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.