start:arduino:esp32:tp:now
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| start:arduino:esp32:tp:now [2024/11/06 21:12] – créée gerardadmin | start:arduino:esp32:tp:now [2024/11/07 10:47] (Version actuelle) – [Materiels] gerardadmin | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ======== Travaux pratique Esp32 Now ======== | ======== Travaux pratique Esp32 Now ======== | ||
| + | |||
| + | == Materiels == | ||
| + | |||
| + | *2 Esp32 wroom ou equivalent | ||
| + | *2 Breadboards avec câbles | ||
| + | *1 Mini bouton poussoir | ||
| + | *1 LED 5mm ou 3 mm | ||
| + | *2 Câbles mini USB d' | ||
| + | *1 Résistance 220 ohms 1W (pour LED) | ||
| + | *1 Résistance 1 Kohms 1W (pour Bp1) | ||
| + | |||
| + | ==== Emetteur avec Bouton poussoir ==== | ||
| + | == Schema de raccordement == | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | {{ : | ||
| + | |||
| <code c emetteurBP.ino> | <code c emetteurBP.ino> | ||
| /* | /* | ||
| - | Raccorder un Bouton poussoir sur la broche | + | |
| - | Et remplacer l' | + | |
| + | Et remplacer l' | ||
| + | Apres le telechargement du programme sur l' | ||
| il faut appuyer environ 1 s sur le Bp1 | il faut appuyer environ 1 s sur le Bp1 | ||
| */ | */ | ||
| Ligne 10: | Ligne 30: | ||
| #include < | #include < | ||
| - | const int Bp1 = 34; | + | const int Bp1 = 2; |
| int MemLed1 = 0; | int MemLed1 = 0; | ||
| int MemBp1 = 0; | int MemBp1 = 0; | ||
| Ligne 18: | Ligne 38: | ||
| - | // Indiquer | + | // Indiquer |
| uint8_t broadcastAddress[] = {0x58, 0xbf, 0x25, 0x14, 0x24, 0x34}; | uint8_t broadcastAddress[] = {0x58, 0xbf, 0x25, 0x14, 0x24, 0x34}; | ||
| Ligne 118: | Ligne 138: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | |||
| + | ==== Recepteur avec Led ==== | ||
| + | |||
| + | == Schema raccordement == | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | <code c recepteur001.ino> | ||
| + | /* | ||
| + | RECEPTEUR | ||
| + | Raccorder la led sur la sortie 34 | ||
| + | Apres le telechargement du programme sur l' | ||
| + | */ | ||
| + | |||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | int led1 = 34; | ||
| + | int tempo = 50; | ||
| + | |||
| + | // Structure example to receive data | ||
| + | // Must match the sender structure | ||
| + | typedef struct struct_message { | ||
| + | char a[32]; | ||
| + | int b; | ||
| + | float c; | ||
| + | bool d; | ||
| + | } struct_message; | ||
| + | |||
| + | // Create a struct_message called myData | ||
| + | struct_message myData; | ||
| + | |||
| + | // callback function that will be executed when data is received | ||
| + | void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, | ||
| + | memcpy(& | ||
| + | Serial.print(" | ||
| + | Serial.println(len); | ||
| + | Serial.print(" | ||
| + | Serial.println(myData.a); | ||
| + | Serial.print(" | ||
| + | Serial.println(myData.b); | ||
| + | Serial.print(" | ||
| + | Serial.println(myData.c); | ||
| + | Serial.print(" | ||
| + | Serial.println(myData.d); | ||
| + | Serial.println(); | ||
| + | } | ||
| + | |||
| + | void setup() { | ||
| + | // Initialize Serial Monitor | ||
| + | Serial.begin(115200); | ||
| + | pinMode(led1, | ||
| + | | ||
| + | // Set device as a Wi-Fi Station | ||
| + | WiFi.mode(WIFI_STA); | ||
| + | |||
| + | // Init ESP-NOW | ||
| + | if (esp_now_init() != ESP_OK) { | ||
| + | Serial.println(" | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv)); | ||
| + | delay(1000); | ||
| + | |||
| + | if (myData.d == true) { | ||
| + | digitalWrite(led1, | ||
| + | } | ||
| + | if (myData.d == false) { | ||
| + | digitalWrite(led1, | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
/home/chanteri/www/fablab37110/data/attic/start/arduino/esp32/tp/now.1730923937.txt.gz · Dernière modification : de gerardadmin
