Search code examples
ubunturaspberry-pigpiorossysfs

Access GPIO pins of Raspberry Pi 2 with ROS


I'm trying to access the GPIO pins of a Raspberry Pi 2 using the robot operating systen ROS. I know, there are many tutorials on this topic. But my problem is as follows:

  • The recommended Linux distribution for ROS is Ubuntu. Since there are other Ubuntu machines in the ROS network, I'd like to avoid compiling ROS for a different OS.
  • In Ubuntu the /sys/class/gpio sysfs is not enabled by default. I'd need to recompile the kernel with a custom configuration.
  • If I can't use /sys/class/gpio, it looks like I need to use /dev/mem (e.g. with the RPi.GPIO package).
  • But /dev/mem is only accessible to root.
  • And I can't run a ROS node as root, since it's missing rospy and the whole ROS setup.

So, what's the "easiest" way to get GPIO access within a ROS node?


Solution

  • I think I've found a rather clean solution to my problem:

    The pigpio library is what I needed. It runs a daemon started with sudo, which is controlling the GPIO pins. A client program (started without sudo) communicates with the deamon and thus indirectly controls the pins.

    You can even run the client on a remote machine. This way a ROS node can control the GPIO pins of a remote raspberry, which itself isn't even running ROS.

    My current setup is a rospy node (indigo) on a fitlet PC talking to a Raspberry Pi 2, both running Ubuntu 14.04.

    djsw's answer in the ROS forum pointed me in the right direction.