I can only reach 155RPM, inputting 4000 step/rev. if speed variable is increased nothing changes.
speed stays the same.
I was able to reach 1200RPM with another code.
but i need to use the accellstepper() library.
<setmaxspeed()>
I can only reach 155RPM, inputting 4000 step/rev. if speed variable is increased nothing changes.
speed stays the same.
I was able to reach 1200RPM with another code.
but i need to use the accellstepper() library.
<setmaxspeed()>
Do you use microstepping?
There is no hard limit in the library, it will goes as fast as the Arduino can call the run() function. And that's the problem, you don't say what board your using but a typical Uno is said to be able to reach 4k steps per minute using Accelstepper. That's if there is NO other code running.
Stepper motors are just not meant for high speed. 1200RPM is quite fast for a stepper too fast really. I am betting there was not any load on it and it was skipping steps badly. Stepper motors are designed for precision movement not high speed for that there are other types of motors .
I figure that you meant per second.
From the AccelStepper reference,
The fastest motor speed that can be reliably supported is about 4000 steps per second at a clock frequency of 16 MHz on Arduino such as Uno etc.
Here is the code.
Using
arduino UNO.
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <AccelStepper.h>
#include <Keypad.h>
int speed = 6400;
int acceleration = 500;
#define dirPinM1 8
#define stepPinM1 9
#define dirPinM2 4
#define stepPinM2 5
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
// define the symbols on the buttons of the keypad
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {13, 12, 11, 10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A0, A1, A2, A3}; //connect to the column pinouts of the keypad
// initialize an instance of class NewKeypad
Keypad keypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS );
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
AccelStepper stepperM1(1,stepPinM1, dirPinM1);
AccelStepper stepperM2(1,stepPinM2, dirPinM2);
// variables for the stepper motor calculations
double r = 18;
double R = 20;
const int b = 6;
double t = 360 / (4 * b);
const int i = 4 * b;
double a = 45;
double o = 0;
double k = 0;
double deg = 0;
int counter = 0;
double j[2][i + 1];
double p[2][i + 1];
double degg[i + 1];
double x_center = 0;
double y_center = 0;
double theta = (90 * (PI / 180)) + ((90 * (PI / 180)) - (a * (PI / 180)));
String input = "0";
void setup()
{
Serial.begin(9600);
lcd.init();
lcd.backlight();
setupValues();
stepperM1.setMaxSpeed(speed);
stepperM1.setAcceleration(a);
stepperM2.setMaxSpeed(speed);
stepperM2.setAcceleration(a);
}
void loop()
{
while (counter < i + 1)
{
for (int n = 0; n < i + 1; n++)
{
deg = t * n;
o = 800*n*n; //"formula" ;
k = 800*n*n; //"formula";
j[0][n] = o;
j[1][n] = k;
degg[n] = deg;
Serial.print("o=");
Serial.print(j[0][n]);
Serial.print(" k=");
Serial.print(j[1][n]);
Serial.print(" deg=");
Serial.print(degg[n]);
Serial.println("");
counter++;
delay(100);
}
Serial.println("");
x_center = j[0][0];
y_center = j[1][0];
for (int d = 0; d < i + 1; d++)
{
j[0][d] = j[0][d] - x_center;
j[1][d] = j[1][d] - y_center;
Serial.print("x_center = ");
Serial.print(j[0][d]);
Serial.print(" y_center = ");
Serial.print(j[1][d]);
Serial.println("");
delay(100);
}
Serial.println("");
for (int d = 0; d < i + 1; d++)
{
p[0][d] = (j[1][d] * cos(theta)) - (j[0][d] * sin(theta));
p[1][d] = (j[1][d] * cos(theta)) + (j[0][d] * sin(theta));
Serial.print("Rotated X = ");
Serial.print(p[0][d]);
Serial.print(" Rotated Y = ");
Serial.print(p[1][d]);
Serial.println("");
delay(100);
}
}
for (int d = 0; d < i + 1; d++)
{
stepperM1.moveTo(j[0][d]);
stepperM2.moveTo(j[1][d]);
while (stepperM1.currentPosition() != j[0][d] && stepperM2.currentPosition() != j[1][d])
{
stepperM1.run();
stepperM2.run();
}
}
}
// get values for a,R,r,acceleration,speed
void setupValues(){
lcd.clear();
lcd.setCursor(0, 0);
Serial.println("Value for 'a':");
lcd.print("Value for 'a':");
lcd.setCursor(0, 1);
while(keypad.getKey() != '#'){
char key = keypad.getKey();
if(key >= '0' && key <= '9'){
input += key;
Serial.println(key);
lcd.print(key);
}
}
a = input.toInt();
lcd.clear();
lcd.setCursor(0, 0);
Serial.println("Value for 'R':");
lcd.print("Value for 'R':");
lcd.setCursor(0, 1);
input = "0";
while(keypad.getKey() != '#'){
char key = keypad.getKey();
if(key >= '0' && key <= '9'){
input += key;
Serial.println(key);
lcd.print(key);
}
}
R = input.toInt();
lcd.clear();
lcd.setCursor(0, 0);
Serial.println("Value for 'r':");
lcd.print("Value for 'r':");
lcd.setCursor(0, 1);
input = "0";
while(keypad.getKey() != '#'){
char key = keypad.getKey();
if(key >= '0' && key <= '9'){
input += key;
Serial.println(key);
lcd.print(key);
}
}
r = input.toInt();
lcd.clear();
lcd.setCursor(0, 0);
Serial.println("Value for 'acceleration':");
lcd.print("Value for 'acceleration':");
lcd.setCursor(0, 1);
input = "500";
while(keypad.getKey() != '#'){
char key = keypad.getKey();
if(key >= '0' && key <= '9'){
input += key;
Serial.println(key);
lcd.print(key);
}
}
acceleration = input.toInt();
lcd.clear();
lcd.setCursor(0, 0);
Serial.println("Value for 'speed':");
lcd.print("Value for 'speed':");
lcd.setCursor(0, 1);
input = "6400";
while(keypad.getKey() != '#'){
char key = keypad.getKey();
if(key >= '0' && key <= '9'){
input += key;
Serial.println(key);
lcd.print(key);
}
}
speed = input.toInt();
}
yes 1/4
yes no load, and no skipping but easy to stop by hand. Good until 1000RPM
800 step/rev from 200 original
You have a lot of blocking code (for loops with slow prints) between the run functions. That will limit speed. The steppers can only step quickly if run() is called often.
Ideally don't use for loops. Do one step of what is in the for loops each time through the loop(). Let loop() do the loop work and call run every time through loop. The faster the loop runs the faster the steppers can run.
Raising your serial baud rate will help.
Can steps-per-revolution be decreased to increase speed? (a side question to this topic)
Reducing microstepping will increase speed if that is what you mean. But that is usually a hardware setting.
That shouldn't be a problem because all the print are done before the run() is called, is that right?
Once it enter the for loop, it's not printing any serial info.
for (int d = 0; d < i + 1; d++)
{
stepperM1.moveTo(j[0][d]);
stepperM2.moveTo(j[1][d]);
while (stepperM1.currentPosition() != j[0][d] && stepperM2.currentPosition() != j[1][d])
{
stepperM1.run();
stepperM2.run();
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.