dev-master
9999999-dev http://github.com/peec/raspberry-piface-apiLets you control your PiFace for Raspberry PI with PHP.
MIT
The Requires
- php >=5.4.0
Wallogit.com
2017 © Pedro Peláez
Lets you control your PiFace for Raspberry PI with PHP.
I ported the original Python library to PHP. This library works almost the same as the python library., (*2)
Don't worry, follow the guides below to get started:, (*3)
Few things you need to install your environment, here is some instructions., (*4)
# Install php + git sudo apt-get install php5 php5-dev php5-cli git # Install php SPI git clone git://github.com/frak/php_spi.git ~/php_spi cd ~/php_spi phpize ./configure --enable-spi make make test sudo make install
Install with Composer:, (*5)
Here is some commands to your new project in ~/myphpiface (in your home directory):, (*6)
mkdir ~/myphpiface
cd ~/myphpiface
touch ~/myphpiface/composer.json
echo '{ "require": { "pkj/raspberry-piface-api": "dev-master" } }' >> ~/myphpiface/composer.json
curl -sS https://getcomposer.org/installer | php
php composer.phar install
This will create a vendor directory where the library is installed., (*7)
Create a PHP script named test_piface.php (We assume that you place test_piface.php where composer.json file is.) and paste this in the file:, (*8)
use Pkj\Raspberry\PiFace\PiFaceDigital;
dl("spi.so"); // Load the SPI extension.
require 'vendor/autoload.php';
$dev = PiFaceDigital::create();
// Run once.
$dev->init();
$dev->getLeds()[0]->turnOn();
sleep(2);
$dev->getLeds()[0]->turnOff();
// $dev->getInputPins();
// $dev->getOutputPins();
// $dev->getLeds();
// $dev->getRelays();
// $dev->getSwitches();
// Turn on relay 0
$dev->getRelays()[0]->turnOn();
// Get 0/1 of input pin 3 (There are 8 pins, 0-7)
$dev->getInputPins()[3]->getValue();
// Toggle a value on a output pin (5 in this example)
$dev->getOutputPins()[5]->toggle(); // 0
$dev->getOutputPins()[5]->toggle(); // 1
$dev->getOutputPins()[5]->toggle(); // 0
And test:, (*9)
php -f test_piface.php
Lets you control your PiFace for Raspberry PI with PHP.
MIT