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
Name Header Name BCM
GPIO
wiringPi
Pin
3.3v 1 | 2 5v
8 R1:0/R2:2 SDA 3 | 4 5v
9 R1:1/R2:3 SCL 5 | 6 0v
7 4 GPIO7 7 | 8 TxD 14 15
0v 9 | 10 RxD 15 16
0 17 GPIO0 11 | 12 GPIO1 18 1
2 R1:21/R2:27 GPIO2 13 | 14 0v
3 22 GPIO3 15 | 16 GPIO4 23 4
3.3v 17 | 18 GPIO5 24 5
12 10 MOSI 19 | 20 0v
13 9 MISO 21 | 22 GPIO6 25 6
14 11 SCLK 23 | 24 CE0 8 10
0v 25 | 26 CE1 7 11
wiringPi
Pin
BCM
GPIO
Name Header Name BCM
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 Pin BCM GPIO Name Header Name BCM GPIO wiringPi Pin
5v 1 | 2 3.3v
17 28 GPIO8 3 | 4 GPIO9 29 18
19 30 GPIO10 5 | 6 GPIO11 31 20
0v 7 | 8 0v
wiringPi
Pin
BCM
GPIO
Name Header Name BCM
GPIO
wiringPi
Pin

Share this post