• Home
  • Annotate
  • current directory
Name Date Size #Lines LOC

..22-Aug-2025-

boards/22-Aug-2025-

src/22-Aug-2025-

CMakeLists.txt A D22-Aug-2025311 117

Kconfig A D22-Aug-2025576 2719

README.rst A D22-Aug-20252.4 KiB5743

prj.conf A D22-Aug-202548 43

sample.yaml A D22-Aug-2025188 98

README.rst

1.. zephyr:code-sample:: stepper
2   :name: Stepper
3   :relevant-api: stepper_interface
4
5   Rotate a stepper motor in 4 different modes.
6
7Description
8***********
9
10This sample demonstrates how to use the stepper driver API to control a stepper motor. The sample
11spins, enables, disables, stops the stepper and outputs the events to the console.
12
13The stepper spins in 4 different modes: ping_pong_relative, ping_pong_absolute, continuous_clockwise
14and continuous_anticlockwise. The micro-step interval in nanoseconds can be configured using the
15:kconfig:option:`CONFIG_STEP_INTERVAL_NS`. The sample also demonstrates how to use the stepper callback
16to change the direction of the stepper after a certain number of steps.
17
18Pressing any button should change the mode of the stepper. The mode is printed to the console.
19Following modes are supported: enable, ping_pong_relative, ping_pong_absolute, rotate_cw, rotate_ccw,
20stop and disable.
21
22The sample also has a monitor thread that prints the actual position of the stepper motor every
23:kconfig:option:`CONFIG_MONITOR_THREAD_TIMEOUT_MS` milliseconds.
24
25Building and Running
26********************
27
28This project spins the stepper and outputs the events to the console.
29
30.. zephyr-app-commands::
31   :zephyr-app: samples/drivers/stepper/generic
32   :board: nucleo_g071rb
33   :goals: build flash
34
35Sample Output
36=============
37
38.. code-block:: console
39
40   *** Booting Zephyr OS build v4.1.0-568-gad33d28d0348 ***
41   [00:00:00.000,000] <inf> stepper: Starting generic stepper sample
42   [00:00:00.000,000] <dbg> stepper: main: stepper is 0x80086b8, name is gpio_stepper
43   [00:00:00.000,000] <dbg> gpio_stepper_motor_controller: gpio_stepper_set_microstep_interval: Setting Motor step interval to 1000000
44   [00:00:00.000,000] <dbg> stepper: monitor_thread: Actual position: 0
45   [00:00:00.491,000] <inf> stepper: mode: enable
46   [00:00:00.876,000] <inf> stepper: mode: ping pong relative
47   [00:00:01.000,000] <dbg> stepper: monitor_thread: Actual position: -114
48   [00:00:01.237,000] <inf> stepper: mode: ping pong absolute
49   [00:00:01.564,000] <inf> stepper: mode: rotate cw
50   [00:00:01.871,000] <inf> stepper: mode: rotate ccw
51   [00:00:02.000,000] <dbg> stepper: monitor_thread: Actual position: 129
52   [00:00:02.164,000] <inf> stepper: mode: stop
53   [00:00:02.444,000] <inf> stepper: mode: disable
54   [00:00:02.755,000] <inf> stepper: mode: enable
55
56   <repeats endlessly>
57