A RaspberryPi GPIO library written in PHP.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
src
tests
.gitignore
.scrutinizer.yml
.travis.yml
LICENSE
Makefile
README.md
build.xml
composer.json
composer.lock
phpunit.php
phpunit.xml

README.md

GPIO

Build Status Code Coverage Scrutinizer Code Quality Code Climate Latest Stable Version Latest Unstable Version License

A RaspberryPi GPIO library written in PHP, This library makes it a breeze to work with simple inputs and outputs such as buttons, switches, LED's, motors and relays.

Requirements

  • PHP >= 7.1.0

This library is unit tested against PHP 7.1, 7.2 and the bleeding edge (nightly build)!

License

This library is released under the GPLv3 license, you are welcome to use it, improve it and contribute your changes back!

Installation

The recommended way of installing this library is via. Composer; To install using Composer type the following command at the console:

composer require ballen/gpio

Example usage

An example of a flashing a single LED:

use Ballen\GPIO\GPIO;

// Create a new instane of the GPIO class.
$gpio = new GPIO();

// Configure our 'LED' output...
$led = $gpio->pin(18, GPIO::OUT);

// Create a basic loop that runs continuously...
while (true) {
    // Turn the LED on...
    $led->setValue(GPIO::HIGH);
    // Wait for one second...
    sleep(1);
    // Turn off the LED...
    $led->setValue(GPIO::LOW);
    // Wait for one second...
    sleep(1);
}

Tests and coverage

This library is fully unit tested using PHPUnit.

I use TravisCI for continuous integration, which triggers tests for PHP 7.1, 7.2 and the latest nightly build every time a commit is pushed.

If you wish to run the tests yourself you should run the following:

# Install the GPIO Library (which will include PHPUnit as part of the require-dev dependencies)
composer install

# Now we run the unit tests (from the root of the project) like so:
./vendor/bin/phpunit

Code coverage can also be ran and a report generated (this does require XDebug to be installed)...

./vendor/bin/phpunit --coverage-html ./report

Support

I am happy to provide support via. my personal email address, so if you need a hand drop me an email at: ballen@bobbyallen.me.