PHPackages                             microscrap/i2c - 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/i2c

ActiveLibrary[Framework](/categories/framework)

microscrap/i2c
==============

Unix libi2c 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/i2c)[ Packagist](https://packagist.org/packages/microscrap/i2c)[ Docs](https://dosr.projectsaturnstudios.com)[ RSS](/packages/microscrap-i2c/feed)WikiDiscussions main Synced 1w ago

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

microscrap/i2c — Linux I²C / SMBus bindings for ScrapyardIO
===========================================================

[](#microscrapi2c--linux-ic--smbus-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\I2C`.

This project provides PHP bindings to the Linux i2c-dev character device API, mirroring the public surface of the userspace [`i2c-tools`](https://git.kernel.org/pub/scm/utils/i2c-tools/i2c-tools.git/) / `` family.

Highlights
----------

[](#highlights)

- Open an I²C bus (`/dev/i2c-0`, `/dev/i2c-1`, etc.) and bind it to a slave address in one call
- Raw byte-stream I/O via `i2c_read` / `i2c_write`
- Configure the kernel adapter — slave address, 10-bit addressing, PEC, retries, timeout
- Query controller capabilities through the `I2CFuncFlag` bitmask (`I2C_FUNCS` ioctl)
- SMBus convenience helpers: quick, byte, byte-data, word-data, and block transfers
- `I2C_RDWR` combined transactions — chain multiple read/write messages with repeated-START in a single ioctl
- Thin global `i2c_*` helper API — all functions are `function_exists`-guarded

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

[](#requirements)

- PHP 8.3+
- Linux kernel with `i2c-dev` (`modprobe i2c-dev`) and a populated `/dev/i2c-N` device
- **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
```

Confirm the bus is visible (and that your user is in the `i2c` group, or run as root):

```
ls /dev/i2c-*
i2cdetect -y 1
```

```
composer require microscrap/i2c
```

Composer autoloads `src/Helpers/i2c-bus.php` and `src/Helpers/i2c-smbus.php`, registering the global `i2c_*` functions.

Usage
-----

[](#usage)

I²C transactions are driven through **global helper functions** (`i2c_open`, `i2c_read`, `i2c_write`, `i2c_smbus_*`, `i2c_rdwr`, etc.). All helpers delegate to the `Bus` facade and are only defined once (`function_exists` guard).

Enums live under `Microscrap\Bindings\I2C\Enums`. The bus handle is `Microscrap\Bindings\I2C\DataObjects\I2CBus`.

---

### Example — read temperature and humidity from an AHT20

[](#example--read-temperature-and-humidity-from-an-aht20)

```
