PWM Servomotor Preset Snippet (pwm-servo)
west build -S pwm-servo [...]
Overview
This snippet is quite board specific and prepares a dedicated PWM channel exclusively for the standard Servomotor sample from Zephyr.
Board specific setups
Only selected boards are supported by this snippet. There is no basic configuration.
Supported boards are:
Cytron MOTION 2350 Pro
Cytron Maker Pi RP2040
Connect a servomotor MG996R to the first on-board PWM channel for servomotors, the 8×3 pin header block at position 17. See the board positions diagram for details.
The corresponding PWM pulse widths for a range of -90° to +90° (180°) are 500 ㎲ to 2,500 ㎲ with a period of 50 ㎐. All these servomotor specific parameters are preset by the snippet PWM Servomotor Preset Snippet (pwm-servo) that have to use to get access to this dedicated PWM channel together with the original Zephyr Servomotor sample. Invoke west build and west flash with this snipped and optional mixed with others, for example:
On ARM Cortex-M33
west build -b cytron_motion_2350_pro/rp2350a/m33 -p always -S "usb-console pwm-servo" -d build/cytron_motion_rp2350 zephyr/samples/basic/servo_motor west flash -r uf2 -d build/cytron_motion_rp2350On Hazard3 RISC-V (RV32IMAC+)
west build -b cytron_motion_2350_pro/rp2350a/hazard3 -p always -S "usb-console pwm-servo" -d build/cytron_motion_rp2350 zephyr/samples/basic/servo_motor west flash -r uf2 -d build/cytron_motion_rp2350
1servo: &pwm_servo0 {
2 compatible = "pwm-servo";
3 min-pulse = <PWM_USEC(500)>;
4 max-pulse = <PWM_USEC(2500)>;
5};
Connect a servomotor MG996R to the first on-board PWM channel for servomotors, the 4×3 pin header block at position 19. See the board positions diagram for details.
The corresponding PWM pulse widths for a range of -90° to +90° (180°) are 500 ㎲ to 2,500 ㎲ with a period of 50 ㎐. All these servomotor specific parameters are preset by the snippet PWM Servomotor Preset Snippet (pwm-servo) that have to use to get access to this dedicated PWM channel together with the original Zephyr Servomotor sample. Invoke west build and west flash with this snipped and optional mixed with others, for example:
west build -b cytron_maker_pi_rp2040 -p always -S "usb-console pwm-servo" -d build/cytron_maker_rp2040 zephyr/samples/basic/servo_motor
west flash -r uf2 -d build/cytron_maker_rp2040
1servo: &pwm_servo0 {
2 compatible = "pwm-servo";
3 min-pulse = <PWM_USEC(500)>;
4 max-pulse = <PWM_USEC(2500)>;
5};
Connect a servomotor MG996R to the first on-board PWM channel for servomotors, the 4×3 pin header block (HDR1 and HDR2).
The corresponding PWM pulse widths for a range of -90° to +90° (180°) are 500 ㎲ to 2,500 ㎲ with a period of 50 ㎐. All these servomotor specific parameters are preset by the snippet PWM Servomotor Preset Snippet (pwm-servo) that have to use to get access to this dedicated PWM channel together with the original Zephyr Servomotor sample. Invoke west build and west flash with this snipped and optional mixed with others, for example:
west build -b coffeecaller_nrf52/nrf52840 -p always -S "pwm-servo" -d build/coffeecaller_nrf52 zephyr/samples/basic/servo_motor
west flash -r uf2 -d build/coffeecaller_nrf52
1servo: &pwm_servo0 {
2 compatible = "pwm-servo";
3 min-pulse = <PWM_USEC(500)>;
4 max-pulse = <PWM_USEC(2500)>;
5};
How to add support of a new board
add board devicetree overlay to this snippet;
which add following options to the dedicated PWM node:
compatible = "pwm-servo";min-pulse = <PWM_USEC(500)>;max-pulse = <PWM_USEC(2500)>;