PHPackages                             iqb/gpio - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. iqb/gpio

ActiveLibrary[Testing &amp; Quality](/categories/testing)

iqb/gpio
========

GPIO library and test framework

261PHP

Since Oct 26Pushed 10y ago1 watchersCompare

[ Source](https://github.com/iqb/gpio)[ Packagist](https://packagist.org/packages/iqb/gpio)[ RSS](/packages/iqb-gpio/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP GPIO abstraction
====================

[](#php-gpio-abstraction)

GPIO abstraction using the linux sysfs interface, mainly for Raspberry PI.

Installation
------------

[](#installation)

Just put the following in your `composer.json` file inside your project root. No stable version exists so far.

```
"require": {
  "iqb/gpio": "*@dev"
}
```

Features
--------

[](#features)

- `Pin` class: abstraction of a single GPIO pin
- `LCD` class: abstraction of a HD44780 compatible 16x2 display
- `PinEmulator` class: mock replacement for `Pin` class
- `Emulator` class: uses `PinEmulator`s to make GPIO using software testable!

### GPIO pin abstraction

[](#gpio-pin-abstraction)

The `Pin` class provides a simple interface to GPIO pins/ports. It uses the userspace GPIO interface provided by the linux kernel below `/sys/class/gpio` and so will obviously not work on other operating systems. It is developed on Raspbian Wheezy.

The linux kernel identifies the GPIO pins by numbers. They can be found using the BCM value of the `gpio readall` (you need WiringPi for the command to exist).

```
namespace iqb\gpio;

// Will open the GPIO pin with BCM number 17 = physical pin 11
$pin = new Pin(17);

// A pin must be enabled so it can be used.
// Pin-consumers like the LCD class enable pins themselves when they use them
$pin->enable();

// Pin is in output mode
$pin->setDirection(Pin::DIRECTION_OUT);

// and the pin is now enabled (sending a 1)
$pin->setValue(true);

// Pin is in input mode now
$pin->setDirection(Pin::DIRECTION_IN);

// Enable edge detection.
// This feature is required to detect changes of the value.
$pin->setEdge(Pin::EDGE_BOTH);

// Read the current value
$value = $pin->getValue();

// We can wait for a change of the pin value using stream_select()
// We need to initialize the file handle sets we want to monitor.
// Changes to GPIO pins are "exceptional" (out of band) events
// so we need the third set of handles.
$read = [];
$write = [];
$except = [$pin->getValueHandle()];
while (true) {
  if (-1 === stream_select($read, $write, $except, 60)) { continue; }

  echo "Value changed: " . ($pin->getValue() ? '1' : '0') . "\n";
}
```

### HD44780 compatible 16x2 display abstraction

[](#hd44780-compatible-16x2-display-abstraction)

This display is connected via 6 GPIO pins.

```
namespace iqb\gpio;

// Create the display, the pins are the actual used pins from my personal project
// You don't need to enable the pins or set the direction,
// that is done by the LCD class.
$lcd = new LCD(
  new Pin(7),
  new Pin(8),
  new Pin(25),
  new Pin(24),
  new Pin(23),
  new Pin(18)
);

// Enable the pins, set the direction, send some magic commands to the display ...
$lcd->initialize();

// Write something in the first line
$lcd->writeString('abcdefghijklmnop', 1);
// Write something in the second line
$lcd->writeString('0123456789012345', 2);
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2b38daf7ea29726e8f479a49857e46ebe2396b354ce31dfabcf504633af43de1?d=identicon)[dennisbirkholz](/maintainers/dennisbirkholz)

---

Top Contributors

[![DennisBirkholz](https://avatars.githubusercontent.com/u/600655?v=4)](https://github.com/DennisBirkholz "DennisBirkholz (49 commits)")[![kevle](https://avatars.githubusercontent.com/u/8260484?v=4)](https://github.com/kevle "kevle (1 commits)")

### Embed Badge

![Health badge](/badges/iqb-gpio/health.svg)

```
[![Health](https://phpackages.com/badges/iqb-gpio/health.svg)](https://phpackages.com/packages/iqb-gpio)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[phpspec/phpspec

Specification-oriented BDD framework for PHP 7.1+

1.9k36.7M3.1k](/packages/phpspec-phpspec)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
