PHPackages                             remithefox/php-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. remithefox/php-gpio

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

remithefox/php-gpio
===================

PHP library to operate with Raspberry Pi's GPIO.

1.0.0(6y ago)131PHP

Since Oct 11Pushed 6y agoCompare

[ Source](https://github.com/remithefox/php-gpio)[ Packagist](https://packagist.org/packages/remithefox/php-gpio)[ RSS](/packages/remithefox-php-gpio/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

remithefox/php-gpio
===================

[](#remithefoxphp-gpio)

PHP library which provide class for GPIO

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

[](#installation)

### Composer

[](#composer)

```
$ composer require remithefox/php-gpio
```

Usage
-----

[](#usage)

At first make sure user has permission to use GPIO. Standard Raspbian configuration users in group GPIO have that permission.

### Pin

[](#pin)

Create `RemiTheFox\PhpGPIO\Pin` object to open GPIO pin.

Constructor parameters:

no.typenamerequireddefaultdescription1integer`$pinNumber`Yes(none)BCM pin number2string`$direction`No`'in'`pin direction `'in'` or `'out'`3bool`$force`No`false`forces when pin is occupied4int`$timeout`No`10000`export timeout in microseconds5bool`$autorelease`No`true`pin will be released after unset or lost the last reference6string`$devicePath`No`'/sys/class/gpio/'`device path (almost sure you should leave it default, it's for testing)Constructor throws:

- [`InvalidDirection`](#InvalidDirection) when direction will be different than `'in'` or `'out'`,
- [`GpioNotFound`](#GpioNotFound) when GPIO is not found in system,
- [`PermissionDenied`](#PermissionDenied) when user does not have permission to use GPIO,
- [`PinOccupied`](#PinOccupied) when chosen pin is occupied (is exported) and `$force` flag is `false`,
- [`ExportTimeout`](#ExportTimeout) when GPIO pin export time limit will be exceeded,
- [`IOError`](#IOError) on any input/output error.

Example:

```
use RemiTheFox\PhpGPIO\Pin;
use RemiTheFox\PhpGPIO\GpioElementInterface;

$pin = new Pin(4, GpioElementInterface::DIRECTION_OUT);
```

#### Reading

[](#reading)

To read pin state use `getValue()` method.

Method `getValue()` can throw:

- [`IOError`](#IOError) on any input/output error.

Method `getValue()` returns `true` for logic high and `false` for logic low.

Example:

```
$input = $pin->getValue();
```

[![](doc/pin_input.gif)](doc/pin_input.gif)

#### Writing

[](#writing)

To write pin state (in output mode) use `setValue()` method.

`setValue()` method parameters:

no.typenamerequireddefaultdescription1bool`$value`Yes(none)new valueMethod `setValue()` throws:

- [`WriteOnInputMode`](#WriteOnInputMode) when trying to write value on GPIO element on input mode,
- [`IOError`](#IOError) on any input/output error.

Method `setValue()` returns `$this`

Example:

```
$pin->setValue(true);
```

[![](doc/pin_output.gif)](doc/pin_output.gif)

#### Changing direction

[](#changing-direction)

To change pin direction use `setDirection()` method.

`setDirection()` method parameters:

no.typenamerequireddefaultdescription1string`$direction`Yes(none)new pin direction `'in'` or `'out'`Method `setDirection()` throws:

- [`InvalidDirection`](#InvalidDirection) when direction will be different than `'in'` or `'out'`.
- [`IOError`](#IOError) on any input/output error.

Method `setDirection()` returns `$this`

Example:

```
$pin->setDirection(GpioElementInterface::DIRECTION_OUT);
```

**Note:** Please be careful with changing directions. If both devices are in output mode at the same time, it can short circuit and cause damages. I highly recommend avoiding direction changes. Otherwise make sure it's not possible for both devices to be in output mode at the same time.

#### Checking direction

[](#checking-direction)

To check pin direction use one of following methods: `getDirection()`, `isInput()`, `isOutput()`

methodtypeinput mode resultoutput mode result`getDirection()``string``'in'``'out'``isInput()``bool``true``false``isOutput()``bool``false``true`### ParallelDataBus

[](#paralleldatabus)

To send data by parallel bus you can use `RemiTheFox\PhpGPIO\ParallelDataBus` object.

Constructor parameters:

no.typenamerequireddefaultdescription1PinInterface\[\]`$pins`Yes(none)Array of pins2string`$direction`No`'in'`pin direction `'in'` or `'out'`Constructor throws:

- [`PinArrayExpected`](#PinArrayExpected) when `ParallelDataBus` gets something other than array of pins in first parameter of constructor,
- [`InvalidDirection`](#InvalidDirection) when direction will be different than `'in'` or `'out'`.
- [`IOError`](#IOError) on any input/output error.

Example:

```
use RemiTheFox\PhpGPIO\ParallelDataBus;
use RemiTheFox\PhpGPIO\Pin;
use RemiTheFox\PhpGPIO\GpioElementInterface;

$pinNumbers = [2, 1, 3, 7];
$pins = [];
foreach ($pinNumbers as $pinNumber) {
    $pins[] = new Pin($pinNumber);
}
$bus = new ParallelDataBus($pins, GpioElementInterface::DIRECTION_IN);
```

Yup it's too long. You can use [factory method](#createParallelDataBus) to make it short.

#### Reading

[](#reading-1)

To read value on bus use `getValue()` method.

Method `getValue()` throws:

- [`IOError`](#IOError) on any input/output error.

Method `getValue()` returns unsigned integer value in range from 0 to 2n-1

Example:

```
$input = $pin->getValue();
```

[![](doc/bus_input.gif)](doc/bus_input.gif)

#### Writing

[](#writing-1)

To write bus value (in output mode) use `setValue()` method.

`setValue()` method parameters:

no.typenamerequireddefaultdescription1int`$value`Yes(none)new value (value should be in range from 0 to 2n-1)Method `setValue()` throws:

- [`WriteOnInputMode`](#WriteOnInputMode) when trying to write value on GPIO element on input mode,
- [`OutOfRange`](#OutOfRange) when trying to write value out of range from 0 to 2n-1,
- [`IOError`](#IOError) on any input/output error.

Method `setValue()` returns `$this`

Example:

```
$pin->setValue(true);
```

[![](doc/bus_output.gif)](doc/bus_output.gif)

#### Changing direction

[](#changing-direction-1)

To change bus direction use `setDirection()` method. This method changes direction of all pins.

`setDirection()` method parameters:

no.typenamerequireddefaultdescription1string`$direction`Yes(none)new pin direction `'in'` or `'out'`Method `setDirection()` throws:

- [`InvalidDirection`](#InvalidDirection) when direction will be different than `'in'` or `'out'`.
- [`IOError`](#IOError) on any input/output error.

Method `setDirection()` returns `$this`

Example:

```
$pin->setDirection(GpioElementInterface::DIRECTION_OUT);
```

**Note:** Please be careful with changing directions. If both devices are in output mode at the same time, it can short circuit and cause damages. I highly recommend avoiding direction changes. Otherwise make sure it's not possible for both devices to be in output mode at the same time.

#### Checking direction

[](#checking-direction-1)

To check pin direction use one of following methods: `getDirection()`, `isInput()`, `isOutput()`

methodtypeinput mode resultoutput mode result`getDirection()``string``'in'``'out'``isInput()``bool``true``false``isOutput()``bool``false``true`### Factory

[](#factory)

#### `createParallelDataBus()`

[](#createparalleldatabus)

To create `ParallelDataBus` in the simpler way, you can use method `Factory::createParallelDataBus()`.

no.typenamerequireddefaultdescription1int\[\]`$pinNumbers`Yes(none)array of BCM pin numbers2string`$direction`No`'in'`pin direction `'in'` or `'out'`3bool`$force`No`false`forces when pin is occupied4int`$timeout`No`10000`export timeout in microseconds5bool`$autorelease`No`true`pin will be released after unset or lost the last reference6string`$devicePath`No`'/sys/class/gpio/'`device path (almost sure you should leave it default, it's for testing)Method `Factory::createParallelDataBus()` throws:

- [`InvalidDirection`](#InvalidDirection) when direction will be different than `'in'` or `'out'`,
- [`GpioNotFound`](#GpioNotFound) when GPIO is not found in system,
- [`PermissionDenied`](#PermissionDenied) when user does not have permission to use GPIO,
- [`PinOccupied`](#PinOccupied) when chosen pin is occupied (is exported) and `$force` flag is `false`,
- [`ExportTimeout`](#ExportTimeout) when GPIO pin export time limit will be exceeded,
- [`IOError`](#IOError) on any input/output error.

Method `Factory::createParallelDataBus()` returns `ParallelDataBus`.

Example:

```
use RemiTheFox\PhpGPIO\Factory as GpioFactory;
use RemiTheFox\PhpGPIO\GpioElementInterface;

$bus = GpioFactory::createParallelDataBus([2, 1, 3, 7], GpioElementInterface::DIRECTION_IN);
```

### Exceptions

[](#exceptions)

All exceptions are in namespace `RemiTheFox\PhpGPIO\Exception` and extends abstract class `RemiTheFox\PhpGPIO\Exception`.

#### ExportTimeout

[](#exporttimeout)

`ExportTimeout` will be thrown when GPIO pin export time limit will be exceeded.

#### GpioNotFound

[](#gpionotfound)

`GpioNotFound` will be thrown when GPIO is not found in system.

#### IOError

[](#ioerror)

`IOError` will be thrown on any input/output error.

#### InvalidDirection

[](#invaliddirection)

`InvalidDirection` will be thrown when direction will be different than `'in'` or `'out'`.

#### OutOfRange

[](#outofrange)

`OutOfRange` will be thrown when trying to write value out of range from 0 to 2n-1 on `ParallelDataBus`.

#### PermissionDenied

[](#permissiondenied)

`PermissionDenied` will be thrown when user does not have permission to use GPIO.

#### PinArrayExpected

[](#pinarrayexpected)

`PinArrayExpected` will be thrown when `ParallelDataBus` gets something other than array of pins in first parameter of constructor.

#### PinOccupied

[](#pinoccupied)

`PinOccupied` will be thrown when chosen pin is occupied (is exported) and `$force` flag is false.

#### WriteOnInputMode

[](#writeoninputmode)

`WriteOnInputMode` will be thrown when trying to write value on GPIO element on input mode.

long text? ASCII-fox

```
 /\-/\
(=^w^=)
 )   (

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2408d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0193368da52007e2a803d8827dd0b584ce1dd93fab2a3805cdc21db817882a6e?d=identicon)[remithefox](/maintainers/remithefox)

---

Top Contributors

[![remithefox](https://avatars.githubusercontent.com/u/46873705?v=4)](https://github.com/remithefox "remithefox (1 commits)")

### Embed Badge

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

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

###  Alternatives

[beechit/news-ttnewsimport

Importer of ext:tt\_news items to ext:news

2012.6k](/packages/beechit-news-ttnewsimport)

PHPackages © 2026

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