2017 © Pedro Peláez
 

library raspberry-piface-api

Lets you control your PiFace for Raspberry PI with PHP.

image

pkj/raspberry-piface-api

Lets you control your PiFace for Raspberry PI with PHP.

  • Tuesday, October 1, 2013
  • by peec
  • Repository
  • 1 Watchers
  • 12 Stars
  • 570 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 1 Versions
  • 1 % Grown

The README.md

Build Status, (*1)

Raspberry PI - PiFace API for PHP 5.4+

I ported the original Python library to PHP. This library works almost the same as the python library., (*2)

Requirements

  • Hardware: Raspberry PI and PiFace module.
  • PHP 5.4+ installed
  • You also need to add the php SPI extension, compile it and configure, see: https://github.com/frak/php_spi
  • Apache if you want to run commands from web scripts.

Don't worry, follow the guides below to get started:, (*3)

Setting up the environment

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

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)

Usage:

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

The Versions

01/10 2013

dev-master

9999999-dev http://github.com/peec/raspberry-piface-api

Lets you control your PiFace for Raspberry PI with PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0