33

What libraries are available for interfacing with the GPIO?

ramblinjan
  • 4,030
  • 7
  • 33
  • 52
  • not a complete list, but here are a few - although I think this question will be closed, as list-type questions tend not to work well on the stack sites, as there will be a never-ending stream of answers – user2813274 Jun 22 '15 at 04:05

9 Answers9

16

I'm going to interpret what I think you might be asking more broadly as "How can I control GPIO from userland?"

A very nice way to get started using GPIO is using the /sys filesytem. You can do it all from the command line.

For example,

cd sys/class/gpio
echo 0 > export
cd gpio0
echo high > direction

More documentation is in linux/Documentation/gpio.txt.

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
blueshift
  • 374
  • 1
  • 6
13

There is one that I've found here. I haven't had the chance to test it, as my Pi hasn't arrived. It does, however, look assuring. There's even a forum thread here that professes promising payoff. If you want a down-to-the-basics C example using standard libraries, there's one here from eLinux.

Andrew Larsson
  • 1,614
  • 17
  • 22
11

RPi.GPIO is a Python package for GPIO control.

This tutorial video shows the basic usage of the package.

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
asalamon74
  • 4,048
  • 4
  • 29
  • 31
2

I realize I'm answering a question that is years old, but there is one that hasn't been mentioned yet: gpiozero. https://gpiozero.readthedocs.io/en/stable/

It should already be installed on new versions of Raspbian. You can also install it on other versions of Linux. https://gpiozero.readthedocs.io/en/stable/installing.html

Paul
  • 242
  • 1
  • 3
  • 10
2

quick2wire can be used by regular users (not root):

Quick2Wire Python API

A Python library for controlling the hardware attached to the Raspberry Pi's header pins, without running as the root user.

dugres
  • 121
  • 2
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Mark Booth Feb 07 '13 at 00:59
  • @MarkBooth : "the essential part of the answer" is "can be used by regular users" unlike other answers. – dugres Feb 07 '13 at 14:51
2

I use Wiring PI and it works really great. I use it with language C and had no problems so far. It is easy to understand and simple to handle.

Franzi
  • 33
  • 1
  • 5
1

Johny-Five is quite easy to use for those familiar with Node.js or JavaScript. See http://johnny-five.io/examples/raspi-io/

npm install johnny-five raspi-io
var five = require("johnny-five");
var Raspi = require("raspi-io").RaspiIO;
var board = new five.Board({
  io: new Raspi()
});

board.on("ready", function() {
  var led = new five.Led("P1-13");
  led.blink();
});

Specially useful for Pi projects controlling GPIO through a Web server

Yves M.
  • 131
  • 6
1

It is really simple to control the GPIO ports in any language as shown on http://elinux.org, so I believe that you actually do not need a framework for the direct control.

You need to know which additional features you expect of a framework, like

  • Remote control via a browser
  • A pretty browser UI or maybe a standalone program
  • Automatic timebased control (cron jobs)

I ended up writing a framework for myself: Control GPIO ports over HTTP and with cron jobs which perfectly fits my needs. I wanted to have something for home-automation. So I needed cron jobs and a JSON web interface to run a native app on my iPhone. Therefore I did not write a browser UI. I believe it would also be good for an alarm system.

I did not find a (complete) list of frameworks yet. There are some mentioned on the forum of raspberrypi.org.

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
theguy
  • 119
  • 2
1

Pi4J allows you to control the GPIO pins using Java. I'm not sure how it works but there's an explanation at http://pi4j.com/

Matthew
  • 979
  • 3
  • 10
  • 20