PHP Classes
elePHPant
Icontem

iWire PHP Raspberry PI GPIO Class: Control a Raspberry PI board using GPIO

Recommend this page to a friend!
  Info   View files Example   View files View files (71)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-04-30 (4 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 147 This week: 1All time: 8,604 This week: 468Up
Version License PHP version Categories
phpiwire 1.0.0Free For Educatio...5Hardware, Zephir
Description Author

This package can control a Raspberry PI board using GPIO.

It is a PHP extension written in Zephir that interfaces with wiringPi to control a Raspberry Pi's GPIO and access values from pins of a board.

The package is able to read or write data from any pin available in each of the supported boards.

Innovation Award
PHP Programming Innovation award nominee
May 2018
Number 3
Raspberry PI is popular platform for tiny computer boards that can be purchased at a low cost and can run many types of software runs on a Linux based OS, including PHP.

This package is a PHP extension written in Zephir that can run on a Raspberry PI board to access values of pins that may be connected to external sensors.

Manuel Lemos
  Performance   Level  
Name: Andrew Collington <contact>
Classes: 15 packages by
Country: United Kingdom United Kingdom
Innovation award
Innovation award
Nominee: 2x

Details

PHPiWire

A wrapper for wiringPi written in Zephir so that is can be compiled as an extension for PHP.

Flattr this git repo

Requirements

This extension and the wiringPi library are intended to run on a RaspberryPi, so having a RaspberryPi is kind of a big requirement here! You also need to have Git installed, the wiringPi library, various build tools and the php development headers.

Installing Git

sudo apt-get update
sudo apt-get install git

Installing wiringPi

git clone git://git.drogon.net/wiringPi
cd wiringPi
./build

If all goes well you should be able to run the gpio utility:

gpio -v

Full instructions for installing wiringPi.

Installing zephir

sudo apt-get install gcc make re2c php5 php5-json php5-dev libpcre3-dev
git clone https://github.com/phalcon/zephir
cd zephir
./install-json
./install -c

If all goes well you should be able to get the help info for zephir:

zephir help

Full instructions for installing zephir.

Building the extension

git clone https://github.com/amnuts/phpiwire
cd phpiwire
zephir build

That will build and install the extension. You'll then have to add the extension to your php.ini file. You may find that you have two php.ini files, one for cli and one for web, so remember to add the extension to both. You'll want to add the line:

extension=phpiwire.so

Once this is done (and the web server restarted if you're adding the extension for web use and not just cli) you should be able to see the extension info when using the `phpinfo()` method or via the command line `php -i`.

Example

Here's a very simple example of how to make an LED attached to pin 0 (using the wiringPi pin numbering scheme, BCM_GPIO pin 17) blink on and off.

Assuming the LED is attached as shown:

Overview

<?php

namespace Phpiwire;

set_time_limit(0);

echo "Raspberry Pi blink\n";

$pi = new Board();
$p = $pi->getPin(0)->mode(Pin::OUTPUT);

while (true) {
    $p->write(Pin::HIGH);
    sleep(1);
    $p->write(Pin::LOW);
    sleep(1);
}

And to run it you'll need to be running as root:

sudo php blink.php

Releases

Releases of the extension are available at:

https://github.com/amnuts/phpiwire/releases/

License

MIT: http://acollington.mit-license.org/

  Files folder image Files  
File Role Description
Files folder imageexample (7 files, 1 directory)
Files folder imageext (1 directory)
Files folder imagephpiwire (2 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file config.json Data Auxiliary data
Plain text file phpstorm-stub.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  example  
File Role Description
Files folder imageajax-example (4 files)
  Accessible without login Plain text file blink.php Example Example script
  Accessible without login Plain text file board.php Example Example script
  Accessible without login Plain text file pin.php Example Example script
  Accessible without login Plain text file pulse.php Example Example script
  Accessible without login Plain text file reset.php Example Example script
  Accessible without login Plain text file rgbled.php Example Example script
  Accessible without login Plain text file softpwm.php Example Example script

  Files folder image Files  /  example  /  ajax-example  
File Role Description
  Accessible without login Plain text file control.php Aux. Auxiliary script
  Accessible without login HTML file index.html Doc. Documentation
  Accessible without login Plain text file _reset.php Example Example script
  Accessible without login Plain text file _set.php Example Example script

  Files folder image Files  /  ext  
File Role Description
Files folder imagekernel (50 files, 1 directory)

  Files folder image Files  /  ext  /  kernel  
File Role Description
Files folder imageextended (4 files)
  Accessible without login Plain text file array.c Data Auxiliary data
  Accessible without login Plain text file array.h Data Auxiliary data
  Accessible without login Plain text file assert.c Data Auxiliary data
  Accessible without login Plain text file assert.h Data Auxiliary data
  Accessible without login Plain text file backtrace.c Data Auxiliary data
  Accessible without login Plain text file backtrace.h Data Auxiliary data
  Accessible without login Plain text file concat.c Data Auxiliary data
  Accessible without login Plain text file concat.h Data Auxiliary data
  Accessible without login Plain text file debug.c Data Auxiliary data
  Accessible without login Plain text file debug.h Data Auxiliary data
  Accessible without login Plain text file exception.c Data Auxiliary data
  Accessible without login Plain text file exception.h Data Auxiliary data
  Accessible without login Plain text file exit.c Data Auxiliary data
  Accessible without login Plain text file exit.h Data Auxiliary data
  Accessible without login Plain text file fcall.c Data Auxiliary data
  Accessible without login Plain text file fcall.h Data Auxiliary data
  Accessible without login Plain text file file.c Data Auxiliary data
  Accessible without login Plain text file file.h Data Auxiliary data
  Accessible without login Plain text file filter.c Data Auxiliary data
  Accessible without login Plain text file filter.h Data Auxiliary data
  Accessible without login Plain text file globals.h Data Auxiliary data
  Accessible without login Plain text file hash.c Data Auxiliary data
  Accessible without login Plain text file hash.h Data Auxiliary data
  Accessible without login Plain text file iterator.c Data Auxiliary data
  Accessible without login Plain text file iterator.h Data Auxiliary data
  Accessible without login Plain text file main.c Data Auxiliary data
  Accessible without login Plain text file main.h Data Auxiliary data
  Accessible without login Plain text file math.c Data Auxiliary data
  Accessible without login Plain text file math.h Data Auxiliary data
  Accessible without login Plain text file memory.c Data Auxiliary data
  Accessible without login Plain text file memory.h Data Auxiliary data
  Accessible without login Plain text file object.c Data Auxiliary data
  Accessible without login Plain text file object.h Data Auxiliary data
  Accessible without login Plain text file operators.c Data Auxiliary data
  Accessible without login Plain text file operators.h Data Auxiliary data
  Accessible without login Plain text file output.c Data Auxiliary data
  Accessible without login Plain text file output.h Data Auxiliary data
  Accessible without login Plain text file persistent.c Data Auxiliary data
  Accessible without login Plain text file persistent.h Data Auxiliary data
  Accessible without login Plain text file README.md Doc. Documentation
  Accessible without login Plain text file require.c Data Auxiliary data
  Accessible without login Plain text file require.h Data Auxiliary data
  Accessible without login Plain text file session.c Data Auxiliary data
  Accessible without login Plain text file session.h Data Auxiliary data
  Accessible without login Plain text file string.c Data Auxiliary data
  Accessible without login Plain text file string.h Data Auxiliary data
  Accessible without login Plain text file time.c Data Auxiliary data
  Accessible without login Plain text file time.h Data Auxiliary data
  Accessible without login Plain text file variables.c Data Auxiliary data
  Accessible without login Plain text file variables.h Data Auxiliary data

  Files folder image Files  /  ext  /  kernel  /  extended  
File Role Description
  Accessible without login Plain text file array.c Data Auxiliary data
  Accessible without login Plain text file array.h Data Auxiliary data
  Accessible without login Plain text file fcall.c Data Auxiliary data
  Accessible without login Plain text file fcall.h Data Auxiliary data

  Files folder image Files  /  phpiwire  
File Role Description
  Plain text file Board.zep Class Class source
  Plain text file Pin.zep Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:147
This week:1
All time:8,604
This week:468Up