Go Down

Topic: Controlling NEMA 17 through RAMPS without firmware (Read 4857 times) previous topic - next topic

Saturisk

I don't know whether the title is a little confusing or not, but mainly I am trying to control a Nema 17 Stepper Motor through RAMPS without having to run Marlin, Sailfish, Teacup, or any other of the software normally supporting 3D Printers.

Anyways, I have tried running my stepper motor through the RAMPS and I can't figure it out. I took the pins from a RAMPS data sheet and made a little progress with the pin layout:
Code: [Select]

#define X_STEP_PIN             54
#define X_DIR_PIN               55
#define X_ENABLE_PIN      38
#define X_MIN_PIN             3
#define X_MAX_PIN            2


However, looking at the Stepper motor tutorials on Arduino, and everywhere I can get my hands on I can't really find anything that tries writing to the motor. I tried setting the X_ENABLE_PIN and X_DIR_PIN to outputs and writing them HIGH and then trying to make it step, but that doesn't even make sense to me so I don't know why I tried it.

Any insight to making this work would be really helpful, sorry if this sounded like a jumbled up mess!

seanz2003

#1
Jun 17, 2014, 07:48 am Last Edit: Jun 17, 2014, 07:50 am by seanz2003 Reason: 1
IF you don't know about stepper motors, you need to do some homework first. Check out google and wikipedia. basically you have to apply current through the proper sequence of coils at the right time to get it to spin. The firmware does this for you, other wise it is tricky to do it right manually. Another suggestion would be to carefully look over the datasheet for the stepper driver chip. My ramps V1.4 happened to come with this one: http://www.pololu.com/file/download/a4988_DMOS_microstepping_driver_with_translator.pdf?file_id=0J450
I just gave it a quick skim and i think  that it requires a PWM signal. But I might be wrong, Yours might have a completely different chip too.

Robin2

Once you know which I/O pins represent the step and direction pins for one motor all you need to make that motor run is to set the direction and send  a series of pulses to the step pin.

This simple code should work as long as you correctly set the pin numbers.

Code: [Select]
// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// as posted on Arduino Forum at http://forum.arduino.cc/index.php?topic=208905.0

byte directionPin = 9;
byte stepPin = 8;
int numberOfSteps = 100;
byte ledPin = 13;
int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 25; // milliseconds


void setup()
{

  Serial.begin(9600);
  Serial.println("Starting StepperTest");
  digitalWrite(ledPin, LOW);
 
  delay(2000);

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
 

  digitalWrite(directionPin, HIGH);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros);
    digitalWrite(stepPin, LOW);
   
    delay(millisbetweenSteps);
   
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
 
  delay(3000);
 

  digitalWrite(directionPin, LOW);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros);
    digitalWrite(stepPin, LOW);
   
    delay(millisbetweenSteps);
   
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
 
}

void loop()
{

}


For a practical project you will need to replace the use of delay() with the technique in the Blink Without Delay example sketch.

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

Saturisk

#3
Jun 17, 2014, 05:35 pm Last Edit: Jun 17, 2014, 05:42 pm by Saturisk Reason: 1

Once you know which I/O pins represent the step and direction pins for one motor all you need to make that motor run is to set the direction and send  a series of pulses to the step pin.

This simple code should work as long as you correctly set the pin numbers.

Code: [Select]
// testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// as posted on Arduino Forum at http://forum.arduino.cc/index.php?topic=208905.0

byte directionPin = 9;
byte stepPin = 8;
int numberOfSteps = 100;
byte ledPin = 13;
int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 25; // milliseconds

void setup()
{

 Serial.begin(9600);
 Serial.println("Starting StepperTest");
 
 delay(2000);

 pinMode(enablePin, OUTPUT);
 pinMode(directionPin, OUTPUT);
 pinMode(stepPin, OUTPUT);  
 
 digitalWrite(enablePin, HIGH);
 digitalWrite(directionPin, HIGH);
 for(int n = 0; n < numberOfSteps; n++) {
   digitalWrite(stepPin, HIGH);
   delayMicroseconds(pulseWidthMicros);
   digitalWrite(stepPin, LOW);
   
   delay(millisbetweenSteps);
 }
 
 delay(3000);
 

 digitalWrite(directionPin, LOW);
 for(int n = 0; n < numberOfSteps; n++) {
   digitalWrite(stepPin, HIGH);
   delayMicroseconds(pulseWidthMicros);
   digitalWrite(stepPin, LOW);
   
   delay(millisbetweenSteps);
 
 }
 
 digitalWrite(directionPin, HIGH);
 
}

void loop()
{

}


For a practical project you will need to replace the use of delay() with the technique in the Blink Without Delay example sketch.

...R


That was actually really helpful, thank you. It makes my stepper motor click with power, however it doesn't move. Do you simulate PWM movement? Also, I don't really understand what you mean by the technique from the Blink Without Delay sketch. I mean, I get why you would need the timing to produce the wavelength to run the motor, but I honestly don't know how to configure it myself.

I tried:
Code: [Select]

byte directionPin = 55;
byte stepPin = 54;
byte enablePin = 38;
int numberOfSteps = 150;
int pulseWidthMicros = 50;  // microseconds
int millisbetweenSteps = 30; // milliseconds
long previousMillis = 0;
long interval = 10;

void setup()
{

  Serial.begin(9600);
  Serial.println("Starting StepperTest");
 
  delay(2000);

  pinMode(enablePin, OUTPUT);
  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT); 
 
  digitalWrite(enablePin, HIGH);
  digitalWrite(directionPin, HIGH);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros);
    digitalWrite(stepPin, LOW);
   
    delay(millisbetweenSteps);
  }
 
  delay(3000);
 

  digitalWrite(directionPin, LOW);
  for(int n = 0; n < numberOfSteps; n++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros);
    digitalWrite(stepPin, LOW);
   
    delay(millisbetweenSteps);
 
  }
 
  digitalWrite(directionPin, HIGH);
 
}
void loop()
{
 
 unsigned long currentMillis = millis() * 10000; //1 ms is 1000us
 
   if(currentMillis - previousMillis > interval) { // interval is set to 10
   
   previousMillis = currentMillis;  

   digitalWrite(enablePin, HIGH);
   digitalWrite(directionPin, HIGH);
   for(int n = 0; n < numberOfSteps; n++) {
     digitalWrite(stepPin, HIGH);
     delayMicroseconds(pulseWidthMicros);
     digitalWrite(stepPin, LOW);
     
     delay(millisbetweenSteps);
   }
   
   delay(3000);
   
 
   digitalWrite(directionPin, LOW);
   for(int n = 0; n < numberOfSteps; n++) {
     digitalWrite(stepPin, HIGH);
     delayMicroseconds(pulseWidthMicros);
     digitalWrite(stepPin, LOW);
     
     delay(millisbetweenSteps);
   
   }
   
   digitalWrite(directionPin, HIGH);

 }
 
}


I guess what I was trying to do was have the currentMillis be the microseconds. I feel as though this is terribly wrong and would like a little insight. Thank you.

Robin2

You don't need PWM to drive a stepper motor - that is done behind the scenes by the stepper motor driver board.

All you need is a sequence of short pulses (around 10 microsecs is probably enough) spaced at timed intervals to control the speed at which the steps happen.

If the motor isn't moving I wonder what sort of power supply you have? You probably need something with at least 12v and 4 amps, preferably 20 volts or more - I don't know what is the upper limit for your stepper drivers.

Also, you haven't said what motors you have - can you provide a link to the motor specification?

Another thing to be aware of is that the stepper drivers have a small potentiometer that can be adjusted to limit the maximum current to protect the motor. If it is set very low there would not be enough current even if the power supply is sufficient.

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

Saturisk


IF you don't know about stepper motors, you need to do some homework first. Check out google and wikipedia. basically you have to apply current through the proper sequence of coils at the right time to get it to spin. The firmware does this for you, other wise it is tricky to do it right manually. Another suggestion would be to carefully look over the datasheet for the stepper driver chip. My ramps V1.4 happened to come with this one: http://www.pololu.com/file/download/a4988_DMOS_microstepping_driver_with_translator.pdf?file_id=0J450
I just gave it a quick skim and i think  that it requires a PWM signal. But I might be wrong, Yours might have a completely different chip too.


I am actually using the Pololu A4988 Stepper motor driver. The most confusing part for me is the PWM because I don't understand how to make it turn even just one step. It just kind of seizes when I run my program.

polymorph

Are you sure you have the stepper connected correctly to the A4988?

It should be as simple as putting a Zero on the Enable line (it is active low) and pulsing the Step line.

Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

Saturisk

#7
Jun 17, 2014, 09:21 pm Last Edit: Jun 17, 2014, 09:24 pm by Saturisk Reason: 1

Are you sure you have the stepper connected correctly to the A4988?

It should be as simple as putting a Zero on the Enable line (it is active low) and pulsing the Step line.




Yeah, I fixed my code and pushed a zero. My motor just vibrates pretty much like the two coils are fighting against eachother.

EDIT: In fact, that was the problem. I changed two wires around and it works in a perfect circle. Now I have to perfect my PWM output.

Robin2


I am actually using the Pololu A4988 Stepper motor driver.


I have the same drivers and the code I posted earlier has been tested with them.

You didn't answer my Reply #4 - especially about your power supply and your motors.

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

Saturisk



I am actually using the Pololu A4988 Stepper motor driver.


I have the same drivers and the code I posted earlier has been tested with them.

You didn't answer my Reply #4 - especially about your power supply and your motors.

...R


Oh, I am sorry. I am using a http://www.zentoolworks.com/files/SST43D2120.pdf SST43D2121 Stepper Motor I found in the shop I work at, and I am using a cpu power supply of which I am only using the 12V section.

Is there a decent tutorial of PWM outputs that I am missing?

Robin2

#10
Jun 17, 2014, 10:54 pm Last Edit: Jun 17, 2014, 11:01 pm by Robin2 Reason: 1

Is there a decent tutorial of PWM outputs that I am missing?


I dealt with that in Reply #4 also.

All you are missing is the knowledge that you don't need to bother about PWM.

That motor should be fine with the Pololu A4988 driver.
Have you checked the max current setting on the drivers?
I presume you mean a power supply from a PC. As far as I know they produce a lot of amps at 5v but do you know how many it produces at 12v. And, yes, you should drive the motors with 12v.

Are there pins attached to the A4988 boards? If so you could connect one to a breadboard and to the Arduino without using the RAMPS board - just for testing.

Also, it is very easy to destroy an A4988 if you disconnect the motor wires while it is powered up.

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

Saturisk



Is there a decent tutorial of PWM outputs that I am missing?


I dealt with that in Reply #4 also.

All you are missing is the knowledge that you don't need to bother about PWM.

...R


Oh my gosh! I completely didn't see that post apparently. I'm terrible sorry. Thank you for explaining that to me.

Quote

All you need is a sequence of short pulses (around 10 microsecs is probably enough) spaced at timed intervals to control the speed at which the steps happen.


So I can understand the pulses portion of it, however, how do I figure how long or fast the motor will run from that?

polymorph

If your motor is 200 steps per turn, there is your answer.
Steve Greenfield AE7HD
Drawing Schematics: tinyurl.com/23mo9pf - tinyurl.com/o97ysyx - https://tinyurl.com/Technote8
Multitasking: forum.arduino.cc/index.php?topic=223286.0
gammon.com.au/blink - gammon.com.au/serial - gammon.com.au/interrupts

Robin2


how do I figure how long or fast the motor will run from that?


If you get my simple demo code (in Reply #2) to work you can change the value of millisbetweenSteps to see what happens.

As @polymorph says it is a simple matter of how often each step occurs and the number of steps needed for 1 revolution.

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

MarkT

BTW look at the AccelStepper library if you can, it does automatic ramping up and
down of step rate.

Do you know the current rating of your motor?  You should set the current trimmer
pot on the A4988 board for the right current level.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up