PiPHP / GPIO

A PHP library for accessing the GPIO pins on a Raspberry Pi.
MIT License
431 stars 42 forks source link

Installation guide insufficient #41

Closed OZ1SEJ closed 2 years ago

OZ1SEJ commented 4 years ago

I installed via composer:

$ php composer.phar require piphp/gpio
Using version ^0.4.0 for piphp/gpio
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing piphp/gpio (0.4.0): Downloading (100%)         
Writing lock file
Generating autoload files

And then using this code in /var/www/html/index.php

use PiPHP\GPIO\GPIO;
use PiPHP\GPIO\Pin\PinInterface;

// Create a GPIO object
$gpio = new GPIO();

// Retrieve pin 18 and configure it as an output pin
$pin = $gpio->getOutputPin(4);

// Set the value of the pin high (turn it on)
$pin->setValue(PinInterface::VALUE_HIGH);

Results in

Fatal error: Uncaught Error: Class 'PiPHP\GPIO\GPIO' not found in /var/www/html/index.php:13 Stack trace: #0 {main} thrown in /var/www/html/index.php on line 13
samwilson commented 3 years ago

You need to include the Composer autoloader:

require __DIR__.'/vendor/autoload.php';
paulisidore commented 2 years ago

Hello, please add information that the apache2 user must be added to the gpio group if we want to deal with the web browser and that it is also necessary to restart raspiberry pi before using the library.

I was stuck on this point and finding the solution took a very long time (5 hours!!!). Thanks for the work and keep it up

OZ1SEJ commented 2 years ago

This seems to solve the problem - closing.