Hi,
Ik ben actief op het engelse gedeelte van de forum. Maar nu dacht ik doe het even in het Nederland.
Misschien makkelijker uitleggen.
Ik ben bezig met het bouwen van een CNC machine (geen 3D printer).
Nu heb ik de onderstaande code die opzich werkt. Echter als ik de startknop indruk dan gaat de stepperL in hele kleine stapjes. En luistert deze niet naar de commandos SetMaxSpeed en Set Acceleration.
Hoe zou dit komen? Ik heb veel online gezocht maar kon het niet vinden.
alvast bedankt
//DRV8825 VREF voltage NEMA 17= 0,65V can be 0.8V
//DRV8825 VREF voltage NEMA 23= 0,6AV can be 0.6V
#include <AccelStepper.h>
#include <Stepper.h>
//NEMA 17 (Actuator)
const int stepsPerRevolutionA = 200;
AccelStepper stepperA(AccelStepper::DRIVER, 3,4); // (DRIVER, Step, Directon)
Stepper myStepperA(stepsPerRevolutionA, 4, 3); // (Direction, Step)
byte directionPinA = 4; // Direction
byte stepPinA = 3; // Step
int enable = 2;
//NEMA 23 (Linear motion)
const int stepsPerRevolutionL = 200;
AccelStepper stepperL(AccelStepper::DRIVER, 7,8); // (DRIVER, Step, Directon)
Stepper myStepperL(stepsPerRevolutionL, 8, 7); // (Direction, Step)
byte directionPinL = 8; // Direction
byte stepPinL = 7; // Step
#define STEP_PIN 7
#define DIR_PIN 8
bool dirHigh;
//int stepCount = 0; // number of steps the motor has taken
// MILLIS in case needed
//unsigned long startMillis; //some global variables available anywhere in the program
//unsigned long currentMillis;
//const unsigned long period = 0; //the value is a number of milliseconds
//ACTUATOR
//Actuator startloop switch
const int crashPin1 = 6;
int crashPin1State;
//Actuator Home position and check position for future Stapper 2
int homePin2State = analogRead(A0);
//STARTBUTTON
const int startButton = 9;
int startButtonState = 1; //1 = open->not pressed
//STRATBUTTON TOGGLE
//int state = HIGH; // the current state of the output pin
int startButtonReading; // the current reading from the input pin
int previouStartButtonReading = 0; // the previous reading from the input pin
unsigned long time = 0; // the last time the output pin was toggled
unsigned long debounce = 100UL; // the debounce time, increase if the output flickers
void setup()
{
//stepperA.setMaxSpeed(4000.0); // speeds possible up to 5000
//stepperL.setMaxSpeed(400.0);
// stepper.setAcceleration(100000.0);
pinMode(directionPinA, OUTPUT);
pinMode(stepPinA, OUTPUT);
pinMode(crashPin1, INPUT);
pinMode(startButton, INPUT_PULLUP);
pinMode(enable, OUTPUT);
digitalWrite(enable,LOW);
Serial.begin(9600);
int homePin2State = analogRead(A0);
while(homePin2State < 50 )
{
homePin2State = analogRead(A0);
myStepperA.setSpeed(1000);
myStepperA.step(stepsPerRevolutionA);
Serial.print("Home switch state = ");
Serial.print(homePin2State);
Serial.println(" - in the WHILE loop");
if( homePin2State == 500)
{
stepperA.setCurrentPosition(0);
break;
}
}
stepperL.setMaxSpeed(4000);
stepperL.setAcceleration(4000);
//stepperL.moveTo(500);
}
void loop()
{
startButtonReading = digitalRead(startButton);
if (startButtonReading == 1 && previouStartButtonReading == 0 && millis() - time > debounce)
{
if (startButtonState == 1)
startButtonState = 0;
else
startButtonState = 1;
time = millis();
}
Serial.println(startButtonState);
crashPin1State = digitalRead(crashPin1);homePin2State = analogRead(A0);
if(startButtonState == 0 && homePin2State > 500 && crashPin1State == 1)
{
if (stepperL.distanceToGo() == 0)
stepperL.setMaxSpeed(40000);
stepperL.setAcceleration(4000);
stepperL.moveTo(1000);
//stepperL.setSpeed(30000);
Serial.print(stepperL.distanceToGo());
Serial.print("MOTOR L Moving");
Serial.print(stepperL.maxSpeed());
stepperL.run();
}
else{
//stepperA.setCurrentPosition(0);
Serial.print(" Start button state = ");
Serial.print(startButtonState);
Serial.print(" | Home switch state = ");
Serial.print(homePin2State);
Serial.println(" - VOID loop");
if (crashPin1State == 0)
{
digitalWrite(enable,LOW);
stepperA.setAcceleration(20000.0);
stepperA.runToNewPosition(3000);
delay(3000);
stepperA.setAcceleration(100000.0);
stepperA.moveTo(1000);
stepperA.runToPosition();
stepperA.runToNewPosition(0);
}
else
{
(digitalWrite(enable,HIGH));
}
}
previouStartButtonReading = startButtonReading;
}