PHPackages                             microscrap/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. [Framework](/categories/framework)
4. /
5. microscrap/gpio

ActiveLibrary[Framework](/categories/framework)

microscrap/gpio
===============

Unix gpiod Bindings for The PHP Posi Extension

0.4.0(2w ago)02↓100%MITPHPPHP ^8.3

Since May 25Pushed 2w agoCompare

[ Source](https://github.com/microscrap/gpio)[ Packagist](https://packagist.org/packages/microscrap/gpio)[ Docs](https://dosr.projectsaturnstudios.com)[ RSS](/packages/microscrap-gpio/feed)WikiDiscussions main Synced 1w ago

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

microscrap/gpio — Linux GPIO bindings for ScrapyardIO
=====================================================

[](#microscrapgpio--linux-gpio-bindings-for-scrapyardio)

PHP library that wraps the [**posi**](https://github.com/php-io-extensions/posi) extension with global helpers, enums, and data objects. Every helper delegates to a facade class under `Microscrap\Bindings\GPIO`.

This project provides PHP bindings to the Linux GPIO character device API (GPIO uAPI v2), mirroring the public surface of [libgpiod v2](https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/).

Highlights
----------

[](#highlights)

- Open and interrogate GPIO chips (`/dev/gpiochip0`, etc.)
- Snapshot any line's metadata — name, direction, bias, drive, edge, debounce
- Request exclusive ownership of one or more lines in a single ioctl
- Read and write line values individually or in bulk
- Watch for line-configuration changes on the chip file descriptor
- Stream rising/falling edge events with nanosecond-precision kernel timestamps
- Full libgpiod-compatible helper API (`gpiod_chip_open`, `gpiod_line_request_set_value`, etc.)

Requirements
------------

[](#requirements)

- PHP 8.3+
- Linux kernel 5.10+ (GPIO uAPI v2)
- **ext-posi** ^0.4.0 — install from [php-io-extensions/posi](https://github.com/php-io-extensions/posi)
- **microscrap/posix** ^0.4.0

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

[](#installation)

Confirm **ext-posi** is loaded:

```
php -m | grep posi
```

```
composer require microscrap/gpio
```

Composer autoloads all helper files in `src/Helpers/`, registering global `gpiod_*` functions when the package is installed.

Usage
-----

[](#usage)

GPIO is controlled through **global helper functions** named after their libgpiod counterparts (`gpiod_chip_open`, `gpiod_line_request_set_value`, etc.). Helpers are only defined if the name is not already taken (`function_exists` guard).

Enums live under `Microscrap\Bindings\GPIO\Enums`. Data objects live under `Microscrap\Bindings\GPIO\DataObjects`.

**Example — blink an LED on GPIO 17, read a button on GPIO 27**

```
