Go Down

Topic: NEMA 17 and CNC shield won't rotate without GRBL (Read 779 times) previous topic - next topic

TenBall

Jan 09, 2019, 04:58 pm Last Edit: Jan 09, 2019, 05:04 pm by TenBall
I normally don't do things this way but unfortunately I'm under the gun. I have a project that requires using the NEMA 17 stepper motors to turn an undetermined number of times, pause, then reverse to return to the home position. I would also like to be able to use either a momentary on switch to activate.

I don't need to use GRBL. I just need to do this "simple" movement sequence.

I am totally new to Arduino and on a very steep learning curve. I'm not a very good coder or programmer but trying to pick it up as quickly as possible. Thank you in advance for your help and for your patience.

I think the issue is that the sequence is not correct to drive the stepper motor, but I don't know where to  address it in the code.

I'm using and UNO with CNC Shield mounted on top with A4988 stepper motor drivers. Here is the link to the kit from Amazon https://www.amazon.com/gp/product/B06XHKSVTG/ref=ppx_yo_dt_b_detailpage_o03_s01?ie=UTF8&psc=1

I have also read the pots may need to be adjusted to produce the correct current but havent found code to produce a constant or know what legs to place probes from multimeter on.

Here is the sample code I'm using to try to just get the motors turning.

Code: [Select]
#define EN        8

//Direction pin
#define X_DIR     5
#define Y_DIR     6
#define Z_DIR     7

//Step pin
#define X_STP     2
#define Y_STP     3
#define Z_STP     4

//DRV8825
int delayTime=30; //Delay between each pause (uS)
int stps=200;// Steps to move


void step(boolean dir, byte dirPin, byte stepperPin, int steps)
{
  digitalWrite(dirPin, dir);
  delay(100);
  for (int i = 0; i < steps; i++) {
    digitalWrite(stepperPin,HIGH);
    delayMicroseconds(delayTime);
    digitalWrite(stepperPin,LOW);
    delayMicroseconds(delayTime);
  }
}

void setup(){
  pinMode(X_DIR,OUTPUT); pinMode(X_STP,OUTPUT);
  pinMode(Y_DIR,OUTPUT); pinMode(Y_STP,OUTPUT);
  pinMode(Z_DIR,OUTPUT); pinMode(Z_STP,OUTPUT);
  pinMode(EN,OUTPUT);
  digitalWrite(EN,LOW);
}

void loop(){
  step(false,X_DIR, X_STP, stps); //X, Clockwise
  step(false,Y_DIR, Y_STP, stps); //Y, Clockwise
  step(false,Z_DIR, Z_STP, stps); //Z, Clockwise
  delay(2000);

  step(true,X_DIR, X_STP, stps); //X, Counterclockwise
  step(true,Y_DIR, Y_STP, stps); //Y, Counterclockwise
  step(true,Z_DIR, Z_STP, stps); //X, Counterclockwise

  delay(2000);
}

groundFungus

#1
Jan 09, 2019, 05:33 pm Last Edit: Jan 09, 2019, 05:34 pm by groundFungus
Quote
I have also read the pots may need to be adjusted to produce the correct current but havent found code to produce a constant or know what legs to place probes from multimeter on.
This Pololu page shows how to set the coil current pot (with video).

Robin2

You are trying to make the motor move much too quickly with steps at 60┬Ásec intervals - that means over 16,000 steps per second. That sort of step rate can only be achieved by accelerating the motor.

Also, have a look at this Simple Stepper Code and see how the length of the step pulse and the time interval between steps are treated separately. It makes the control of the step rate much easier.

...R
Stepper Motor Basics

Two or three hours spent thinking and reading documentation solves most programming problems.

MarkT

Have you tried the AccelStepper libary examples?
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up