Acheter un Raspberry Pi: http://bit.ly/2eXSxB7
Acheter une carte MicroSD: http://bit.ly/2eJWFnI
Acheter un power supply 5V 2,5A (Amérique): http://bit.ly/2eS93jc
Acheter un power supply 5V 2,5A (Europe): http://bit.ly/2dTt7F2
Bonjour ! Dans cette vidéo je vais vous apprendre à contrôler les GPIO de votre Raspberry Pi à partir d’une page web. J’ai conçu ce tutoriel pour qu’il soit le plus simple possible. Je vais vous montrer comment activer et désactiver un relais connecté à une lumière. On utilisera du HTML, PHP et CSS pour faire ce projet, aucun Javascript requis ! J’espère que vous aimer la vidéo !
Guide complet de la procédure:
Relier le relais au Raspberry Pi et brancher une lumière sur le relais :
Voir mon tutoriel sur le fonctionnement d’un relais : https://www.youtube.com/watch?v=-BFrgrpGyUM
Préparation du Raspberry Pi:
Téléchargez la dernière version de Raspbian (Pixel ou Lite, ça ne dérange pas): https://www.raspberrypi.org/downloads/raspbian/
Téléchargez SDFormater: https://www.sdcard.org/downloads/formatter_4/
Téléchargez Win32 Disk Imager: https://sourceforge.net/projects/win32diskimager/
Téléchargez Putty: http://www.putty.org
Utilisez SDFormater pour formater votre carte MicroSD et transférez l’image Raspbian sur la carte avec l’aide de Win32 Disk Imager.
Une fois la carte MicroSD prête, insérez-la dans le Raspberry Pi. Branchez celui-ci à son alimentation ainsi qu’à votre réseau.
Connectez-vous ensuite au Raspberry Pi en SSH avec Putty.
Mettre à jour la liste de packets du Pi:
sudo apt-get update
sudo apt-get upgrade -y
Installer Apache et PHP:
sudo apt-get install apache2 –y
sudo apt-get install php5 libapache2-mod-php5 -y
Installer WiringPi:


sudo apt-get install git-core
git clone git://git.drogon.net/wiringPi
cd wiringPi
sudo git pull origin
cd wiringPi
./build
cd
sudo rm –rf wiringPi
Tester WiringPi:
gpio -v
gpio readall
Rendez-vous au dossier racine du serveur Apache:
cd /var/www/html
Supprimez index.html:
sudo rm -rf index.html
Créez index.php:
sudo nano index.php
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Contrôle GPIO</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<form action="script.php" method="post">
<input type="submit" name="executer" value="ON" class="button" id="ON">
<br/>
<input type="submit" name="executer" value="OFF" class="button" id="OFF">
</form>
</body>
</html>
Créez stylesheet.css:
sudo nano stylesheet.css
html, body
{
margin: 0;
}
.button
{
border: none;
color: white;
text-align: center;
font-size: 10em;
padding: 25px 25px;
cursor: pointer;
width: 100%;
height: 50vh;
}
#ON
{
background-color: green;
}
#OFF
{
background-color: red;
}
Créez script.php:
sudo nano script.php
<?php
system("gpio -g mode 4 out");
if($_POST['executer'] == 'ON')
{
system("gpio -g write 4 1");
}
else
{
system("gpio -g write 4 0");
}
header('Location: index.php');
?>
C’est déjà terminé !
Ouvrez votre navigateur web et connectez-vous à l’adresse IP de votre Raspberry Pi. Les deux boutons devraient apparaitre et vous devriez maintenant pouvoir faire allumer ou éteindre votre lumière !
