ENIB 2025 : Godzilla : Différence entre versions
(→Mettre du code Arduino) |
(→fichiers à joindre) |
||
Ligne 25 : | Ligne 25 : | ||
* du papier canson | * du papier canson | ||
− | == | + | ==code Godzilla== |
− | + | ||
Servo monservo4; | Servo monservo4; | ||
− | |||
+ | WiFiServer server(80); | ||
//////////////// | //////////////// | ||
// Godzilla // | // Godzilla // | ||
//////////////// | //////////////// | ||
− | /* | + | /* un programme conçu par Mattéo Le Guen à partir de celui de Julien Rat sous licence CC-By-Sa. |
Ce programme sert à piloter le "Godzilla". | Ce programme sert à piloter le "Godzilla". | ||
− | C'est un robot pédagogique, très peu cher, utilisé par les petits débrouillards */ | + | C'est un robot pédagogique, très peu cher, utilisé par les petits débrouillards*/ |
+ | |||
+ | |||
+ | #include <ESP8266WiFi.h> | ||
− | |||
////////////////////// | ////////////////////// | ||
//Définition du Wifi// | //Définition du Wifi// | ||
////////////////////// | ////////////////////// | ||
− | const char WiFiAPPSK[] = "1234567890"; // | + | const char WiFiAPPSK[] = "1234567890"; //mot de passe |
+ | |||
////////////////////////// | ////////////////////////// | ||
Ligne 49 : | Ligne 52 : | ||
////////////////////////// | ////////////////////////// | ||
− | #include <Servo.h> | + | |
+ | #include <Servo.h> | ||
+ | |||
Servo monservo1; | Servo monservo1; | ||
Ligne 55 : | Ligne 60 : | ||
Servo monservo3; | Servo monservo3; | ||
− | const int led1 = D3; | + | |
− | const int led2 = D4; | + | const int led1 = D3; |
+ | const int led2 = D4; | ||
+ | |||
void setup() | void setup() | ||
{ | { | ||
− | initHardware(); | + | initHardware(); |
− | setupWiFi(); | + | setupWiFi(); |
− | server.begin(); | + | server.begin(); |
− | + | monservo1.attach(5); | |
− | + | monservo2.attach(4); | |
− | monservo1.attach(5); | + | monservo3.attach(12);b |
− | monservo2.attach(4); | ||
− | monservo3.attach(12); | ||
monservo4.attach(15); | monservo4.attach(15); | ||
− | |||
− | |||
monservo1.write(91); | monservo1.write(91); | ||
monservo2.write(93); | monservo2.write(93); | ||
monservo3.write(90); | monservo3.write(90); | ||
monservo4.write(90); | monservo4.write(90); | ||
− | |||
− | |||
pinMode(led1, OUTPUT); | pinMode(led1, OUTPUT); | ||
pinMode(led2, OUTPUT); | pinMode(led2, OUTPUT); | ||
+ | |||
+ | |||
} | } | ||
+ | |||
void loop() | void loop() | ||
{ | { | ||
− | // | + | // Regarder si un client s'est connecté |
WiFiClient client = server.available(); | WiFiClient client = server.available(); | ||
if (!client) { | if (!client) { | ||
− | return; | + | return; |
} | } | ||
− | // | + | |
+ | // Lire la première ligne de la requête | ||
String req = client.readStringUntil('\r'); | String req = client.readStringUntil('\r'); | ||
− | client.flush(); // | + | |
+ | client.flush(); | ||
+ | |||
+ | |||
+ | // Tester la requête pour identifier la consigne | ||
+ | int val = -1; | ||
+ | |||
+ | |||
+ | if (req.indexOf("/stop") != -1) | ||
+ | val = 0; | ||
+ | else if (req.indexOf("/avance") != -1) | ||
+ | val = 2; | ||
+ | else if (req.indexOf("/recule") != -1) | ||
+ | val = 1; | ||
+ | else if (req.indexOf("/gauche") != -1) | ||
+ | val = 3; | ||
+ | else if (req.indexOf("/droite") != -1) | ||
+ | val = 4; | ||
+ | else if (req.indexOf("/allume1") != -1) | ||
+ | val = 5; | ||
+ | else if (req.indexOf("/eteint1") != -1) | ||
+ | val = 6; | ||
+ | else if (req.indexOf("/allume2") != -1) | ||
+ | val = 7; | ||
+ | else if (req.indexOf("/eteint2") != -1) | ||
+ | val = 8; | ||
+ | else if (req.indexOf("/ouvrir") != -1) | ||
+ | val = 9; | ||
+ | else if (req.indexOf("/arret") != -1) | ||
+ | val = 12; | ||
+ | else if (req.indexOf("/fermer") != -1) | ||
+ | val = 11; | ||
+ | |||
− | + | // Prépare la page web de réponse | |
+ | String s = "HTTP/1.1 200 OK\r\n"; | ||
+ | s += "Content-Type: text/html\r\n\r\n"; | ||
+ | s += "<!DOCTYPE HTML>\r\n<html>\r\n"; | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | // Interface web du contrôle du robot | |
− | + | s += "<h1>Controle de Godzilla</h1>"; | |
− | + | s += "<button onclick=\"location.href='/avance';\">Avancer</button>"; | |
− | + | s += "<button onclick=\"location.href='/recule';\">Reculer</button>"; | |
+ | s += "<button onclick=\"location.href='/gauche';\">Gauche</button>"; | ||
+ | s += "<button onclick=\"location.href='/droite';\">Droite</button>"; | ||
+ | s += "<button onclick=\"location.href='/stop';\">Stop</button>"; | ||
+ | s += "<h2>Controle des LEDs bouche</h2>"; | ||
+ | s += "<button onclick=\"location.href='/allume1';\">Allumer Feu </button>"; | ||
+ | s += "<button onclick=\"location.href='/eteint1';\">Eteindre Feu </button>"; | ||
+ | s += "<h3>Controle des LEDs yeux</h3>"; | ||
+ | s += "<button onclick=\"location.href='/allume2';\">Allumer yeux </button>"; | ||
+ | s += "<button onclick=\"location.href='/eteint2';\">Eteindre yeux </button>"; | ||
+ | s += "<h4>Controle de la bouche </h4>"; | ||
+ | s += "<button onclick=\"location.href='/ouvrir';\">ouvrir bouche </button>"; | ||
+ | s += "<button onclick=\"location.href='/arret';\">arret bouche </button>"; | ||
+ | s += "<button onclick=\"location.href='/fermer';\">fermer bouche </button>"; | ||
+ | s += "<style>"; | ||
+ | s += "button { padding: 20px; margin: 15px; font-size: 18px; width: 150px; }"; | ||
+ | s += "body { text-align: center; font-family: Arial; }"; | ||
+ | s += "@media (max-width: 600px) { button { width: 100%; margin: 5px 0; } }"; | ||
+ | s += "</style>"; | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | // | + | // Si on a reçu l’instruction, il faut la l’appliquer au robot |
− | if (val == 2) { s += " avance "; monservo2.write(180); monservo1.write(0); } | + | if (val == 2 ) |
− | if (val == 1) { s += " recule "; monservo2.write(0); monservo1.write(180); } | + | { |
− | if (val == 0) { s += " stop "; monservo1.write(91); monservo2.write(93); } | + | s += " avance "; |
− | if (val == 3) { s += " gauche "; monservo1.write(180); monservo2.write(180); } | + | monservo2.write(180); //avance |
− | if (val == 4) { s += " droite "; monservo1.write(0); monservo2.write(0); } | + | monservo1.write(0); //avance |
− | if (val == 5) { s += " bouche allumee"; digitalWrite(led1, HIGH); } | + | } |
− | if (val == 6) { s += " bouche eteinte"; digitalWrite(led1, LOW); } | + | if (val == 1)//recule |
− | if (val == 7) { s += " yeux allume"; digitalWrite(led2, HIGH); } | + | { |
− | if (val == 8) { s += " yeux eteint"; digitalWrite(led2, LOW); } | + | s += " recule "; |
− | if (val == 9) { s += " bouche ouverte"; monservo3.write(180); monservo4.write(0); } | + | monservo2.write(0); //recule |
− | if (val == 12) { s += " arret bouche "; monservo3.write(90); monservo4.write(90); } | + | monservo1.write(180); //recule |
− | if (val == 11) { s += " bouche fermee"; monservo3.write(0); monservo4.write(180); | + | } |
− | + | if (val == 0) | |
+ | { | ||
+ | s += " stop "; | ||
+ | monservo1.write(91); //stop | ||
+ | monservo2.write(93); //stop | ||
+ | } | ||
+ | if (val == 3) | ||
+ | { | ||
+ | s += " gauche "; | ||
+ | monservo1.write(180); //gauche | ||
+ | monservo2.write(180); //gauche | ||
+ | } | ||
+ | if (val == 4) | ||
+ | { | ||
+ | s += " droite "; | ||
+ | monservo1.write(0); //droite | ||
+ | monservo2.write(0); //recule | ||
+ | } | ||
+ | if (val == 5) | ||
+ | { | ||
+ | s+= " bouche allumee"; | ||
+ | digitalWrite(led1,HIGH); //led bouche allumee | ||
+ | } | ||
+ | if (val == 6) | ||
+ | { | ||
+ | s+= " bouche eteinte"; | ||
+ | digitalWrite(led1,LOW); //led bouche eteinte | ||
+ | } | ||
+ | if (val == 7) | ||
+ | { | ||
+ | s+= " yeux allume"; | ||
+ | digitalWrite(led2,HIGH); //led yeux allumee | ||
+ | } | ||
+ | if (val == 8) | ||
+ | { | ||
+ | s+= " yeux eteint"; | ||
+ | digitalWrite(led2,LOW); //led yeux eteinte | ||
+ | } | ||
+ | if (val == 9 ) | ||
+ | { | ||
+ | s+= " bouche ouverte"; | ||
+ | monservo3.write(180); | ||
+ | monservo4.write(0); | ||
+ | } | ||
+ | if (val == 12) | ||
+ | { | ||
+ | s+= " arret bouche "; | ||
+ | monservo3.write(90); | ||
+ | monservo4.write(90); | ||
+ | } | ||
+ | if (val==11) | ||
+ | { | ||
+ | s+= " bouche fermee"; | ||
+ | monservo3.write(0); | ||
+ | monservo4.write(180); | ||
+ | } | ||
s += "</html>\n"; | s += "</html>\n"; | ||
+ | |||
// Envoie la réponse au client | // Envoie la réponse au client | ||
Ligne 158 : | Ligne 237 : | ||
Serial.println("Client deconnecte "); | Serial.println("Client deconnecte "); | ||
client.flush(); | client.flush(); | ||
+ | |||
+ | |||
} | } | ||
+ | |||
void setupWiFi() | void setupWiFi() | ||
{ | { | ||
− | WiFi.mode(WIFI_AP); | + | WiFi.mode(WIFI_AP); |
uint8_t mac[WL_MAC_ADDR_LENGTH]; | uint8_t mac[WL_MAC_ADDR_LENGTH]; | ||
− | WiFi.softAPmacAddress(mac); | + | WiFi.softAPmacAddress(mac); |
− | String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) + String(mac[WL_MAC_ADDR_LENGTH - 1], HEX); | + | String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) + |
+ | String(mac[WL_MAC_ADDR_LENGTH - 1], HEX); | ||
macID.toUpperCase(); | macID.toUpperCase(); | ||
String AP_NameString = "Godzilla"; | String AP_NameString = "Godzilla"; | ||
+ | |||
char AP_NameChar[AP_NameString.length() + 1]; | char AP_NameChar[AP_NameString.length() + 1]; | ||
− | memset(AP_NameChar, 0, AP_NameString.length() + 1); | + | memset(AP_NameChar, 0, AP_NameString.length() + 1);//zero out AP_NameChar |
+ | |||
for (int i = 0; i < AP_NameString.length(); i++) | for (int i = 0; i < AP_NameString.length(); i++) | ||
AP_NameChar[i] = AP_NameString.charAt(i); | AP_NameChar[i] = AP_NameString.charAt(i); | ||
− | WiFi.softAP(AP_NameChar, WiFiAPPSK, 7); | + | |
+ | WiFi.softAP(AP_NameChar, WiFiAPPSK, 7); | ||
} | } | ||
void initHardware() | void initHardware() | ||
{ | { | ||
− | Serial.begin(115200); // | + | Serial.begin(115200);//ouvre le moniteur série |
− | } | + | } //Ce programme est inspiré de celui-ci : http://www.esp8266.com/viewtopic.php?f=29&t=6419#sthash.gd1tJhwU.dpuf |
==étapes de fabrication== | ==étapes de fabrication== |
Version du 21 janvier 2025 à 16:07
Titre de la fiche expérience :
Sommaire
[masquer]description (résumé)
Auteurs
- Isaac
- Matteo
- Mathieu
- Kénan
Introduction
Nous créons un robot Godzilla époustouflant avec des LED dans les yeux et la bouche, capable d'ouvrir sa mâchoire pour un effet spectaculaire !
Outils et matériaux
- 4 servomoteurs
- 2 roues imprimées en 3D
- 1 microprocesseur ESP8266
- 1 module wifi
- 2 grandes LED rouges
- 1 bille avec son support imprimé en 3D
- des fils électriques
- des morceaux de carton
- du papier canson
code Godzilla
Servo monservo4;
WiFiServer server(80);
////////////////
// Godzilla //
////////////////
/* un programme conçu par Mattéo Le Guen à partir de celui de Julien Rat sous licence CC-By-Sa.
Ce programme sert à piloter le "Godzilla".
C'est un robot pédagogique, très peu cher, utilisé par les petits débrouillards*/
- include <ESP8266WiFi.h>
//////////////////////
//Définition du Wifi//
//////////////////////
const char WiFiAPPSK[] = "1234567890"; //mot de passe
//////////////////////////
//Définition des broches//
//////////////////////////
- include <Servo.h>
Servo monservo1;
Servo monservo2;
Servo monservo3;
const int led1 = D3;
const int led2 = D4;
void setup()
{
initHardware(); setupWiFi(); server.begin(); monservo1.attach(5); monservo2.attach(4); monservo3.attach(12);b monservo4.attach(15); monservo1.write(91); monservo2.write(93); monservo3.write(90); monservo4.write(90); pinMode(led1, OUTPUT); pinMode(led2, OUTPUT);
}
void loop()
{
// Regarder si un client s'est connecté WiFiClient client = server.available(); if (!client) { return; }
// Lire la première ligne de la requête String req = client.readStringUntil('\r'); client.flush();
// Tester la requête pour identifier la consigne int val = -1;
if (req.indexOf("/stop") != -1) val = 0; else if (req.indexOf("/avance") != -1) val = 2; else if (req.indexOf("/recule") != -1) val = 1; else if (req.indexOf("/gauche") != -1) val = 3; else if (req.indexOf("/droite") != -1) val = 4; else if (req.indexOf("/allume1") != -1) val = 5; else if (req.indexOf("/eteint1") != -1) val = 6; else if (req.indexOf("/allume2") != -1) val = 7; else if (req.indexOf("/eteint2") != -1) val = 8; else if (req.indexOf("/ouvrir") != -1) val = 9; else if (req.indexOf("/arret") != -1) val = 12; else if (req.indexOf("/fermer") != -1) val = 11;
// Prépare la page web de réponse
String s = "HTTP/1.1 200 OK\r\n";
s += "Content-Type: text/html\r\n\r\n";
s += "<!DOCTYPE HTML>\r\n\r\n";
// Interface web du contrôle du robot
s += "
Controle de Godzilla
"; s += ""; s += ""; s += ""; s += ""; s += ""; s += "Controle des LEDs bouche
"; s += ""; s += ""; s += "Controle des LEDs yeux
"; s += ""; s += ""; s += "Controle de la bouche
"; s += ""; s += ""; s += ""; s += ""; // Si on a reçu l’instruction, il faut la l’appliquer au robot if (val == 2 ) { s += " avance "; monservo2.write(180); //avance monservo1.write(0); //avance } if (val == 1)//recule { s += " recule "; monservo2.write(0); //recule monservo1.write(180); //recule } if (val == 0) { s += " stop "; monservo1.write(91); //stop monservo2.write(93); //stop } if (val == 3) { s += " gauche "; monservo1.write(180); //gauche monservo2.write(180); //gauche } if (val == 4) { s += " droite "; monservo1.write(0); //droite monservo2.write(0); //recule } if (val == 5) { s+= " bouche allumee"; digitalWrite(led1,HIGH); //led bouche allumee } if (val == 6) { s+= " bouche eteinte"; digitalWrite(led1,LOW); //led bouche eteinte } if (val == 7) { s+= " yeux allume"; digitalWrite(led2,HIGH); //led yeux allumee } if (val == 8) { s+= " yeux eteint"; digitalWrite(led2,LOW); //led yeux eteinte } if (val == 9 ) { s+= " bouche ouverte"; monservo3.write(180); monservo4.write(0); } if (val == 12) { s+= " arret bouche "; monservo3.write(90); monservo4.write(90); } if (val==11) { s+= " bouche fermee"; monservo3.write(0); monservo4.write(180); } s += "\n";
// Envoie la réponse au client client.print(s); delay(1); Serial.println("Client deconnecte "); client.flush();
}
void setupWiFi()
{
WiFi.mode(WIFI_AP); uint8_t mac[WL_MAC_ADDR_LENGTH]; WiFi.softAPmacAddress(mac); String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) + String(mac[WL_MAC_ADDR_LENGTH - 1], HEX); macID.toUpperCase(); String AP_NameString = "Godzilla"; char AP_NameChar[AP_NameString.length() + 1]; memset(AP_NameChar, 0, AP_NameString.length() + 1);//zero out AP_NameChar
for (int i = 0; i < AP_NameString.length(); i++) AP_NameChar[i] = AP_NameString.charAt(i);
WiFi.softAP(AP_NameChar, WiFiAPPSK, 7);
}
void initHardware() {
Serial.begin(115200);//ouvre le moniteur série
} //Ce programme est inspiré de celui-ci : http://www.esp8266.com/viewtopic.php?f=29&t=6419#sthash.gd1tJhwU.dpuf
étapes de fabrication
étape 1 On dessine un schéma du rendu souhaité
étape 2 On vérifie le fonctionnement de la carte Wi-Fi
Pour vérifier le bon fonctionnement de la carte Wi-Fi, commencez par la connecter à l’aide de l’adaptateur USB vers Micro-USB. Ensuite, accédez au menu "Outils" dans votre logiciel Arduino, sélectionnez l’option "Carte", puis choisissez "LOLIN (WEMOS) D1 R2 & mini". Assurez-vous également que le port USB correct est bien sélectionné dans la section "Port" du menu "Outils".
Pour tester la carte, utilisez le code Arduino fourni. Avant de téléverser le code, modifiez le nom du réseau Wi-Fi directement dans le script selon vos besoins. Une fois cette étape effectuée, téléversez le code. Si tout est correctement configuré, vous devriez voir apparaître le nouveau nom de réseau Wi-Fi lorsque vous recherchez les réseaux disponibles à proximité. Le mot de passe par défaut est "1234567890".
Si le réseau est visible, cela confirme que la carte fonctionne correctement.
Remarque importante : Veillez à bien téléverser le code sur la carte, et non simplement le compiler.
étape 3 réaliser la tête de Godzilla
étape 4 coder l'ouverture de la bouche de Godzilla
Troubleshouting
Difficultés :
- il faut être très minutieux et précis pour la découpe
- faire attention à quelle broche on utilise : https://www.wikidebrouillard.org/wiki/Item:D1_mini
Solutions :
- patience
- persévérance
- ne pas s'énerver
- précision
- concentration
Sources et documentation complémentaire
sources et ressources utiles
Et dans la vie de tous les jours ?
Vous pouvez profiter du robot Godzilla pour vous amuser en faisant peur aux gens !! Ce projet permet de s'approprier l'environnement de développement Arduino