Download the PHP package tasoft/php-i2c-extension without Composer
On this page you can find all versions of the php package tasoft/php-i2c-extension. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tasoft/php-i2c-extension
More information about tasoft/php-i2c-extension
Files in tasoft/php-i2c-extension
Package php-i2c-extension
Short Description A simple I2C extension for PHP to read from and write to i2c bus.
License MIT
Informations about the package php-i2c-extension
The PHP i2c Extension
I've created this extension to get access to the i2c bus on my raspberry pi.
Prerequisites
- The development module for your version of PHP, i.e, php7.4-dev, php8.2-dev.
Installation
Change the configure file on line 5 (php-config7.4), to match your installed version of PHP. Then, run the following commands to install the extension.
Next, find the location of PHP's INI files on your computer by running the following command.
Note: If you're using Microsoft Windows, then run php --ini
and look for the value of "Configuration File (php.ini) Path:".
You should see a directory path such as /etc/php/7.4/cli. In that directory, create a new INI file named 20-i2c.ini with the following contents
Then, with the file created, test that the I2C extension is loaded by running the following command:
You should see the following output:
Usage
The extension adds five function to the global scope:
-
This opens the device bus.
-
This selects an address of a connected chip.
-
Reads data from the i2c bus.
-
Writes data to the i2c bus
-
Closes the bus.
Example
I've tested with a Raspberry Pi Model B 3+ and the Adafruit ADS1115 analog to digital converter. It's default i2c address is 0x48.
Usage PHP
The package also contains a php wrapper class for i2c.
Please note that the composer installation does not compile the extension! For compilation use the installation guide described before.
Now the same example can be rewritten as: