#include //Required only in Platformio #include bool newData; char pythonData; //Serial data coming from python byte Enable_All_Steppers = 8; //Pin 8 Low = Enable,High = disable String abc; AccelStepper stepperX(1,2,5); //(DirStep type,Step pin, Dir pin) AccelStepper stepperY(1,3,6); //(DirStep type,Step pin, Dir pin) AccelStepper stepperZ(1,4,7); //(DirStep type,Step pin, Dir pin) void setup(){ pinMode(2,OUTPUT); //x step pinMode(5,OUTPUT); //d dir pinMode(3,OUTPUT); //y step pinMode(6,OUTPUT); //y dir pinMode(4,OUTPUT); //z step pinMode(7,OUTPUT); //z dir pinMode(Enable_All_Steppers, OUTPUT); Serial.begin(115200); digitalWrite(Enable_All_Steppers,1); //0=enable all steppers, 1=disable stepperX.setMaxSpeed(700); //Steps/sec stepperX.setAcceleration(1400); //steps/sec^2 (uses lot's of computational power) //x_motor.setSpeed(500); // used with runSpeed() } void loop(){ if (Serial.available() > 0){ pythonData = Serial.read(); //read serial sent from Python newData = true; //Flag there is new data if(pythonData == 'x'){ digitalWrite(Enable_All_Steppers,0); //0=enable all steppers, 1=disable stepperX.move(1000); //Set the target position relative to the current position stepperX.runToPosition(); //Moves the motor (with accel./decel.) to target position and blocks until it is at position. Dont use this in event loops, since it blocks. digitalWrite(Enable_All_Steppers,1); //0=enable all steppers, 1=disable Serial.println("x move done"); } if(pythonData == 'y'){ stepperX.move(1000); //Set the target position relative to the current position stepperX.runToPosition(); //Moves the motor (with accel./decel.) to target position and blocks until it is at position. Dont use this in event loops, since it blocks. Serial.println("y move done"); } if(pythonData == 'e'){ digitalWrite(Enable_All_Steppers,0); //0=enable all steppers, 1=disable Serial.println("All motors enabled"); } if(pythonData == 'd'){ digitalWrite(Enable_All_Steppers,1); //0=enable all steppers, 1=disable Serial.println("All motors disabled"); } } newData = false; //turn off new data flag } //stepperX.move(-1000); //Set the target position relative to the current position //stepperX.runToPosition(); //Moves the motor (with accel./decel.) to target position and blocks until it is at position. Dont use this in event loops, since it blocks. //digitalWrite(Enable_All_Steppers,1); //delay(500); // D9 +/-X-Limit D10 +/-Y-Limit D11 +/-Z-Limit // D8 Enable/Disable all stepper // D12 Spindle enable/A step // D13 Spindle direction/A direction //https://www.airspayce.com/mikem/arduino/AccelStepper/classAccelStepper.html#ace236ede35f87c63d18da25810ec9736 //Brainy-bits: https://www.youtube.com/watch?v=YsLykxnHApg&t=277s