From: David Woodhouse Date: Thu, 27 Feb 2025 14:32:31 +0000 (+0000) Subject: more cleanups and parameterisation for blinds X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=8a7a560b8a607bbae7662d10a74212d5ac526ee0;p=users%2Fdwmw2%2Fesp32-pool.git more cleanups and parameterisation for blinds --- diff --git a/blind.yaml b/blind.yaml index 34f2fe5..c9ae422 100644 --- a/blind.yaml +++ b/blind.yaml @@ -1,11 +1,39 @@ # Based on https://github.com/joshr120/PD-Stepper/blob/main/Software/ESPHome/PD-Stepper-Blinds-Advanced.yaml # (GPLv3) +# Tuning... +# +# Total motor speed (steps/s / microsteps) should be fast enough to be useful, +# but slow enough not to be too noisy. Too fast may also make the cord skip on +# the gear when it should be stalling. +# +# If steps/s is too high (regardless of microsteps), the Power Good light randomly +# cuts out and the board resets (with three different power supplies). Decreasing +# run_current doesn't seem to make any difference to that. +# +# StallGuard should be sensitive (high) enough to stop quickly when it reaches +# the end stop (although that's less important with the reed switch hooked up), +# but low enough not to trigger if starting up in the high-torque region when +# the blind is almost, but not quite fully up. +# +# Making the re-homing run at half speed helps with the latter, as does lower +# acceleration. +# +# Increasing microsteps decreases torque, as does decreasing the current. This +# affects the StallGuard settings. +# +# Microsteps (between 1 and 4 at least) don't seem to make any noticeable difference +# to the smoothness of operation. +# +# Setting standstill_mode to coil_short_ls prevents high back EMF if someone +# manually turns the blinds. esp32: board: esp32-s3-devkitc-1 framework: type: esp-idf + version: latest +# platform_version: 6.10.0 esphome: name: ${name} @@ -49,7 +77,6 @@ esphome: id(CFG2_pin).set_state(cfg2); id(CFG3_pin).set_state(cfg3); - - delay: 0.5s - lambda: id(sensored_home_pos) = id(encoder)->get_state(); # Set the home position to power on position # - button.press: home @@ -57,9 +84,11 @@ esphome: packages: base: !include base.yaml +# Log too much, and the encoder can miss revolutions. logger: level: INFO +# Close the blind at sunset. Open it at 07:30 or sunrise, whichever is later. time: - platform: sntp on_time: @@ -94,10 +123,12 @@ external_components: mqtt: on_connect: then: - - light.turn_on: led2 + - light.turn_on: blue_led on_disconnect: then: - - light.turn_off: led2 + - light.turn_off: blue_led + idf_send_async: true +# log_topic: null i2c: sda: 8 @@ -112,11 +143,11 @@ uart: output: - platform: ledc pin: 12 - id: led1_output + id: red_led_output - platform: ledc pin: 10 - id: led2_output + id: blue_led_output - platform: gpio pin: GPIO38 @@ -130,12 +161,14 @@ output: light: - platform: monochromatic - output: led1_output - id: led1 + internal: true + output: red_led_output + id: red_led name: LED 1 - platform: status_led - output: led2_output - id: led2 + internal: true + output: blue_led_output + id: blue_led name: Status LED globals: @@ -187,11 +220,11 @@ stepper: } - stepper.stop: motor - light.turn_on: - id: led1 + id: red_led transition_length: 0s - delay: 250ms - light.turn_off: - id: led1 + id: red_led transition_length: 1s button: @@ -227,6 +260,7 @@ binary_sensor: - platform: gpio name: Button 1 + internal: true pin: number: 35 mode: INPUT @@ -266,6 +300,7 @@ binary_sensor: - platform: gpio name: Button 3 + internal: true id: btn3 pin: number: 37 @@ -366,6 +401,7 @@ sensor: state_class: measurement - platform: adc + internal: true pin: 4 name: VBUS Voltage update_interval: 10s @@ -374,6 +410,7 @@ sensor: - multiply: 8.47742 - platform: tmc2209 + internal: true type: motor_load name: Motor load update_interval: 250ms @@ -381,6 +418,7 @@ sensor: delta: 1 - platform: tmc2209 + internal: true type: stallguard_result name: StallGuard result update_interval: 250ms @@ -388,6 +426,7 @@ sensor: delta: 1 - platform: tmc2209 + internal: true type: actual_current name: Actual current update_interval: 250ms @@ -413,7 +452,7 @@ cover: - lambda: |- int32_t wantpos = id(sensored_home_pos); int32_t posdelta = wantpos - id(encoder)->get_state(); - int32_t stepdelta = ((posdelta * 200 * ${microsteps}) + 2048) / 4096; + int32_t stepdelta = ((posdelta * 200 * ${microsteps} * ${encoder_direction}) + 2048) / 4096; ESP_LOGI("cover", "From %f to open (%f to %d) is delta %d, %d steps. Step %d -> %d", id(pd_blinds)->position, id(encoder)->get_state(), wantpos, posdelta, stepdelta, id(motor)->current_position, id(motor)->current_position + stepdelta); @@ -423,7 +462,7 @@ cover: - lambda: |- int32_t wantpos = id(sensored_home_pos) + ${encoder_closed_pos}; int32_t posdelta = wantpos - id(encoder)->get_state(); - int32_t stepdelta = ((posdelta * 200 * ${microsteps}) + 2048) / 4096; + int32_t stepdelta = ((posdelta * 200 * ${microsteps} * ${encoder_direction}) + 2048) / 4096; ESP_LOGI("cover", "From %f to closed (%f to %d) is delta %d, %d steps. Step %d -> %d", id(pd_blinds)->position, id(encoder)->get_state(), wantpos, posdelta, stepdelta, id(motor)->current_position, id(motor)->current_position + stepdelta); @@ -433,7 +472,7 @@ cover: - lambda: |- int32_t wantpos = id(sensored_home_pos) + (1.0 - pos) * ${encoder_closed_pos}; int32_t posdelta = wantpos - id(encoder)->get_state(); - int32_t stepdelta = ((posdelta * 200 * ${microsteps}) + 2048) / 4096; + int32_t stepdelta = ((posdelta * 200 * ${microsteps} * ${encoder_direction}) + 2048) / 4096; ESP_LOGI("cover", "From %f to %f (%f to %d) is delta %d, %d steps. Step %d -> %d", id(pd_blinds)->position, pos, id(encoder)->get_state(), wantpos, posdelta, stepdelta, id(motor)->current_position, id(motor)->current_position + stepdelta); diff --git a/landing-blind-3.yaml b/landing-blind-3.yaml index b70ea14..3ad0cab 100644 --- a/landing-blind-3.yaml +++ b/landing-blind-3.yaml @@ -2,10 +2,12 @@ substitutions: name: "landing-blind-3" encoder_closed_pos: "230000" # full blinds length (in encoder counts) !! CHANGE TO SUIT YOUR SETUP !! + encoder_direction: "1" microsteps: "2" run_current: "100m" max_speed: "800" stallguard_threshold: "60" + pd_voltage: "15" packages: blind: !include blind.yaml