|
| 1 | +Stepper Component |
| 2 | +================= |
| 3 | + |
| 4 | +The ``stepper`` component allows you to use stepper motors with esphomelib. |
| 5 | +Currently only the A4988 stepper driver |
| 6 | +(`datasheet <https://www.pololu.com/file/0J450/a4988_DMOS_microstepping_driver_with_translator.pdf>`__) |
| 7 | +is supported. |
| 8 | + |
| 9 | +.. code:: yaml |
| 10 | +
|
| 11 | + # Example configuration entry |
| 12 | + stepper: |
| 13 | + - platform: a4988 |
| 14 | + id: my_stepper |
| 15 | + step_pin: D0 |
| 16 | + dir_pin: D1 |
| 17 | + max_speed: 250 steps/s |
| 18 | +
|
| 19 | + # Optional: |
| 20 | + sleep_pin: D2 |
| 21 | + acceleration: inf |
| 22 | + deceleration: inf |
| 23 | +
|
| 24 | +
|
| 25 | +Configuration variables: |
| 26 | +------------------------ |
| 27 | + |
| 28 | +- **id** (**Required**, :ref:`config-id`): Specify the ID of the stepper so that you can control it. |
| 29 | +- **step_pin** (**Required**, :ref:`Pin Schema <config-pin_schema>`): The ``STEP`` pin of the A4988 |
| 30 | + stepper driver. |
| 31 | +- **dir_pin** (**Required**, :ref:`Pin Schema <config-pin_schema>`): The ``DIRECTION`` pin of the A4988 |
| 32 | + stepper driver. |
| 33 | +- **max_speed** (**Required**, float): The maximum speed in ``steps/s`` (steps per seconds) to drive the |
| 34 | + stepper at. Note most steppers can't step properly with speeds higher than 250 steps/s. |
| 35 | +- **sleep_pin** (*Optional*, :ref:`Pin Schema <config-pin_schema>`): Optionally also use the ``SLEEP`` pin |
| 36 | + of the A4988 stepper driver. If specified, the driver will be put into sleep mode as soon as the stepper |
| 37 | + reaches the target steps. |
| 38 | +- **acceleration** (*Optional*, float): The acceleration in ``steps/s^2`` (steps per seconds squared) |
| 39 | + to use when starting to move. The default is ``inf`` which means infinite acceleration, so the |
| 40 | + stepper will try to drive with the full speed immediately. |
| 41 | +- **deceleration** (*Optional*, float): The same as ``acceleration``, but for when the motor is decelerating |
| 42 | + shortly before reaching the set position. Defaults to ``inf`` (immediate deceleration). |
| 43 | + |
| 44 | + |
| 45 | +.. note:: |
| 46 | + |
| 47 | + Esphomelib's core loop only runs 60 times per second by default to conserve power. But this also means it's limited |
| 48 | + to 60 steps per second. To have higher step rater, you have to open up the ``<NODE_NAME>/src/main.cpp`` file, |
| 49 | + scroll down to the ``void loop()`` section and remove the ``delay(16);`` line. |
| 50 | + |
| 51 | +.. note:: |
| 52 | + |
| 53 | + If the stepper is driving in the wrong direction, you can invert the ``dir_pin``: |
| 54 | + |
| 55 | + .. code:: yaml |
| 56 | +
|
| 57 | + stepper: |
| 58 | + - platform: a4988 |
| 59 | + # ... |
| 60 | + dir_pin: |
| 61 | + number: D1 |
| 62 | + inverted: True |
| 63 | +
|
| 64 | +
|
| 65 | +.. _stepper-set_target_action: |
| 66 | + |
| 67 | +``stepper.set_target`` Action |
| 68 | +----------------------------- |
| 69 | + |
| 70 | +To use your stepper motor in :ref:`automations <automation>` or templates, you can use this action to set the target |
| 71 | +position (in steps). The stepper will always run towards the target position and stop once it has reached the target. |
| 72 | + |
| 73 | +.. code:: yaml |
| 74 | +
|
| 75 | + on_...: |
| 76 | + then: |
| 77 | + - stepper.set_target: |
| 78 | + id: my_stepper |
| 79 | + target: 250 |
| 80 | +
|
| 81 | + # Templated |
| 82 | + - stepper.set_target: |
| 83 | + id: my_stepper |
| 84 | + target: !lambda |- |
| 85 | + if (id(my_binary_sensor).value) { |
| 86 | + return 1000; |
| 87 | + } else { |
| 88 | + return -1000; |
| 89 | + } |
| 90 | +
|
| 91 | +Configuration options: |
| 92 | + |
| 93 | +- **id** (**Required**, :ref:`config-id`): The ID of the stepper. |
| 94 | +- **target** (*Optional*, int, :ref:`templatable <config-templatable>`): The target position in steps. |
| 95 | + |
| 96 | +.. note:: |
| 97 | + |
| 98 | + This action can also be expressed as a :ref:`lambda <config-lambda>`: |
| 99 | + |
| 100 | + .. code:: cpp |
| 101 | +
|
| 102 | + id(my_stepper).set_target(250); |
| 103 | +
|
| 104 | + // Get the currently set target position: |
| 105 | + int target = id(my_stepper).target_position; |
| 106 | +
|
| 107 | +.. _stepper-report_position_action: |
| 108 | + |
| 109 | +``stepper.report_position`` Action |
| 110 | +---------------------------------- |
| 111 | + |
| 112 | +All steppers start out with a target and current position of ``0`` on boot. However, if you for example want to home |
| 113 | +a stepper motor, it can be useful to **report** the stepper where it is currently at. |
| 114 | + |
| 115 | +With this action, you can set the stepper's internal position counter to a specific value (in steps). Please note |
| 116 | +that reporting the position can create unexpected moves of the stepper. For example, if the stepper's target and |
| 117 | +current position is at 1000 steps and you "report" a position of 0, the stepper will move 1000 steps forward to match |
| 118 | +the target again. |
| 119 | + |
| 120 | +.. code:: yaml |
| 121 | +
|
| 122 | + on_...: |
| 123 | + then: |
| 124 | + - stepper.report_position: |
| 125 | + id: my_stepper |
| 126 | + position: 250 |
| 127 | + # It's best to call set_target directly after report_position, so that the stepper doesn't move |
| 128 | + - stepper.set_target: |
| 129 | + id: my_stepper |
| 130 | + target: 250 |
| 131 | +
|
| 132 | + # Templated |
| 133 | + - stepper.report_position: |
| 134 | + id: my_stepper |
| 135 | + position: !lambda |- |
| 136 | + if (id(my_binary_sensor).value) { |
| 137 | + return 0; |
| 138 | + } else { |
| 139 | + return -1000; |
| 140 | + } |
| 141 | +
|
| 142 | +Configuration options: |
| 143 | + |
| 144 | +- **id** (**Required**, :ref:`config-id`): The ID of the stepper. |
| 145 | +- **target** (*Optional*, int, :ref:`templatable <config-templatable>`): The target position in steps. |
| 146 | + |
| 147 | +.. note:: |
| 148 | + |
| 149 | + This action can also be expressed as a :ref:`lambda <config-lambda>`: |
| 150 | + |
| 151 | + .. code:: cpp |
| 152 | +
|
| 153 | + id(my_stepper).report_position(250); |
| 154 | +
|
| 155 | + // Get the current position: |
| 156 | + int pos = id(my_stepper).current_position; |
| 157 | +
|
| 158 | +See Also |
| 159 | +-------- |
| 160 | + |
| 161 | +- :doc:`API Reference </api/misc/stepper>` |
| 162 | +- `Edit this page on GitHub <https://github.com/OttoWinter/esphomedocs/blob/current/esphomeyaml/components/stepper.rst>`__ |
| 163 | + |
| 164 | +.. disqus:: |
0 commit comments