ENIB 2026 :Gestion de toilettes : Différence entre versions
(→fichiers à joindre) |
(→Mettre du code Arduino) |
||
| Ligne 16 : | Ligne 16 : | ||
===Mettre du code Arduino=== | ===Mettre du code Arduino=== | ||
<syntaxhighlight lang="Arduino" line> | <syntaxhighlight lang="Arduino" line> | ||
| − | # | + | //code de la carte du sender |
| − | #include < | + | |
| + | #include <esp_now.h> | ||
| + | #include <WiFi.h> | ||
| + | |||
| + | #define buttonPin 18 | ||
| + | #define ledPin 4 | ||
| + | |||
| + | bool systemState = false; | ||
| + | bool lastButtonState = HIGH; | ||
| + | |||
| + | uint8_t broadcastAddress1[] = {0x20,0xe7,0xc8,0xac,0xb1,0x48}; | ||
| + | esp_now_peer_info_t peerInfo; | ||
| + | |||
| + | // Callback | ||
| + | void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { | ||
| + | Serial.print("Send status: "); | ||
| + | Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Success" : "Fail"); | ||
| + | } | ||
void setup() { | void setup() { | ||
| − | + | Serial.begin(115200); | |
| + | |||
| + | pinMode(buttonPin, INPUT_PULLUP); | ||
| + | pinMode(ledPin, OUTPUT); | ||
| + | WiFi.mode(WIFI_STA); | ||
| + | |||
| + | if (esp_now_init() != ESP_OK) { | ||
| + | Serial.println("ESP-NOW init failed"); | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | esp_now_register_send_cb(OnDataSent); | ||
| + | |||
| + | memcpy(peerInfo.peer_addr, broadcastAddress1, 6); | ||
| + | peerInfo.channel = 0; | ||
| + | peerInfo.encrypt = false; | ||
| + | |||
| + | if (esp_now_add_peer(&peerInfo) != ESP_OK) { | ||
| + | Serial.println("Failed to add peer"); | ||
| + | } | ||
} | } | ||
void loop() { | void loop() { | ||
| − | // | + | char message = '2'; // default value |
| + | bool buttonState = digitalRead(buttonPin); | ||
| + | // Detect button press (falling edge) | ||
| + | if (lastButtonState == HIGH && buttonState == LOW) { | ||
| + | systemState = !systemState; | ||
| + | |||
| + | if (systemState) { | ||
| + | digitalWrite(ledPin, 0); | ||
| + | message = '1'; | ||
| + | } else { | ||
| + | digitalWrite(ledPin, 1); | ||
| + | message = '0'; | ||
| + | } | ||
| + | |||
| + | esp_err_t result = esp_now_send( | ||
| + | broadcastAddress1, | ||
| + | (uint8_t *)&message, | ||
| + | sizeof(message) | ||
| + | ); | ||
| + | |||
| + | if (result == ESP_OK) { | ||
| + | Serial.print("Sent: "); | ||
| + | Serial.println(message); | ||
| + | } else { | ||
| + | Serial.println("Send error"); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | lastButtonState = buttonState; | ||
| + | delay(50); // debounce | ||
| + | } | ||
| + | //code de la carte du receiver | ||
| + | #include <esp_now.h> | ||
| + | #include <WiFi.h> | ||
| + | #include <ESP32Servo.h> | ||
| + | #define led1 18 | ||
| + | #define servoPin 5 | ||
| + | Servo myServo; | ||
| + | |||
| + | // Callback function executed when data is received | ||
| + | void OnDataRecv(const esp_now_recv_info_t *recv_info, const uint8_t *incomingData, int len) { | ||
| + | if (len > 0) { | ||
| + | char receivedChar = incomingData[0]; // extract the first byte | ||
| + | |||
| + | // Convert MAC to string | ||
| + | char macStr[18]; | ||
| + | snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", | ||
| + | recv_info->src_addr[0], recv_info->src_addr[1], recv_info->src_addr[2], | ||
| + | recv_info->src_addr[3], recv_info->src_addr[4], recv_info->src_addr[5]); | ||
| + | |||
| + | Serial.print("Received from: "); | ||
| + | Serial.println(macStr); | ||
| + | Serial.print("Character received: "); | ||
| + | Serial.println(receivedChar); | ||
| + | if(receivedChar=='1'){ | ||
| + | digitalWrite(led1, 1); | ||
| + | |||
| + | myServo.write(180); | ||
| + | } | ||
| + | else if(receivedChar=='0'){ | ||
| + | digitalWrite(led1, 0); | ||
| + | |||
| + | myServo.write(0); | ||
| + | } | ||
| + | else{ | ||
| + | for (int i=0;i<180;i+=10){ | ||
| + | myServo.write(i); | ||
| + | digitalWrite(led1, 0); | ||
| + | delay(1000); | ||
| + | digitalWrite(led1, 1); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | } | ||
| + | } | ||
| + | |||
| + | void setup() { | ||
| + | Serial.begin(115200); | ||
| + | |||
| + | // Set device as a Wi-Fi Station | ||
| + | WiFi.mode(WIFI_STA); | ||
| + | |||
| + | // Initialize ESP-NOW | ||
| + | if (esp_now_init() != ESP_OK) { | ||
| + | Serial.println("Error initializing ESP-NOW"); | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | // Register callback for receiving data | ||
| + | esp_now_register_recv_cb(OnDataRecv); | ||
| + | |||
| + | Serial.println("ESP-NOW Receiver Ready"); | ||
| + | pinMode(led1,OUTPUT); | ||
| + | myServo.attach(servoPin); | ||
| + | myServo.write(0); // position initiale du servo | ||
| + | digitalWrite(led1,0); // éteindre la led | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | // Nothing needed here; data is handled in the callback | ||
} | } | ||
Version du 22 janvier 2026 à 11:50
Titre de la fiche expérience :
Sommaire
description (résumé)
éventuelle photo de l'équipe
Introduction
éventuelle vidéo
outil et matériel
Pour mener à bien ce projet nous eûmes besoin de deux ESP32, ainsi que deux servomoteurs, de deux câbles USB, d'une breadboard, d'un boutton poussoir, d'une dizaine de fils
fichiers à joindre
code, ficher d'impression 3D, de découpe laser ou vinyle, ... Fichier:Gestion de toilettes.pdf
Mettre du code Arduino
1
2 //code de la carte du sender
3
4 #include <esp_now.h>
5 #include <WiFi.h>
6
7 #define buttonPin 18
8 #define ledPin 4
9
10 bool systemState = false;
11 bool lastButtonState = HIGH;
12
13 uint8_t broadcastAddress1[] = {0x20,0xe7,0xc8,0xac,0xb1,0x48};
14 esp_now_peer_info_t peerInfo;
15
16 // Callback
17 void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
18 Serial.print("Send status: ");
19 Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Success" : "Fail");
20 }
21
22 void setup() {
23 Serial.begin(115200);
24
25 pinMode(buttonPin, INPUT_PULLUP);
26 pinMode(ledPin, OUTPUT);
27
28 WiFi.mode(WIFI_STA);
29
30 if (esp_now_init() != ESP_OK) {
31 Serial.println("ESP-NOW init failed");
32 return;
33 }
34
35 esp_now_register_send_cb(OnDataSent);
36
37 memcpy(peerInfo.peer_addr, broadcastAddress1, 6);
38 peerInfo.channel = 0;
39 peerInfo.encrypt = false;
40
41 if (esp_now_add_peer(&peerInfo) != ESP_OK) {
42 Serial.println("Failed to add peer");
43 }
44 }
45
46 void loop() {
47 char message = '2'; // default value
48 bool buttonState = digitalRead(buttonPin);
49
50 // Detect button press (falling edge)
51 if (lastButtonState == HIGH && buttonState == LOW) {
52 systemState = !systemState;
53
54 if (systemState) {
55 digitalWrite(ledPin, 0);
56 message = '1';
57 } else {
58 digitalWrite(ledPin, 1);
59 message = '0';
60 }
61
62 esp_err_t result = esp_now_send(
63 broadcastAddress1,
64 (uint8_t *)&message,
65 sizeof(message)
66 );
67
68 if (result == ESP_OK) {
69 Serial.print("Sent: ");
70 Serial.println(message);
71 } else {
72 Serial.println("Send error");
73 }
74 }
75
76 lastButtonState = buttonState;
77 delay(50); // debounce
78 }
79 //code de la carte du receiver
80 #include <esp_now.h>
81 #include <WiFi.h>
82 #include <ESP32Servo.h>
83 #define led1 18
84 #define servoPin 5
85 Servo myServo;
86
87 // Callback function executed when data is received
88 void OnDataRecv(const esp_now_recv_info_t *recv_info, const uint8_t *incomingData, int len) {
89 if (len > 0) {
90 char receivedChar = incomingData[0]; // extract the first byte
91
92 // Convert MAC to string
93 char macStr[18];
94 snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
95 recv_info->src_addr[0], recv_info->src_addr[1], recv_info->src_addr[2],
96 recv_info->src_addr[3], recv_info->src_addr[4], recv_info->src_addr[5]);
97
98 Serial.print("Received from: ");
99 Serial.println(macStr);
100 Serial.print("Character received: ");
101 Serial.println(receivedChar);
102 if(receivedChar=='1'){
103 digitalWrite(led1, 1);
104
105 myServo.write(180);
106 }
107 else if(receivedChar=='0'){
108 digitalWrite(led1, 0);
109
110 myServo.write(0);
111 }
112 else{
113 for (int i=0;i<180;i+=10){
114 myServo.write(i);
115 digitalWrite(led1, 0);
116 delay(1000);
117 digitalWrite(led1, 1);
118 }
119 }
120
121 }
122 }
123
124 void setup() {
125 Serial.begin(115200);
126
127 // Set device as a Wi-Fi Station
128 WiFi.mode(WIFI_STA);
129
130 // Initialize ESP-NOW
131 if (esp_now_init() != ESP_OK) {
132 Serial.println("Error initializing ESP-NOW");
133 return;
134 }
135
136 // Register callback for receiving data
137 esp_now_register_recv_cb(OnDataRecv);
138
139 Serial.println("ESP-NOW Receiver Ready");
140 pinMode(led1,OUTPUT);
141 myServo.attach(servoPin);
142 myServo.write(0); // position initiale du servo
143 digitalWrite(led1,0); // éteindre la led
144 }
145
146 void loop() {
147 // Nothing needed here; data is handled in the callback
148 }
étapes de fabrication
indiquer autant d'étape que nécessaire, chacune illustrée par des images (photo, dessins, ...)
étape 1
étape 2
étape ...
Troubleshouting
Quelles sont difficultés, les problèmes, quelles sont les solutions, les trucs et astuces pour que ça marche ?
Sources et documentation complémentaire
- Rédаctiоn et illustratiоn :
Pоur tоus vоs trаvauх, qu'ils sоient écrits оu visuels, l'utilisatiоn de l'intеlligеnce artificiеllе générativе, que сe sоit pоur le teхte оu les images, n'еst pas conseillé.
- Prоgrammаtiоn :
En сe qui cоncernе la prоgrаmmatiоn, il est еssentiеl de ne pаs faire dе l'IA vоtrе prеmier rеcоurs. Cоncеntrеz-vоus d'abоrd sur vоtre prоpre lоgiquе, votre experience еt lеs ressоurcеs disponibles.
- Transpаrence et dосumеntatiоn :
Si vоus utilisеz l'IA pоur déblоquer оu améliоrеr une pаrtiе de vоtre cоdе, il est cruciаl de l'indiquеr сlairеmеnt dans vоtre dосumentatiоn tеchniquе.
- Traçabilité :
Chаque ехtrait de cоde généré avес l'аidе de l'IA dоit êtrе accоmpagné de la sоurce, ainsi que du prоmpt eхact qui a été utilisé pоur sа créatiоn, afin d'аssurеr une évaluatiоn clаire dе vоtre prоcessus.
Elément de présentation
je met ici le document de présentation de mon projet