2017 © Pedro Peláez
 

library raspio

Raspberry Pi GPIO/Peripheral Library

image

noccylabs/raspio

Raspberry Pi GPIO/Peripheral Library

  • Wednesday, January 22, 2014
  • by noccy80
  • Repository
  • 2 Watchers
  • 1 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

RaspIo

Installing

Install using composer:, (*1)

composer require "noccylabs/raspio:dev-master"

Or by cloning the github repository:, (*2)

git clone git@github.com:noccylabs/php-raspio

Note that composer will take care of the autoloading; if you clone the repository you have to take care of that yourself., (*3)

Getting Started

On a Raspberry Pi, just call on RaspberryPi::getInstance() to get an instance of the board driver., (*4)

use RaspIo\RaspberryPi;

// Get an instance of the Pi
$pi = RaspberryPi::getInstance();

getInstance() will find the first registered board driver that doesn't throw an exception, make sure it's an instance of RaspIo\RaspberryPi, and then use that for subsequent calls to getInstance()., (*5)

Devices are registered in the board driver constructor or in device drivers with a call to the registerDevice($id,$device) method. This makes them available via their respective properties as well as the getDevice() method., (*6)

// Like this
$gpio = $pi->gpio;
// Or this
$gpio = $pi->getDevice("gpio");

Devices can also be aliased, by calling registerAlias($alias,$id). This is used to define the default devices when more than one of the device type may be available on the board., (*7)

You can get the info on the board detected by calling getVersion():, (*8)

printf("Board: %s\n", $pi->getVersion());

Devices can also be iterated over, or accessed via getRegisteredDevices() (and getRegisteredAliases())., (*9)

printf("Devices:\n");
foreach($pi as $device=>$obj) {
    printf("  %s => %s\n", $device, get_class($obj));
}

printf("Aliases:\n");
foreach($pi->getRegisteredAliases() as $alias=>$device) {
    printf("  %s -> %s\n", $alias, $device);
}

...on any other platform

If you will be using or testing cose using RaspIo on a platform that is not supported, you can enable emulation., (*10)

use RaspIo\RaspberryPi;

// Add the emulated rev2 board. This must be done before the first
// call to RaspberryPi::getInstance()
RaspberryPi::addBoardDriver("RaspIo\\Board\\EmulatedRev2Board");
// Get an instance of the Pi
$pi = RaspberryPi::getInstance();

Using the devices

GPIO

The GPIO is available with the device id gpio, and it should be a class implementing the interface RaspIo\Device\Gpio\IGpioMapper. It is normally an instance of RaspIo\Device\Gpio\GpioMapper., (*11)

// Get Pi instance
$pi = RaspberryPi::getInstance();

// Export and set direction
$pin = $pi->gpio->export(0)->setDirection("out");

// Write to the pin
$pin->setValue(1);

Available methods are defined in RaspIo\Device\Gpio\IGpioExport:, (*12)

  • setDirection($dir) and getDirection() to set the gpio direction to one of in or out.
  • setValue($val) and getValue() to set the gpio value to either 1 or 0.

To unexport a pin, call on unexport() on the GpioMapper:, (*13)

// Unexport the pin
$pi->gpio->unexport(0);

UART

UART support is not yet implemented., (*14)

Dummy Devices

Dummy devices are placeholders for not yet implemented devices., (*15)

The Versions

22/01 2014

dev-master

9999999-dev

Raspberry Pi GPIO/Peripheral Library

  Sources   Download

GPL-2.0+

by NoccyLabs

21/01 2014

0.1.1

0.1.1.0

Raspberry Pi GPIO/Peripheral Library

  Sources   Download

GPL-2.0+

by NoccyLabs

20/01 2014

0.1.0

0.1.0.0

Raspberry Pi GPIO/Peripheral Library

  Sources   Download

GPL-2.0+

by NoccyLabs