Skip to content
forked from PiPHP/GPIO

A non-root userland Client/Server Fork of a PHP library for accessing the GPIO pins on a Raspberry Pi. Splitting the functionality into a root run service accessible by non root clients using message queue semaphores in SysV

License

Notifications You must be signed in to change notification settings

laxamar/GPIOSysV

 
 

Repository files navigation

Amar: GPIOSysV

License Total Downloads

A userland (non-root) library for low level access to the GPIO pins on a Raspberry Pi. These pins can be used to control outputs (LEDs, motors, valves, pumps) or read inputs (sensors).

Adapted by laxamar (Twitter)

From AndrewCarterUK (Twitter)

Installing

This release has two components. A server that can be installed via git or composer. A client that uses composer to install and run.

Client (with server as a service with manual installation)

Using composer:

composer require laxamar/gpiosysv

Or:

php composer.phar require laxamar/gpiosysv

The server code is installed in the vendors/laxamar/gpiosysv directory of composer under the service directory and can be installed as below

Server

The server can be downloaded as by git sudo install_systemd.sh will install the necessary files in /usr/local/GPIOSysV and install the systemd service

Examples

Setting Output Pins

use Amar\GPIOSysV\GPIOSysVClt;

// Create a GPIO object
$gpio_obj = GPIOSysVClt::getInstance();

// Set the value of the pin high (turn it on)
$success = $gpio_obj->setPinHigh(18);

$success = $gpio_obj->setPinLow(18);

// Set a series on PINs using BCD
$gpio->setPinsBinary($board, CS_PINs);
for ($dec = 0; $dec < 8; $dec++) {
    // echo "Decimal $dec";
    $gpio->strobeBinary($dec, LED_PINs, FLASH_PIN, 1, 0, $frequency, true, $error);
}

Input Pin

use Amar\GPIOSysV\GPIOSysVClt;

// Create a GPIO object
$gpio_obj = GPIOSysVClt::getInstance();

// Set the value of the pin high (turn it on)
$value = $gpio_obj->getPin(4);

Further Reading

SitePoint published a tutorial about powering Raspberry Pi projects with PHP which used this library and shows a push button example with a wiring diagram.

More Resources

PiPHP maintains a resource directory for PHP programming on the Raspberry Pi.

About

A non-root userland Client/Server Fork of a PHP library for accessing the GPIO pins on a Raspberry Pi. Splitting the functionality into a root run service accessible by non root clients using message queue semaphores in SysV

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 96.9%
  • Shell 3.1%