Вы находитесь на странице: 1из 8

19/06/2018 Tutoriel: Contrôle des GPIO du Raspberry Pi à partir d'une page Web - TD72PRO

TD72PRO
Menu 

Tutoriel: Contrôle des GPIO du


Raspberry Pi à partir d’une page Web

https://td72pro.com/tutoriel-controle-des-gpio-du-raspberry-pi-a-partir-dune-page-web/ 1/8
19/06/2018 Tutoriel: Contrôle des GPIO du Raspberry Pi à partir d'une page Web - TD72PRO

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 :

https://td72pro.com/tutoriel-controle-des-gpio-du-raspberry-pi-a-partir-dune-page-web/ 2/8
19/06/2018 Tutoriel: Contrôle des GPIO du Raspberry Pi à partir d'une page Web - TD72PRO

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:

https://td72pro.com/tutoriel-controle-des-gpio-du-raspberry-pi-a-partir-dune-page-web/ 3/8
19/06/2018 Tutoriel: Contrôle des GPIO du Raspberry Pi à partir d'une page Web - TD72PRO

http://wiringpi.com/

http://wiringpi.com/

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:
https://td72pro.com/tutoriel-controle-des-gpio-du-raspberry-pi-a-partir-dune-page-web/ 4/8
19/06/2018 Tutoriel: Contrôle des GPIO du Raspberry Pi à partir d'une page Web - TD72PRO

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

1. <!doctype html>
2. <html lang="fr">
3. <head>
4.
5. <meta charset="utf-8">
6. <title>Contrôle GPIO</title>
7.
8. <link rel="stylesheet" type="text/css"
href="stylesheet.css">
9.
10. </head>
11. <body>
12.
13. <form action="script.php" method="post">
14. <input type="submit" name="executer" value="ON"
class="button" id="ON">
15. <br/>
16. <input type="submit" name="executer" value="OFF"
class="button" id="OFF">
17. </form>
18.
19. </body>
20. </html>

Créez stylesheet.css:

https://td72pro.com/tutoriel-controle-des-gpio-du-raspberry-pi-a-partir-dune-page-web/ 5/8
19/06/2018 Tutoriel: Contrôle des GPIO du Raspberry Pi à partir d'une page Web - TD72PRO

sudo nano stylesheet.css

1. html, body
2. {
3. margin: 0;
4. }
5.
6. .button
7. {
8. border: none;
9. color: white;
10. text-align: center;
11. font-size: 10em;
12. padding: 25px 25px;
13. cursor: pointer;
14. width: 100%;
15. height: 50vh;
16. }
17.
18. #ON
19. {
20. background-color: green;
21. }
22.
23. #OFF
24. {
25. background-color: red;
26.
27. }

Créez script.php:

sudo nano script.php

1. <?php
2.
3. system("gpio -g mode 4 out");
4.
5. if($_POST['executer'] == 'ON')
6. {
7. system("gpio -g write 4 1");
8. }
9. else
10. {
11. system("gpio -g write 4 0");
12. }
https://td72pro.com/tutoriel-controle-des-gpio-du-raspberry-pi-a-partir-dune-page-web/ 6/8
19/06/2018 Tutoriel: Contrôle des GPIO du Raspberry Pi à partir d'une page Web - TD72PRO

13.
14. header('Location: index.php');
15.
16. ?>

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 !

Bravo, vous avez réussi !

N’hésitez pas à partager ce tutoriel s’il vous a aidé

  

Articles récents

Parlons système de filtration et évacuation d’air pour imprimante 3D

https://td72pro.com/tutoriel-controle-des-gpio-du-raspberry-pi-a-partir-dune-page-web/ 7/8
19/06/2018 Tutoriel: Contrôle des GPIO du Raspberry Pi à partir d'une page Web - TD72PRO

Caisson pour imprimante 3D: Pourquoi et comment ?

Comment bien entreposer et restaurer son filament pour imprimante 3D ?

Tommy Desrochers 2018

YouTube Facebook Twitter Google+ Instagram

https://td72pro.com/tutoriel-controle-des-gpio-du-raspberry-pi-a-partir-dune-page-web/ 8/8

Вам также может понравиться