ROS 2 Jazzy Python package for Raspberry Pi GPIO control using gpiozero.
DigitalInputDeviceSmoothedInputDeviceDigitalOutputDevicePWMOutputDeviceServo
- Publishes digital input state on
~/inputs/<name>/state(std_msgs/Bool) - Publishes smoothed input value on
~/smoothed_inputs/<name>/value(std_msgs/Float32) - Provides digital output service
~/outputs/<name>/set(std_srvs/SetBool) - Provides PWM output service
~/pwm_outputs/<name>/set(ros_common_srvs/SetFloat32) - Provides servo output service
~/servo_outputs/<name>/set(ros_common_srvs/SetFloat32)
cd /path/to/workspace
colcon build --packages-select rpi_gpiozero_rossource install/setup.bash
ros2 launch rpi_gpiozero_ros gpiozero_node.launch.pyParameters live under the node name (for example gpiozero_node) in ros__parameters:. See config/gpiozero_params.yaml.
Declare each device under gpio.<logical_name>.<field>. In YAML this is normally a nested map gpio: with one key per <logical_name>. ROS stores these as flat dotted parameters (for example gpio.button.pin).
There must be at least one configured device (type + pin per logical name).
| Parameter | Type | Default | Description |
|---|---|---|---|
pin_factory |
string | auto |
auto: use gpiozero’s default backend. mock: MockFactory with PWM-capable mock pins so pwm_output can run without a Pi. |
pin_numbering |
string | bcm |
How each integer pin is turned into a gpiozero pin specification. See next subsection. |
publish_rate_hz |
float | 20.0 |
Period for publishing all digital and smoothed input topics (1.0 / publish_rate_hz). Must be > 0. |
If a device entry defines publish_rate_hz, it is validated (must be > 0) but publishing still uses the global publish_rate_hz timer only.
| Value | Example YAML pin |
Passed to gpiozero |
|---|---|---|
bcm |
17 |
17 (integer BCM number) |
gpio |
17 |
"GPIO17" |
board |
11 |
"BOARD11" (header pin numbering) |
wpi |
0 |
"WPI0" (WiringPi style index; availability depends on backend) |
The map key <logical_name> becomes the device name in topics and services. Required for every entry: type and pin.
type |
Extra fields | Notes |
|---|---|---|
digital_input |
|
If pull_up is omitted and active_state is omitted, behaviour matches gpiozero pull-up default (pull_up=true). If you set active_state, you must omit pull_up; gpiozero does not allow both pull_up=true/false and a custom active_state. See also. |
smoothed_input |
|
queue_len must be > 0; threshold in [0.0, 1.0]. |
digital_output |
|
|
pwm_output |
|
initial_value in [0.0, 1.0]; frequency must be > 0. On real Pi hardware, BCM PWM-capable pins restrictions still apply (same as gpiozero). |
servo |
|
initial_value and service setpoint in [0.0, 1.0]; min_pulse_width > 0; max_pulse_width > min_pulse_width; frame_width > max_pulse_width. See gpiozero Servo. |