Hello,
I'm creating a kind of winch of a stepper motor. The mass trowed is negligible but has to move very slowly, we'll take the example of 1meter in 1 hours, so I need to control exactly the RPM (rotation per minutes of my motor) the speed but I meet lots of problems. I'll show you here what I have already try done and what are my results.
MY SUPPLIES:
Stepper motor nema 24
Driver M542T
Arduino UNO
You can find my datasheets in this pages for the motor and my driver : http://www.ebay.co.uk/itm/1-Axis-CNC-Kit-3-1Nm-Nema-24-Stepper-Motor-Driver-CNC-Mill-Router-Lathe-Robot-/121684677477?hash=item1c54f8d365
Assembly:
Motor -> Driver: Red A+, Bleu A-, Green B+, Black B-
Driver ->Arduino: PUL+ pin2, PUL- GND, DIR+ pin3, DIR- GND
Calculations :
Later, I would like to add 3 switch buttons on a breadboard (SW1: foreward with Speed1, SW2 : STOP, SW3 : backward with Speed2) in my assembly. And later again, I would like add a clock in my code (in our exemple, 1 hours after SW1, then activate SW2 to stop the motor automatically).
BUT first, I need to be able to control the speed of my mass. Let's keep the example of 1meter in 1 hour.
I used v=d/t, w=v/r, N=(w60)/2Pi = 0.3536 RMPs with r=7.5mm=0.0075m
My motor has got 200 steps but witch the driver revolution, I can increase this numbers of steps with microsteps. Let's called R the number of resolution. I would like to use the maximum so R=51200 microstpes per revolution mPR.
So, 0.35366051200= 1 086 498,8 microsteps to trow on 1 meter in 1 hour
Code:
I'm new on Arduino but I tried 2 ways to control my speed: Stepper.h and delay. In the two cases, it's a fail.
include <Stepper.h>
R=51200
#include <Stepper.h>
#define NumberOfSteps 51200 // Number of microsteps available for 1 revolution
Stepper MyMotor(NumberOfSteps,2,3); // Creation of the object, Stepper Motor
int TotalSteps=1086498; // Our motors realised 1 086 498 microsteps to pull the mass on 1 meter, it's a constant
void setup()
{
** // Set the motor speed in revolution per minute (rotations per minues RPM)**
** MyMotor.setSpeed(0.353678); //set the speed of the motor to 0,353678 RPMs**
}
void loop()
{
** // Set the number of microssteps realised by the motor.**
** // A positiv number turns the motor forwards, a negatif number turns the motor backwards**
** MyMotor.step(TotalSteps);**
** TotalSteps = 0;**
}
This code (or the figures) doesn't work or I'm not able to see my motor move.
Let's see an other example with R=400
#include <Stepper.h>
#define NumberOfSteps 400
Stepper MyMotor(NumberOfSteps,2,3);
int TotalSteps=400;
void setup()
{
** MyMotor.setSpeed(10);**
}
void loop()
{
** MyMotor.step(TotalSteps);**
** TotalSteps = 0;**
}
My NumberOfStepes is 400, so I would expect 1 total revolution but it's not the case. In fact I have only, what it look like exactly or almost: 1/4 of revolution. For the speed, lots of values work: MyMotor.setSpeed(X); for 500<X<1. And with int TotalSteps=4004; I have well, what it looks like 1 total revolution (or almost).
But with R=400, I have lots of vibrations. When I increase R with int TotalSteps=R4, for R from 400 to 20000 I have always what it looks like a revolution but after it become less than a revolution. (It becomes worst when I increase R).
There is an other thing really weird For R = 5000 on my driver, #define NumberOfSteps 500, int TotalSteps=50004; my motor makes 1 revolution clickwise. But if I put int TotalSteps=100004; my motor makes 1 revolution anticlockwise !!! (And I don't put -TotalSteps) :o
Delay
I meet lots of problems too, as if the control of the speed wasn't linear.
int PUL=2; // Match PIN 2 and Pulses PUL
int DIR=3; // Match PIN 3 and Direction DIR
void setup()
{
** //Setup Stepper Motor**
pinMode(PUL,OUTPUT); // pulses
pinMode(DIR, OUTPUT); // direction
digitalWrite(PUL, LOW); // set the default of PULS
digitalWrite(DIR, LOW); // set the default of DIR : clockwise
}
void loop()
{//
digitalWrite(PUL, HIGH);
delay(212); // PUL HIGH, 212 milliseconds
digitalWrite(PUL, LOW);
delay(212); // PUL LOW
}
If we calculate the delay ""n, I found that we could write the delay (in ms) like this :n=(1000Pirt)/(Rd)
For R=51200 on my driver, I calculated a delay n=212.
1 meter in 1 hours it's 16,67 mm/min. Finally, I obtain this speed (the speed of my mass) with n=212*2. I don't know with, probably in mistake of mine (there are 2 delay but there are already counted in my formula.
If I calculte n for R!=400, it becomes worst and worst and sometimes not linear (I change the delay but nothing linear happens or the speed increases suddenly) . Even if I multiply n per 2. So even with the experience I'm not able to predict the delay and then the speed.
If you can help me it would be great. Please be clear if you want to talk me about Delay or Stepper.h or an other solution possible.