Hello,
I am just starting a maybe over ambition project using Arduino and steppers motors to create a robot for some cleaning tasks. The setup below is to push objects using a rotating hand on a slide. I named it "god's hand" with all modesty. I am struggling for weeks now trying to get it working as expected. Chat-GPT was pretty useless to be frank. Is there here a kind person to help me, please ?
Here the setup (test bench for now)
Here my project description:
WRITE FULL OPTIMIZED CODE FOR FOLLOWING INSTRUCTIONS.
A CNC Shield is mounted on a Arduino One.
a stepper motor named M1 is connected to the CNC Shield to a DRV8825 driver on module C1 using STEP d2 and DIR 5.
a stepper motor named M2 is connected to the CNC Shield to a DRV8825 driver on module C2 using STEP d3 and DIR 6.
A limit switch name L1 is connected to the CNC Shield on pin 9.
A limit switch name L2 is connected to the CNC Shield on pin 10.
A limit switch name L3 is connected to the CNC Shield on pin 11. L3 is used to count that 1 revolution of M2 is done.
Stepper Power : 24V , 2A
M2 can only turn CLOCKWISE.
ACCELSTEPPER library for all rotations.
Initialization:
If L1 is LOW, run M1 for - 50 steps. Set Home Position
if L2 is LOW, initiate HOMING function
IF L1 and L2 are LOW, initiate HOMING function.
HOMING:
Run M1 and M2.
If L1 is HIGH then STOP M1 and Run M1 for -50 Steps. Set M1 Home Position.
If L3 is HIGH then STOP M2 and set M2 Home Position.
MAIN SEQUENCE:
-
Run M1.
-
When M1 DISTANCE = 800 then run M1 reverse direction to Home Position and run M2 for 100 steps.
-
Run M2 until L3 is LOW
When M1 is at M1 Home Position. Loop to 1.
If L1 or L2 are LOW during MAIN SEQUENCE. STOP M1 and M2.