Cannon Moyer
Cannon Moyer

Reputation: 99

PHP - Write to GPIO Rapberry Pi

I am trying to write to the GPIO pins in php. I do not want to use a library to do so unless it is necessary. I have been able to do these operations in the cmd line, but I don't know how to pull off the correct operations in php with the system function and not get the permission denied error. Can someone please show me how this is done and explain the code please? I am new to Raspberry Pi so please keep that in mind.

Upvotes: 0

Views: 362

Answers (1)

Twisty
Twisty

Reputation: 30893

Appears if you perform your script with sudo or adjust the permissions, you can perform the following:

file_put_contents('/sys/class/gpio/gpio'.$pinNo.'/value', $value);

This Guide seems very helpful:

http://www.xodustech.com/guides/raspberry-pi-php-gpio

Upvotes: 1

Related Questions