Cannon Moyer
Cannon Moyer

Reputation: 99

Write GPIO Raspberry PI 2 B+

I am new to Raspberry Pi. I need to read and write to the GPIO pins on the Raspberry Pi. I am trying to do this operation in php, python, and the command line. Do I need to download any kind of library to do this in php, python, or command line?

Upvotes: 2

Views: 225

Answers (3)

Ghanima
Ghanima

Reputation: 409

Besides sysfs, the virtual filesystem that allows root to directly read from and write to GPIO pins by echo to or cat from various files in the /sys/class/gpio/ folder (as already mentioned) there are libraries available to do so. Two noteworthy examples are:

  1. wiringPi library provides a cli command gpio to be used by non-privileged users for direct access.

  2. pigs utility, part of the pigpio library also offers comprehensive control of the GPIO pins from the command line (see pigpio for download of source, installation procedures and excellent application examples).

Upvotes: 1

Martin Beckett
Martin Beckett

Reputation: 96119

In python you can use the GPIO library

Generally in unix devices are represented as files, so you can open a file in /dev/ and read/write to the devices.

You might get more detailed help on https://raspberrypi.stackexchange.com/

Upvotes: 3

Salo
Salo

Reputation: 2126

No, controlling GPIOs from userspace is a feature provided by the operating system. You just need to write a number to the GPIO value "file" thats provided by the kernel. It is located under /sys/class/gpio/gpio<number>/value. This should give you a kickstart. There they show how its done on the BeagleBoard with the shell but it is a general concept and it doesnt matter which language you use.

Upvotes: 3

Related Questions