I have a Pi running ROS 2 in Ubuntu. How do you access the Pi's GPIO ports? Is there a library? I'm not sure if I'm running into a ROS 2 or C++ issue.

I've had trouble importing the wiringPi package as there was no .cmake.

CMake Error at CMakeLists.txt:17 (find_package):
  By not providing "FindwiringPi.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "wiringPi",
  but CMake did not find one.

  Could not find a package configuration file provided by "wiringPi" with any
  of the following names:


  Add the installation prefix of "wiringPi" to CMAKE_PREFIX_PATH or set
  "wiringPi_DIR" to a directory containing one of the above files.  If
  "wiringPi" provides a separate development package or SDK, be sure it has
  been installed.

Is it common practice to use someone's pigpio repo as a ROS 2 package?


  • 1
    $\begingroup$ what have you tried? $\endgroup$
    – jsotola
    Nov 20, 2023 at 20:58
  • $\begingroup$ Welcome to Robotics, but I'm afraid that shopping questions really aren't a good fit for a stack exchange site. We prefer practical, answerable questions based on actual problems that you face. Take a look at How to Ask and tour for more information on how stack exchange works, and the Robotics question checklist for details of how to write a good question. $\endgroup$
    – Tully
    Nov 21, 2023 at 2:34
  • $\begingroup$ I tried to answer it assuming a beginner level learner. @Tully $\endgroup$
    – Robotawi
    Nov 21, 2023 at 2:48
  • 1
    $\begingroup$ Thanks @Robotawi, you did do your best to provide an answer that could answer one interpretation of the question. There are lots of ways to solve this problem. You've picked one, which I agree is generally reasonable for a potential interpretation of the question. This question does not meet our standards for a good question which is why I closed it. Please read through the links in my comment above for more info. You spent a bunch of time and potentially others will spend a bunch of time trying to answer this question that cannot be effectively answered and would better serve a good question. $\endgroup$
    – Tully
    Nov 21, 2023 at 16:33
  • $\begingroup$ Thanks for revising this. But I'm not going to reopen it. It's now a duplicate of your other question robotics.stackexchange.com/questions/105602/… $\endgroup$
    – Tully
    Nov 22, 2023 at 18:35

2 Answers 2


Your question about using Rasperry Pi GPIO ports in ROS 2 is an example of combining hardware controller with robotics software frameworks. I mean they are separate, but can be integrated to serve application purpose. Let's break down the integration process in a simple way.

ROS 2: is a framework used in robotics for managing communication and an hardware interfacing.

Raspberry Pi: a computer equipped with general purpose input/output (GPIO) pins. Thosse pins can interface with various electronic components like LEDs, sensors, and motor drives. We can program those pins with Python or C++.

The Integration

Integrating Ras Pi's GPIO functionality with ROS 2 involves creating a ROS 2 node which code interacts with the GPIO pin. This node serves as a bridge, allowing ROS 2 ecosystem to communicate with the Raspberry Pi. Notice we can write code that talks with Ras Pi with nothing to do with ROS at all.

Minimal examples:

(1) Simple Python LED control script

Controlling a LED using the Ras Pi's GPIO:

import RPi.GPIO as GPIO
import time

led_pin = 17  # GPIO pin to which a LED is connected

GPIO.setup(led_pin, GPIO.OUT)

while True:
    GPIO.output(led_pin, GPIO.HIGH)
    GPIO.output(led_pin, GPIO.LOW)


(2) Make the previous minimal example a ROS 2 node

Notice how the code that uses the GPIO integrates within the code that makes a ROS 2 node.

import rclpy
from rclpy.node import Node
import RPi.GPIO as GPIO
import time

class LEDBlinkerNode(Node):
    def __init__(self):
        self.led_pin = 17
        GPIO.setup(self.led_pin, GPIO.OUT)
        self.timer = self.create_timer(1.0, self.timer_callback)

    def timer_callback(self):
        GPIO.output(self.led_pin, GPIO.HIGH)
        GPIO.output(self.led_pin, GPIO.LOW)

def main(args=None):
    led_blinker_node = LEDBlinkerNode()


if __name__ == '__main__':

Those examples are about the idea of integrating separate modules to serve the purpose the application. The key takeaway is the adaptability of these systems. Start simple and keep going!

I did not go into the parts of the dependencies installation, which is usually available in documentations. If this is needed, I will enhance the reply.

  • $\begingroup$ Have you ever used wiringPi with C? I got the gpio commands working in the terminal and reflect on the physical wiring but I can't get it to work using the wiringPi library. $\endgroup$
    – Yato
    Nov 28, 2023 at 20:00

Pi GPIO library doesn't interact with ROS2 in any way I know of. Just use it as you would any library. The Pi GPIO deamon doesn't seem to impact ROS2 function either.


Not the answer you're looking for? Browse other questions tagged or ask your own question.