Hi everyone,
I am designing dosing control system with 5 Stepper motors. So, Hardwares that I used are Pololu 2267 (200Steps/rev, 2.8V 1.7A Phase) Stepper Motor , Pololu A4988 Stepper driver and Ramps 1.6 and 12V 40A PSU.
I connected one stepper motor to the Ramps and it works successfully when I tried with different script rather than using of Accelstepper library.
First, I am sharing the first code that works for me ;
byte directionPin = 55;
byte stepPin = 54;
int numberOfSteps = 2000;
byte ledPin = 38;
int pulseWidthMicros = 500; // microseconds
void setup()
{
Serial.begin(9600);
delay(2000);
pinMode(directionPin, OUTPUT);
pinMode(stepPin, OUTPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
digitalWrite(directionPin, HIGH);
for(int n = 0; n < numberOfSteps; n++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(pulseWidthMicros);
digitalWrite(stepPin, LOW);
delayMicroseconds(pulseWidthMicros);
digitalWrite(ledPin, !digitalRead(ledPin));
}
delay(1000);
digitalWrite(directionPin, LOW);
for(int n = 0; n < numberOfSteps; n++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(pulseWidthMicros);
digitalWrite(stepPin, LOW);
delayMicroseconds(pulseWidthMicros);
digitalWrite(ledPin, !digitalRead(ledPin));
}
}
void loop()
{
}
After this step, I tried different codes with using Accelstepper library, even so using of setMinPulseWidth, motor do not move.
Codes with Accelstepper library are ;
#include <AccelStepper.h>
AccelStepper stepperA(1,54, 55);
int steps = 10000;
int X = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Test");
if (X < 2)
{
stepperA.move(steps);
stepperA.setSpeed(10000);
stepperA.runSpeedToPosition();
delay(2000);
X = X + 1;
}
}
void loop() {
// put your main code here, to run repeatedly:
}
#include <Arduino.h>
#include <AccelStepper.h>
long receivedStep = 0;
long receivedSpeed = 0;
long receivedAcceleration = 0;
char receivedCommand;
/* r = Start command(Observe which side to turn)
* x = Clockwise
* y= Counterclockwise
* a= Set Acceleration
* s= Stop the motor
*/
bool newVal, runallowed = false; // runallowed flag for new value
AccelStepper stepperA(1,54, 55);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("Test");
stepperA.setMaxSpeed(500);
stepperA.setAcceleration(200);
stepperA.disableOutputs();
}
void continousRun2() {
if (runallowed == true) {
if (abs(stepperA.currentPosition()) < receivedStep)
{
stepperA.enableOutputs();
stepperA.run();
}
else
{
runallowed = false ;
stepperA.disableOutputs();
Serial.print("Position: ");
Serial.println(stepperA.currentPosition());
stepperA.setCurrentPosition(0);
Serial.print("Position: ");
Serial.println(stepperA.currentPosition());
}
}
else
{
return ;
}
}
void checkSerial() {
if (Serial.available() > 0) {
receivedCommand = Serial.read();
newVal = true;
}
if (newVal == true) {
if(receivedCommand == 'r') {
runallowed = true ;
receivedStep = Serial.parseFloat();
receivedSpeed = Serial.parseFloat();
Serial.print(receivedStep);
Serial.println("Steps");
Serial.print(receivedSpeed);
Serial.println("steps/second");
stepperA.setMaxSpeed(receivedSpeed);
stepperA.move(receivedStep);
}
if (receivedCommand == 'x') {
runallowed = true;
receivedStep = Serial.parseFloat();
receivedSpeed = Serial.parseFloat();
Serial.print(receivedStep);
Serial.println("Steps in CounterClockwise");
Serial.print(receivedSpeed);
Serial.println("steps/second");
stepperA.setMaxSpeed(receivedSpeed);
stepperA.move(receivedStep);
}
if (receivedCommand == 'y') {
runallowed = true;
receivedStep = Serial.parseFloat();
receivedSpeed = Serial.parseFloat();
Serial.print(receivedStep);
Serial.println("Steps in Clockwise");
Serial.print(receivedSpeed);
Serial.println("steps/second");
stepperA.setMaxSpeed(receivedSpeed);
stepperA.move(-1*receivedStep);
}
if (receivedCommand == 's') {
runallowed = false;
stepperA.setCurrentPosition(0);
Serial.println("Emergency Stop");
stepperA.stop();
stepperA.disableOutputs();
}
if (receivedCommand == 'a') {
runallowed = false;
receivedAcceleration = Serial.parseFloat();
stepperA.setAcceleration(receivedAcceleration);
Serial.println("Acceleration updated");
}
}
newVal = false;
}
void loop() {
// put your main code here, to run repeatedly:
checkSerial() ;
continousRun2();
}
Can anyone help me to handle this issue?