tasoft / php-spi-extension
A simple SPI extension for PHP to read from and write to the spi bus.
Installs: 6
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Language:C
Requires
- php: >=7.2
This package is auto-updated.
Last update: 2025-01-29 07:08:40 UTC
README
I've created this extension to get access to the spi bus on my raspberry pi.
Installation
$ cd ~
$ git clone https://github.com/tasoftch/php-spi-extension.git
$ cd php-spi-extension
$ phpize
$ ./configure --enable-php-spi
$ make
$ sudo make install
This compiles the source on your machine.
Next find the php.ini file
$ php --ini
Will list scanned ini files.
Add the following line to that php.ini file:
extension=php_spi
<?php var_dump( extension_loaded('php_spi') ); // Should be true
Usage
The extension adds the following functions to the global scope:
spi_open
This opens the device bus.spi_read
Reads data from the spi bus.spi_write
Writes data to the spi busspi_transfer
Reads and writes data to and from the spi bus in duplex modespi_close
Closes the bus.spi_get_mode
Reads the modespi_get_speed
Reads the maximum speedspi_get_bits_per_word
Reads bits per wordspi_get_delay
Reads the delay
Example
<?php use TASoft\Bus\SPI; $dev = new SPI(0); // /dev/spidev0.0 $backData = $dev->transfer([0x0, 0xFF]); print_r($backData); ?>