fbpx

Install WiringPi and controlling raspberrypi gpio pins with php

Install WiringPi and controlling raspberrypi gpio pins with php

WiringPi is a GPIO access library written in C for the BCM2835 used in the Raspberry Pi.
How to download wiring pi?
If you do not have GIT installed, then under any of the Debian releases (e.g. Raspbian), you can install it with:

sudo apt-get install git-core

To obtain WiringPi using GIT

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

If you have already used the clone operation for the first time, then

cd wiringPi
git pull origin

To build/install there is a new simplified script:

cd wiringPi
./build

Get version info of wiring pi

gpio -v

 
Before you get started you should now how & what pins do. Read details on “Special Pin Functions
If you are new to raspberry Pi. You can follow the guide “How to blink a led“.
 
Read value of wiring pi socket number.

gpio read 1

Read value of raspberry pi socket number.

gpio -g read 1

Change mode of a pin to “up”

gpio -g mode 18 up

Change mode of a pin to “down”

gpio -g mode 18 down

 
Write value of wiring pi socket number.

gpio write 29 1

Get the detailed stats of gpio pins

gpio readall

According to it, configure GPIO18 (WiringPi Pin 1) in HW PWM Mode using the command shell:

gpio mode 1 pwm

 
Write a value to the PWM module (from 1 to 1023):

gpio pwm 1 500

 
To remove the configuration of the pin, use:

gpio unexport 1

 
To remove all configurations:

gpio unexportall

 
How to run gpio commands via php

<?php
system ( "gpio mode 0 out" );
system ( "gpio write 0 1" );
exec ( "gpio read 0", $status );
print_r ( $status );
?>

 
You can see the Wiring Pi Chart
 

wiringPi
Pin
BCM
GPIO
NameHeaderNameBCM
GPIO
wiringPi
Pin
3.3v1 | 25v
8R1:0/R2:2SDA3 | 45v
9R1:1/R2:3SCL5 | 60v
74GPIO77 | 8TxD1415
0v9 | 10RxD1516
017GPIO011 | 12GPIO1181
2R1:21/R2:27GPIO213 | 140v
322GPIO315 | 16GPIO4234
3.3v17 | 18GPIO5245
1210MOSI19 | 200v
139MISO21 | 22GPIO6256
1411SCLK23 | 24CE0810
0v25 | 26CE1711
wiringPi
Pin
BCM
GPIO
NameHeaderNameBCM
GPIO
wiringPi
Pin

 

  • Board Revisions: Please note the differences between board revisions 1 and 2 (R1 and R2 above)

P5: The auxiliary GPIO connector present on Rev. 2 boards only:
 

wiringPi PinBCM GPIONameHeaderNameBCM GPIOwiringPi Pin
5v1 | 23.3v
1728GPIO83 | 4GPIO92918
1930GPIO105 | 6GPIO113120
0v7 | 80v
wiringPi
Pin
BCM
GPIO
NameHeaderNameBCM
GPIO
wiringPi
Pin

Share this post