I want to turn a stepper motor 1 step every time a hit the switch.
Has anybody have an idea on how to do this
been at it for a few hours now and i’m unable to combine a switch with a stepper
Based on Stepper Component — ESPHome
on_...:
then:
# Move 1 steps forward
- stepper.report_position:
id: my_stepper
position: 0
- stepper.set_target:
id: my_stepper
target: 1
I have the similar script that you have to run the motor, but I can’t get mine working. I’m not sure if it’s the driver that is not compatible with esphome or I wired it all wrong, but I have a DRV8825 driver which is similar to A4988.
I’m doing a test rig to be able to replace my arduino blinds with esphome.
So far this is my script:
esphome:
name: blinds-bedroom
platform: ESP8266
board: d1_mini
on_boot:
then:
- ds1307.read_time
- display.page.show: intro_page
- delay: 2s
- display.page.show: main_page
#- lambda: id(oled).turn_on();
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
power_save_mode: none
#output_power: 20.0
fast_connect: on
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
# password: "***"
# # Enable fallback hotspot (captive portal) in case wifi connection fails
# ap:
# ssid: "Blinds-Bedroom Fallback Hotspot"
# password: "***"
captive_portal:
#Time
time:
- platform: homeassistant
id: homeassistant_time
on_time_sync:
then:
ds1307.write_time:
- platform: sntp
id: sntp_time
- platform: ds1307
id: ds_time
#Light Sensor
sensor:
- platform: adc
id: ambient_sensor
pin: A0
name: "Ambient Light"
update_interval: '1s'
unit_of_measurement: lux
filters:
- lambda: |-
return (21 - (x * 21));
#Stepper Motor
stepper:
- platform: a4988
id: stepper_motor
dir_pin: D8
step_pin: D7
max_speed: 250 steps/s
acceleration: 200
deceleration: 200
#Optional
sleep_pin: D6
#OLED Display
i2c:
sda: D1
scl: D2
display:
- platform: ssd1306_i2c
id: oled
model: "SSD1306 128x32"
address: 0x3C
pages:
- id: intro_page
lambda: |-
it.print(15, 12, id(calibri1), "Test Blinds.");
- id: main_page
lambda: |-
it.strftime(0, 8, id(calibri1), TextAlign::BASELINE_LEFT, "%a, %B %d, %Y", id(ds_time).now());
it.strftime(0, 18, id(calibri1), TextAlign::BASELINE_LEFT, "%I:%M:%S %p", id(ds_time).now());
it.printf(0, 22, id(calibri1), "%.0f%% Lux", id(ambient_sensor).state);
binary_sensor:
- platform: gpio
pin:
number: D4
mode: INPUT_PULLUP
inverted: True
name: Button Up
id: button_up
on_press:
then:
- stepper.report_position:
id: stepper_motor
position: 0
- stepper.set_target:
id: stepper_motor
target: 150
- platform: gpio
pin:
number: D3
mode: INPUT_PULLUP
inverted: True
name: Button Down
id: button_down
on_press:
then:
- stepper.report_position:
id: stepper_motor
position: 0
- stepper.set_target:
id: stepper_motor
target: -150
font:
- file: "fonts/times.ttf"
id: calibri1
size: 10
- file: "fonts/times.ttf"
id: calibri2
size: 35
- file: "fonts/calibri.ttf"
id: calibri3
size: 30
What is it that I’m missing that I can’t get the motor working? Could it be that the driver is incompatible (which I think is not really the case).
I just need the motor to move forward or backward with a press of a button. Can anyone help? Thanks.