You are on page 1of 12

Raspberry Pi - Python

Wiringpi library
# gpio –v
# gpio readall
# gpio –g mode 17 out // -g for interpreting BCM nos
# gpio –g write 17 1
# gpio –g write 17 0
Uninstalling apache2
# which apache2
# sudo service apache2 stop
# sudo apt-get purge apache2 apache2-utils apache2.2-bin
apache2-common
# sudo apt-get autoremove

# which apache2 //conforming the removal

# sudo apt-get purge php libapache2-mod-php


Installing apache2
# sudo apt-get update
# sudo apt-get install apache2 -y

Browse to: http://localhost/

Default webpage:
/var/www/html/index.html
Installing php
# sudo apt-get install php libapache2-mod-php -y

# sudo rm index.html
# sudo leafpad index.php

# sudo visudo
- www-data ALL=NOPASSWD: ALL in sudoers file
# sudo chown -R www-data:www-data /var/www
php examples
<!DOCTYPE html>
<html>
<body>

<?php
echo "My first PHP script!";
?> 

</body>
</html>
php examples
<!DOCTYPE HTML>
<html>  
<body>

<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>
php code for remote led
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>LED Control</title>
</head>
<body> LED Control: <form method="get” action="gpio.php“>
<input type="submit" value="ON" name="on“>
<input type="submit" value="OFF" name="off“>
</form>
<?php
$setmode17 = shell_exec("/usr/bin/gpio -g mode 17 out");
if(isset($_GET['on']))
{
$gpio_on = shell_exec("/usr/bin/gpio -g write 17 1");
echo "LED is on";
}
else if(isset($_GET['off']))
{
$gpio_off = shell_exec("/usr/bin/gpio -g write 17 0");
echo "LED is off";
}
?>
</body>
</html>
5V Relay

•JZC-11F
Lamp interfacing
Assessment
1. Which is not a valid input method in html form____________ .
a)buttonb)text c)radio d)edit

2. GPIO utility command to configure the pin as PWM


a) gpio mode <pin> in b) gpio mode <pin> out
c) gpio mode <pin> pwm d) gpio mode <pin> pwmout
3. Which statement is wrong?
1) exec only returns the last line of the generated output.
2) shell_exec returns the full output of the command.
3) system immediately shows all output.
4) passthru displays ascii data.
• Contact
A.Arul Prabahar,
Asst. Manager,
NTSC, Ekkadu thangal,
Chennai -32.

Mob: 8754871885
E-mail: ntscchennai@gmail.com

You might also like