Stepper Motor Direction

Hi, my name is Lex. I'm a contractor and i am "trying" to build an automated fence for my saws. I am doing this by using a stepper motor to convert rotational steps to linear movement. Which is what led me to arduino. I have taken a few basic online stepper motor tutorials and I am a bit stumped as of now and thought joining the forum and sharing info would be beneficial for me. So... my setup. I am using a 20 tooth pulley with a 2mm pitch belt so one full rotations will give me 40mm of linear movement. I have a NEMA 23 1.8 degree stepper with the driver set at 1/16 step. So 40mm/3200steps so .0125mm per steps. I am working on the code and need to be able to tell my stepper how far to move in one direction. For example if i want to move the "fence" 350mm. I need my stepper to move 350/0.125mm, so 28000 steps. Could someone help me with the code for this. And is there a way i can save the position so once i move the fence it will calculate from there. If someone could help me get going in the right direction i would much appreciate it. And if you could link any threads that may help, or if there is any readily available software (I am using mac) please share.

#include <Stepper.h>
int stepsPerRevolution=800; // 1 Rev equals 40mm //
int motSpeed=120;
int dt=1000;
Stepper myStepper(stepsPerRevolution, 8,9,10,11);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
myStepper.setSpeed(motSpeed);
myStepper.step(1500*20); // Moving 1.5m right //
delay(dt);

}

void loop() {

}

sketch_apr04a.ino (301 Bytes)

So I've sorta figured out how to move in one directions. i've been getting by with myStepper.Step myStepper.step(4080). That would be 40mm linear movement with 3200 steps per revolution. So 40mm or for 20mm (2080). The problem is if I want to move more than 1.5-2m which would be myStepper.step(2000800). The stepper will spend counterclockwise sometime and move 30 revolutions or so but will not complete. Is this bc there is not enough memory in the setup portion of the code? Would i be better off with Arduino mega rather than uno? Or possibly Raspberry Pi 4? I would potentially need to move 4ms. So the memory would have to support (400080) and convert that to the driver.. Thoughts?

P.S. I am completely new to this. My background is residential construction, I'm a contractor. So if I'm misusing terminology or seem unawares bc I am, i apologize and please take it easy on me. haha thanks.

Post your code (in code tags). It may be that you are using data types that are too small.

Part of your problem may be with the program not knowing the position of the fence when the program starts. If there is any power interruption during movement, the position is lost, so the program needs to determine the zero position of the mechanism when the program starts up.
Paul

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