Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
projets:b3:v2:accueil [2016/11/21 21:55] resonance créée |
projets:b3:v2:accueil [2017/11/28 16:38] (Version actuelle) resonance [Vidéo] |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
====== B3 - version 2 ====== | ====== B3 - version 2 ====== | ||
- | Version sans fils, avec de plus petits | + | Version sans fils, avec de plus petits |
- | {{: | + | Sources : https:// |
+ | |||
+ | ===== Électronique ===== | ||
+ | **Idée de départ** | ||
+ | {{: | ||
+ | |||
+ | **09/ | ||
+ | {{: | ||
+ | |||
+ | |||
+ | ===== Code ESP8266 ===== | ||
+ | * Installation et configuration sur notre page dédiée : [[materiel: | ||
+ | |||
+ | |||
+ | ==== v1 ==== | ||
+ | * Fichiers : {{ : | ||
+ | |||
+ | Communication en UDP, réception d'une seule valeur pour l' | ||
+ | |||
+ | ++++ Code Arduino | | ||
+ | <code cpp> | ||
+ | /* | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | */ | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | #include " | ||
+ | |||
+ | const boolean DEBUG = false; | ||
+ | |||
+ | // NETWORK SETUP | ||
+ | char ssid[] = " | ||
+ | char pass[] = ""; | ||
+ | IPAddress ip(192, 168, 0, 111); // Local IP (static) | ||
+ | IPAddress gateway(192, | ||
+ | const unsigned int localPort = 8888; // Local Port | ||
+ | |||
+ | // OTHER SETUP | ||
+ | IPAddress subnet(255, 255, 255, 0); | ||
+ | char packetBuffer[255]; | ||
+ | String data[2]; // Store incoming data | ||
+ | int status = WL_IDLE_STATUS; | ||
+ | WiFiUDP udp; | ||
+ | |||
+ | // ---- CONFIGURATIONS ---- // | ||
+ | const int PINS[] = {12, 13, 14}; // Pins for ESP8266 Wemos like 11, 12, 13 Arduino pins | ||
+ | const int DELAY_MAX = 50; | ||
+ | const int NB = 3; | ||
+ | const int TEMPO = 10; // Sampling tempo | ||
+ | |||
+ | // ---- SOLENOIDS --------- // | ||
+ | Solenoid solenoids[NB]; | ||
+ | int solenoid_id, | ||
+ | unsigned long current = 0; | ||
+ | |||
+ | void setup() { | ||
+ | |||
+ | // Output | ||
+ | for (int i=0; i < NB; i++) { | ||
+ | | ||
+ | } | ||
+ | |||
+ | // WiFi Connection | ||
+ | WiFi.config(ip, | ||
+ | WiFi.begin(ssid, | ||
+ | while (WiFi.status() != WL_CONNECTED) | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | |||
+ | // UDP Connection | ||
+ | udp.begin(localPort); | ||
+ | |||
+ | if (DEBUG) | ||
+ | { | ||
+ | Serial.begin(115200); | ||
+ | Serial.print(" | ||
+ | Serial.println(WiFi.localIP()); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | |||
+ | // UPDATE TIME | ||
+ | current = millis(); | ||
+ | |||
+ | // Read data if available | ||
+ | int packetSize = udp.parsePacket(); | ||
+ | if (packetSize) | ||
+ | { | ||
+ | // Read the packet into packetBuffer | ||
+ | int len = udp.read(packetBuffer, | ||
+ | if (len > 0) packetBuffer[len] = 0; | ||
+ | |||
+ | // Parse with space delimiter ' ' and fill data[] | ||
+ | String strData(packetBuffer); | ||
+ | splitString(strData, | ||
+ | |||
+ | solenoid_id = data[0].toInt(); | ||
+ | solenoid_delay = data[1].toInt(); | ||
+ | |||
+ | // SOLENOID ON | ||
+ | if( solenoids[solenoid_id].isOn() == false ) solenoids[solenoid_id].on(current, | ||
+ | } | ||
+ | |||
+ | // SOLENOID OFF | ||
+ | for (int i=0; i < NB; i++) { | ||
+ | if( solenoids[i].isOn() ) solenoids[i].off(current); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Méthode pour découper le message avec un séparateur (ou " | ||
+ | // Split string messages with a separator character | ||
+ | void splitString(String message, char separator) { | ||
+ | int index = 0; | ||
+ | int cnt = 0; | ||
+ | do { | ||
+ | index = message.indexOf(separator); | ||
+ | // s'il y a bien un caractère séparateur | ||
+ | if(index != -1) { | ||
+ | // on découpe la chaine et on stocke le bout dans le tableau | ||
+ | data[cnt] = message.substring(0, | ||
+ | cnt++; | ||
+ | // on enlève du message le bout stocké | ||
+ | message = message.substring(index+1, | ||
+ | } else { | ||
+ | // après le dernier espace | ||
+ | // on s' | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | } while(index >=0); // tant qu'il y a bien un séparateur dans la chaine | ||
+ | } | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | |||
+ | ==== v2 - nov 2017 ==== | ||
+ | |||
+ | ++++ Code Arduino | | ||
+ | <code cpp> | ||
+ | /* | ||
+ | * B3 | ||
+ | * Control solenoids and LEDs through Wi-Fi network (UDP) | ||
+ | * Website: http:// | ||
+ | | ||
+ | * Setup: Pure Data > " | ||
+ | * Messages Solenoids: Id (0,1,2) Delay (0-120). | ||
+ | * Messages Leds: Id (3,4,5) Pwm (0-255) | ||
+ | * | ||
+ | * Arduino | ||
+ | * D0 3 | ||
+ | * D1 1 | ||
+ | * D2 16 | ||
+ | * D3 5 | ||
+ | * D4 4 | ||
+ | * D5/ | ||
+ | * D6/ | ||
+ | * D7/ | ||
+ | * D8 | ||
+ | * D9 | ||
+ | * D10 15 (Pull-down) | ||
+ | * | ||
+ | * Author : Jerome Abel / http:// | ||
+ | * Licence : GNU/GPL3 | ||
+ | */ | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | #include " | ||
+ | |||
+ | const boolean DEBUG = true; | ||
+ | |||
+ | // NETWORK SETUP TPLINK | ||
+ | /* | ||
+ | * char ssid[] = " | ||
+ | IPAddress ip(192, 168, 0, 111); // Local IP (static) | ||
+ | IPAddress gateway(192, | ||
+ | */ | ||
+ | // NETWORK SETUP LINKSYS | ||
+ | |||
+ | char ssid[] = " | ||
+ | IPAddress ip(192, 168, 1, 111); // Local IP (static) | ||
+ | IPAddress gateway(192, | ||
+ | |||
+ | |||
+ | char pass[] = ""; | ||
+ | const unsigned int localPort = 8888; // Local Port | ||
+ | |||
+ | // OTHER SETUP | ||
+ | IPAddress subnet(255, 255, 255, 0); | ||
+ | char packetBuffer[255]; | ||
+ | String data[2]; // Store incoming data | ||
+ | int status = WL_IDLE_STATUS; | ||
+ | WiFiUDP udp; | ||
+ | |||
+ | // ---- CONFIGURATIONS ---- // | ||
+ | const int LEDS[] = {13, 12, 14}; // Arduino: D11, D12, D13 | ||
+ | const int PINS[]= {1, 5, 4};// Arduino: D1, D3, D4 | ||
+ | const int DELAY_MAX = 50; | ||
+ | const int NB = 3; | ||
+ | const int TEMPO = 10; // Sampling tempo | ||
+ | |||
+ | |||
+ | // ---- SOLENOIDS --------- // | ||
+ | Solenoid solenoids[NB]; | ||
+ | int id, solenoid_delay; | ||
+ | unsigned long current = 0; | ||
+ | |||
+ | void setup() { | ||
+ | |||
+ | // Output solenoids | ||
+ | for (int i=0; i < NB; i++) { | ||
+ | | ||
+ | } | ||
+ | |||
+ | // Output LEDs | ||
+ | for (int i=0; i < NB; i++) { | ||
+ | pinMode(LEDS[i], | ||
+ | digitalWrite(LEDS[i], | ||
+ | } | ||
+ | |||
+ | // WiFi Connection | ||
+ | WiFi.config(ip, | ||
+ | WiFi.begin(ssid, | ||
+ | while (WiFi.status() != WL_CONNECTED) | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | |||
+ | // UDP Connection | ||
+ | udp.begin(localPort); | ||
+ | |||
+ | if (DEBUG) | ||
+ | { | ||
+ | Serial.begin(115200); | ||
+ | Serial.print(" | ||
+ | Serial.println(WiFi.localIP()); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | |||
+ | // UPDATE TIME | ||
+ | current = millis(); | ||
+ | |||
+ | // Read data if available | ||
+ | int packetSize = udp.parsePacket(); | ||
+ | if (packetSize) | ||
+ | { | ||
+ | // Read the packet into packetBuffer | ||
+ | int len = udp.read(packetBuffer, | ||
+ | if (len > 0) packetBuffer[len] = 0; | ||
+ | |||
+ | // Parse with space delimiter ' ' and fill data[] | ||
+ | String strData(packetBuffer); | ||
+ | splitString(strData, | ||
+ | id = data[0].toInt(); | ||
+ | |||
+ | // SOLENOID ON | ||
+ | if (id > 2) { | ||
+ | solenoid_delay = data[1].toInt(); | ||
+ | if( solenoids[id-3].isOn() == false ) solenoids[id-3].on(current, | ||
+ | } | ||
+ | // LEDS ON | ||
+ | else { | ||
+ | analogWrite(LEDS[id], | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | // SOLENOID OFF | ||
+ | for (int i=0; i < NB; i++) { | ||
+ | if( solenoids[i].isOn() ) solenoids[i].off(current); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Méthode pour découper le message avec un séparateur (ou " | ||
+ | // Split string messages with a separator character | ||
+ | void splitString(String message, char separator) { | ||
+ | int index = 0; | ||
+ | int cnt = 0; | ||
+ | do { | ||
+ | index = message.indexOf(separator); | ||
+ | // s'il y a bien un caractère séparateur | ||
+ | if(index != -1) { | ||
+ | // on découpe la chaine et on stocke le bout dans le tableau | ||
+ | data[cnt] = message.substring(0, | ||
+ | cnt++; | ||
+ | // on enlève du message le bout stocké | ||
+ | message = message.substring(index+1, | ||
+ | } else { | ||
+ | // après le dernier espace | ||
+ | // on s' | ||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | } while(index >=0); // tant qu'il y a bien un séparateur dans la chaine | ||
+ | } | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ===== Code Pure Data ===== | ||
+ | |||
+ | * Fichiers de tests : {{ : | ||
+ | {{: | ||
+ | |||
+ | |||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | ===== Fabrication ===== | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | ---- | ||
+ | ===== Vidéo ===== | ||
+ | {{: |