Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
|
projets:b3:v2:accueil [2017/03/10 11:34] resonance [B3 - version 2] |
projets:b3:v2:accueil [2017/11/28 16:38] (Version actuelle) resonance [Vidéo] |
||
|---|---|---|---|
| Ligne 14: | Ligne 14: | ||
| ===== Code ESP8266 ===== | ===== Code ESP8266 ===== | ||
| * Installation et configuration sur notre page dédiée : [[materiel: | * Installation et configuration sur notre page dédiée : [[materiel: | ||
| + | |||
| + | |||
| + | ==== v1 ==== | ||
| * Fichiers : {{ : | * Fichiers : {{ : | ||
| - | Communication en UDP, réception d'une seule valeur pour l' | + | Communication en UDP, réception d'une seule valeur pour l' |
| ++++ Code Arduino | | ++++ Code Arduino | | ||
| Ligne 110: | Ligne 113: | ||
| solenoid_delay = data[1].toInt(); | solenoid_delay = data[1].toInt(); | ||
| - | // MOTOR ON | + | // SOLENOID |
| if( solenoids[solenoid_id].isOn() == false ) solenoids[solenoid_id].on(current, | if( solenoids[solenoid_id].isOn() == false ) solenoids[solenoid_id].on(current, | ||
| } | } | ||
| - | // MOTOR OFF | + | // 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 | ||
| for (int i=0; i < NB; i++) { | for (int i=0; i < NB; i++) { | ||
| if( solenoids[i].isOn() ) solenoids[i].off(current); | if( solenoids[i].isOn() ) solenoids[i].off(current); | ||
| Ligne 148: | Ligne 319: | ||
| ===== Code Pure Data ===== | ===== Code Pure Data ===== | ||
| - | Voir sources bientôt. | ||
| * Fichiers de tests : {{ : | * Fichiers de tests : {{ : | ||
| {{: | {{: | ||
| + | |||
| + | |||
| + | |||
| + | {{: | ||
| ===== Fabrication ===== | ===== Fabrication ===== | ||
| - | A venir. | + | |
| + | {{ : | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | {{: | ||
| + | |||
| + | |||
| + | ---- | ||
| + | ===== Vidéo ===== | ||
| + | {{: | ||