I am trying to get a stepper motor to make multiple moves with only one action. I want to be able to push a button and have the stepper move X numbers of steps… say 10,000 steps and once it has completed the first move then move the opposite way say 100 steps. problem is I know very little about yaml or lambda and I don’t even know where to start. I have 2 steppers that I want to move simultaneously but each can be homed independently. There are two homing switches to indicate when each stepper has reached home and it will be controlled with 3 buttons, one to home, 1 to raise and 1 to lower. I know that if I set the stepper to move one direction and then the opposite direction in the same button press the last move automatically overrides the first one so it will only make one of the moves. Any help would be greatly appreciated.
esp32:
board: esp32dev
framework:
type: arduino
stepper:
- platform: a4988
id: chopsaw_stepper_a
step_pin: GPIO26
dir_pin: GPIO18
max_speed: 2000 steps/s
# Optional:
sleep_pin: GPIO25
acceleration: inf
deceleration: inf
- platform: a4988
id: chopsaw_stepper_b
step_pin: GPIO19
dir_pin: GPIO23
max_speed: 250 steps/s
# Optional:
acceleration: inf
deceleration: inf
binary_sensor:
- platform: gpio
pin:
number: GPIO22
mode:
input: true
pullup: true
name: "Chopsaw Raise"
id: chopsaw_raise
on_press: #on
then:
- stepper.set_target:
id: chopsaw_stepper_a
target: 10000
- platform: gpio
pin:
number: GPIO21
mode:
input: true
pullup: true
name: "Chopsaw Lower"
id: chopsaw_lower
on_press: #on
then:
- stepper.set_target:
id: chopsaw_stepper_a
target: 0
- platform: gpio
pin:
number: GPIO16
mode:
input: true
pullup: true
name: "Chopsaw Homed A"
id: chopsaw_homed_a
on_press: #on
then:
- stepper.report_position:
id: chopsaw_stepper_a
position: 0
- stepper.set_target:
id: chopsaw_stepper_a
target: 0
- platform: gpio
pin:
number: GPIO27
mode:
input: true
pullup: true
name: "Chopsaw Homed B"
id: chopsaw_homed_b
on_press: #on
then:
- stepper.report_position:
id: chopsaw_stepper_b
position: 0
- stepper.set_target:
id: chopsaw_stepper_b
target: 0
- platform: gpio
pin:
number: GPIO17
mode:
input: true
pullup: true
name: "Chopsaw Home"
id: chopsaw_home
on_press: #on
then:
- stepper.report_position:
id: chopsaw_stepper_a
position: 0
- stepper.set_target:
id: chopsaw_stepper_a
target: !lambda |-
if (id(chopsaw_homed_a).state) {
return -1000;
} else {
return 0;
}