zephyr/samples/basic/servo_motor
Gerard Marull-Paretas 23225c68c6 samples: basic: servo_motor: delete nrf52840dk wrong overlay
The overlay was accidentally pushed as part of another commit while
doing some pinctrl/pwm tests.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-11 10:49:05 +02:00
..
boards samples: basic: servo_motor: delete nrf52840dk wrong overlay 2022-05-11 10:49:05 +02:00
dts/bindings samples: basic: servo_motor: use pwm_dt_spec 2022-04-28 11:29:38 +02:00
src samples: migrate includes to contain <zephyr/...> prefix 2022-05-06 11:29:59 +02:00
CMakeLists.txt cmake: increase minimal required version to 3.20.0 2021-08-20 09:47:34 +02:00
README.rst samples: basic: servo_motor: use pwm_dt_spec 2022-04-28 11:29:38 +02:00
prj.conf
sample.yaml samples: basic: servo_motor: use pwm_dt_spec 2022-04-28 11:29:38 +02:00

README.rst

.. _servo-motor-sample:

Servomotor
##########

Overview
********

This is a sample app which drives a servomotor using PWM.

The sample rotates a servomotor back and forth in the 180 degree range with a
PWM control signal.

This app is targeted for servomotor ROB-09065. The corresponding PWM pulse
widths for a 0 to 180 degree range are 700 to 2300 microseconds, respectively.
Different servomotors may require different PWM pulse widths, and you may need
to modify the source code if you are using a different servomotor.

Requirements
************

The sample requires a servomotor whose signal pin is connected to a pin driven
by PWM. The servo must be defined in Devicetree using the ``pwm-servo``
compatible (part of the sample) and setting its node label to ``servo``. You
will need to do something like this:

.. code-block:: devicetree

   / {
       servo: servo {
           compatible = "pwm-servo";
           pwms = <&pwm0 1 PWM_MSEC(20) PWM_POLARITY_NORMAL>;
           min-pulse = <PWM_USEC(700)>;
           max-pulse = <PWM_USEC(2500)>;
       };
   };

Note that a commonly used period value is 20 ms. See
:zephyr_file:`samples/basic/servo_motor/boards/bbc_microbit.overlay` for an
example.

Wiring
******

BBC micro:bit
=============

You will need to connect the motor's red wire to external 5V, the black wire to
ground and the white wire to the SCL pin, i.e. pin P19 on the edge connector.

Building and Running
********************

The sample has a devicetree overlay for the :ref:`bbc_microbit`.

This sample can be built for multiple boards, in this example we will build it
for the bbc_microbit board:

.. zephyr-app-commands::
   :zephyr-app: samples/basic/servo_motor
   :board: bbc_microbit
   :goals: build flash
   :compact: