mirror of
https://github.com/esphome/esphome-docs.git
synced 2024-09-28 04:17:47 +02:00
Add Stepper Support (#68)
This commit is contained in:
parent
8489ec555e
commit
7b68e925d0
35
api/misc/stepper.rst
Normal file
35
api/misc/stepper.rst
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
Stepper Component
|
||||||
|
=================
|
||||||
|
|
||||||
|
.. cpp:namespace:: nullptr
|
||||||
|
|
||||||
|
API Reference
|
||||||
|
-------------
|
||||||
|
|
||||||
|
.. cpp:namespace:: nullptr
|
||||||
|
|
||||||
|
Stepper
|
||||||
|
*******
|
||||||
|
|
||||||
|
.. doxygenclass:: stepper::Stepper
|
||||||
|
:members:
|
||||||
|
:protected-members:
|
||||||
|
:undoc-members:
|
||||||
|
|
||||||
|
.. doxygenclass:: stepper::SetTargetAction
|
||||||
|
:members:
|
||||||
|
:protected-members:
|
||||||
|
:undoc-members:
|
||||||
|
|
||||||
|
.. doxygenclass:: stepper::ReportPositionAction
|
||||||
|
:members:
|
||||||
|
:protected-members:
|
||||||
|
:undoc-members:
|
||||||
|
|
||||||
|
A4988
|
||||||
|
*****
|
||||||
|
|
||||||
|
.. doxygenclass:: stepper::A4988
|
||||||
|
:members:
|
||||||
|
:protected-members:
|
||||||
|
:undoc-members:
|
164
esphomeyaml/components/stepper/index.rst
Normal file
164
esphomeyaml/components/stepper/index.rst
Normal file
@ -0,0 +1,164 @@
|
|||||||
|
Stepper Component
|
||||||
|
=================
|
||||||
|
|
||||||
|
The ``stepper`` component allows you to use stepper motors with esphomelib.
|
||||||
|
Currently only the A4988 stepper driver
|
||||||
|
(`datasheet <https://www.pololu.com/file/0J450/a4988_DMOS_microstepping_driver_with_translator.pdf>`__)
|
||||||
|
is supported.
|
||||||
|
|
||||||
|
.. code:: yaml
|
||||||
|
|
||||||
|
# Example configuration entry
|
||||||
|
stepper:
|
||||||
|
- platform: a4988
|
||||||
|
id: my_stepper
|
||||||
|
step_pin: D0
|
||||||
|
dir_pin: D1
|
||||||
|
max_speed: 250 steps/s
|
||||||
|
|
||||||
|
# Optional:
|
||||||
|
sleep_pin: D2
|
||||||
|
acceleration: inf
|
||||||
|
deceleration: inf
|
||||||
|
|
||||||
|
|
||||||
|
Configuration variables:
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
- **id** (**Required**, :ref:`config-id`): Specify the ID of the stepper so that you can control it.
|
||||||
|
- **step_pin** (**Required**, :ref:`Pin Schema <config-pin_schema>`): The ``STEP`` pin of the A4988
|
||||||
|
stepper driver.
|
||||||
|
- **dir_pin** (**Required**, :ref:`Pin Schema <config-pin_schema>`): The ``DIRECTION`` pin of the A4988
|
||||||
|
stepper driver.
|
||||||
|
- **max_speed** (**Required**, float): The maximum speed in ``steps/s`` (steps per seconds) to drive the
|
||||||
|
stepper at. Note most steppers can't step properly with speeds higher than 250 steps/s.
|
||||||
|
- **sleep_pin** (*Optional*, :ref:`Pin Schema <config-pin_schema>`): Optionally also use the ``SLEEP`` pin
|
||||||
|
of the A4988 stepper driver. If specified, the driver will be put into sleep mode as soon as the stepper
|
||||||
|
reaches the target steps.
|
||||||
|
- **acceleration** (*Optional*, float): The acceleration in ``steps/s^2`` (steps per seconds squared)
|
||||||
|
to use when starting to move. The default is ``inf`` which means infinite acceleration, so the
|
||||||
|
stepper will try to drive with the full speed immediately.
|
||||||
|
- **deceleration** (*Optional*, float): The same as ``acceleration``, but for when the motor is decelerating
|
||||||
|
shortly before reaching the set position. Defaults to ``inf`` (immediate deceleration).
|
||||||
|
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
Esphomelib's core loop only runs 60 times per second by default to conserve power. But this also means it's limited
|
||||||
|
to 60 steps per second. To have higher step rater, you have to open up the ``<NODE_NAME>/src/main.cpp`` file,
|
||||||
|
scroll down to the ``void loop()`` section and remove the ``delay(16);`` line.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
If the stepper is driving in the wrong direction, you can invert the ``dir_pin``:
|
||||||
|
|
||||||
|
.. code:: yaml
|
||||||
|
|
||||||
|
stepper:
|
||||||
|
- platform: a4988
|
||||||
|
# ...
|
||||||
|
dir_pin:
|
||||||
|
number: D1
|
||||||
|
inverted: True
|
||||||
|
|
||||||
|
|
||||||
|
.. _stepper-set_target_action:
|
||||||
|
|
||||||
|
``stepper.set_target`` Action
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
To use your stepper motor in :ref:`automations <automation>` or templates, you can use this action to set the target
|
||||||
|
position (in steps). The stepper will always run towards the target position and stop once it has reached the target.
|
||||||
|
|
||||||
|
.. code:: yaml
|
||||||
|
|
||||||
|
on_...:
|
||||||
|
then:
|
||||||
|
- stepper.set_target:
|
||||||
|
id: my_stepper
|
||||||
|
target: 250
|
||||||
|
|
||||||
|
# Templated
|
||||||
|
- stepper.set_target:
|
||||||
|
id: my_stepper
|
||||||
|
target: !lambda |-
|
||||||
|
if (id(my_binary_sensor).value) {
|
||||||
|
return 1000;
|
||||||
|
} else {
|
||||||
|
return -1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
Configuration options:
|
||||||
|
|
||||||
|
- **id** (**Required**, :ref:`config-id`): The ID of the stepper.
|
||||||
|
- **target** (*Optional*, int, :ref:`templatable <config-templatable>`): The target position in steps.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
This action can also be expressed as a :ref:`lambda <config-lambda>`:
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
id(my_stepper).set_target(250);
|
||||||
|
|
||||||
|
// Get the currently set target position:
|
||||||
|
int target = id(my_stepper).target_position;
|
||||||
|
|
||||||
|
.. _stepper-report_position_action:
|
||||||
|
|
||||||
|
``stepper.report_position`` Action
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
All steppers start out with a target and current position of ``0`` on boot. However, if you for example want to home
|
||||||
|
a stepper motor, it can be useful to **report** the stepper where it is currently at.
|
||||||
|
|
||||||
|
With this action, you can set the stepper's internal position counter to a specific value (in steps). Please note
|
||||||
|
that reporting the position can create unexpected moves of the stepper. For example, if the stepper's target and
|
||||||
|
current position is at 1000 steps and you "report" a position of 0, the stepper will move 1000 steps forward to match
|
||||||
|
the target again.
|
||||||
|
|
||||||
|
.. code:: yaml
|
||||||
|
|
||||||
|
on_...:
|
||||||
|
then:
|
||||||
|
- stepper.report_position:
|
||||||
|
id: my_stepper
|
||||||
|
position: 250
|
||||||
|
# It's best to call set_target directly after report_position, so that the stepper doesn't move
|
||||||
|
- stepper.set_target:
|
||||||
|
id: my_stepper
|
||||||
|
target: 250
|
||||||
|
|
||||||
|
# Templated
|
||||||
|
- stepper.report_position:
|
||||||
|
id: my_stepper
|
||||||
|
position: !lambda |-
|
||||||
|
if (id(my_binary_sensor).value) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return -1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
Configuration options:
|
||||||
|
|
||||||
|
- **id** (**Required**, :ref:`config-id`): The ID of the stepper.
|
||||||
|
- **target** (*Optional*, int, :ref:`templatable <config-templatable>`): The target position in steps.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
This action can also be expressed as a :ref:`lambda <config-lambda>`:
|
||||||
|
|
||||||
|
.. code:: cpp
|
||||||
|
|
||||||
|
id(my_stepper).report_position(250);
|
||||||
|
|
||||||
|
// Get the current position:
|
||||||
|
int pos = id(my_stepper).current_position;
|
||||||
|
|
||||||
|
See Also
|
||||||
|
--------
|
||||||
|
|
||||||
|
- :doc:`API Reference </api/misc/stepper>`
|
||||||
|
- `Edit this page on GitHub <https://github.com/OttoWinter/esphomedocs/blob/current/esphomeyaml/components/stepper.rst>`__
|
||||||
|
|
||||||
|
.. disqus::
|
@ -37,8 +37,7 @@ This action toggles a switch with the given ID when executed.
|
|||||||
|
|
||||||
on_...:
|
on_...:
|
||||||
then:
|
then:
|
||||||
- switch.toggle:
|
- switch.toggle: id: relay_1
|
||||||
id: relay_1
|
|
||||||
|
|
||||||
.. _switch-turn_on_action:
|
.. _switch-turn_on_action:
|
||||||
|
|
||||||
@ -51,8 +50,7 @@ This action turns a switch with the given ID on when executed.
|
|||||||
|
|
||||||
on_...:
|
on_...:
|
||||||
then:
|
then:
|
||||||
- switch.turn_on:
|
- switch.turn_on: relay_1
|
||||||
id: relay_1
|
|
||||||
|
|
||||||
.. _switch-turn_off_action:
|
.. _switch-turn_off_action:
|
||||||
|
|
||||||
@ -65,8 +63,7 @@ This action turns a switch with the given ID off when executed.
|
|||||||
|
|
||||||
on_...:
|
on_...:
|
||||||
then:
|
then:
|
||||||
- switch.turn_off:
|
- switch.turn_off: relay_1
|
||||||
id: relay_1
|
|
||||||
|
|
||||||
lambda calls
|
lambda calls
|
||||||
************
|
************
|
||||||
|
36
esphomeyaml/images/stepper.svg
Normal file
36
esphomeyaml/images/stepper.svg
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
viewBox="0 0 280 60"
|
||||||
|
height="60"
|
||||||
|
width="280"
|
||||||
|
xml:space="preserve"
|
||||||
|
id="svg2"
|
||||||
|
version="1.1"><metadata
|
||||||
|
id="metadata8"><rdf:RDF><cc:Work
|
||||||
|
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
|
||||||
|
id="defs6" /><g
|
||||||
|
transform="matrix(1.3333333,0,0,-1.3333333,0,60)"
|
||||||
|
id="g10"><g
|
||||||
|
transform="scale(0.1)"
|
||||||
|
id="g12"><path
|
||||||
|
id="path14"
|
||||||
|
style="fill:#000000;fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||||
|
d="M 151.832,440 H 1948.17 c 77.32,0 140,-62.68 140,-140 V 145 c 0,-77.3203 -62.68,-140 -140,-140 H 151.832 c -77.3203,0 -140,62.6797 -140,140 v 155 c 0,77.32 62.6797,140 140,140 z" /><path
|
||||||
|
id="path16"
|
||||||
|
style="fill:none;stroke:#000000;stroke-width:10;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
d="M 151.832,440 H 1948.17 c 77.32,0 140,-62.68 140,-140 V 145 c 0,-77.3203 -62.68,-140 -140,-140 H 151.832 c -77.3164,0 -140,62.6797 -140,140 v 155 c 0,77.32 62.6836,140 140,140 z" /><g
|
||||||
|
transform="scale(10)"
|
||||||
|
id="g18"><text
|
||||||
|
id="text22"
|
||||||
|
style="font-variant:normal;font-weight:900;font-size:35px;font-family:Montserrat;-inkscape-font-specification:Montserrat-Black;writing-mode:lr-tb;fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||||
|
transform="matrix(1,0,0,-1,9.48516,9.75)"><tspan
|
||||||
|
id="tspan20"
|
||||||
|
y="0"
|
||||||
|
x="0 25.645 51.535 78.090004 106.74499 135.39999 161.95499">STEPPER</tspan></text>
|
||||||
|
</g></g></g></svg>
|
After Width: | Height: | Size: 1.9 KiB |
@ -681,9 +681,9 @@ Misc Components
|
|||||||
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
|
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
|
||||||
`ESP32 Touch Hub`_ `Status LED`_ `PN532`_
|
`ESP32 Touch Hub`_ `Status LED`_ `PN532`_
|
||||||
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
|
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
|
||||||
|RDM6300|_ |Time|_
|
|RDM6300|_ |Time|_ |Stepper|_
|
||||||
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
|
-------------------------------------------------- -------------------------------------------------- --------------------------------------------------
|
||||||
`RDM6300`_ `Time`_
|
`RDM6300`_ `Time`_ `Stepper`_
|
||||||
================================================== ================================================== ==================================================
|
================================================== ================================================== ==================================================
|
||||||
|
|
||||||
.. |Dallas Hub| image:: /esphomeyaml/images/dallas.jpg
|
.. |Dallas Hub| image:: /esphomeyaml/images/dallas.jpg
|
||||||
@ -728,6 +728,10 @@ Misc Components
|
|||||||
.. |Time| image:: /esphomeyaml/images/clock-outline.svg
|
.. |Time| image:: /esphomeyaml/images/clock-outline.svg
|
||||||
:class: component-image
|
:class: component-image
|
||||||
.. _Time: /esphomeyaml/components/time.html
|
.. _Time: /esphomeyaml/components/time.html
|
||||||
|
.. |Stepper| image:: /esphomeyaml/images/stepper.svg
|
||||||
|
:class: component-image
|
||||||
|
.. _Stepper: /esphomeyaml/components/stepper.html
|
||||||
|
|
||||||
|
|
||||||
.. _cookbook:
|
.. _cookbook:
|
||||||
|
|
||||||
|
@ -12,3 +12,4 @@ Status LED, components/status_led, led-on.svg
|
|||||||
PN532, components/pn532, pn532.jpg
|
PN532, components/pn532, pn532.jpg
|
||||||
RDM6300, components/rdm6300, rdm6300.jpg
|
RDM6300, components/rdm6300, rdm6300.jpg
|
||||||
Time, components/time, clock-outline.svg
|
Time, components/time, clock-outline.svg
|
||||||
|
Stepper, components/stepper, stepper.svg
|
||||||
|
|
Loading…
Reference in New Issue
Block a user