Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédenteProchaine révisionLes deux révisions suivantes | ||
ateliers:ouverture_de_portes [2021/09/30 19:42] – gepeto | ateliers:ouverture_de_portes [2021/10/01 12:45] – [Ouverture de porte commandée] gepeto | ||
---|---|---|---|
Ligne 9: | Ligne 9: | ||
{{: | {{: | ||
- | Je pars sur la platine wemos sur TB6612 qui encaisse le moteur choisi (0,5A 12V) avec une autre platine d' | + | Je pars maintenant sur la L298N |
+ | |||
+ | **Connexion** | ||
+ | * D1 bouton Fermé | ||
+ | * D2 bouton Ouvert D2-> | ||
+ | * D5 -> In2 / | ||
+ | * D6 -> In1 / L298N | ||
+ | * D7 -> Ain / | ||
+ | * 5V -> 5V / | ||
+ | * moteur 500mA en A | ||
+ | |||
+ | Commande OSC par exemple ./osc.py send 192.168.1.31: | ||
+ | |||
+ | Reste à faire le flow nodered ou une commande cron/bash sur le serveur ;-) | ||
+ | |||
+ | ===== Code V1 L298N ===== | ||
+ | |||
+ | <code c> | ||
+ | /* Poulpidou V1.0 | ||
+ | gepeto@du-libre.org 2018 | ||
+ | commande de porte de poulaillé , commande par Wifi / OSC | ||
+ | la commande OSC | ||
+ | /ouvre | ||
+ | /ferme | ||
+ | /status | ||
+ | // a cause de OSC sur purdata on garde que des float ! | ||
+ | sorties : 1, 2, 4, 5, 6, 7 //ok pour 1, | ||
+ | |||
+ | Matériel: ESP Wemos + platine wemos alimentation = platine L298N Driver moteurs | ||
+ | |||
+ | */ | ||
+ | #include < | ||
+ | //#include < | ||
+ | #include < | ||
+ | |||
+ | #include < | ||
+ | //#include < | ||
+ | // OSC | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | // | ||
+ | |||
+ | // | ||
+ | |||
+ | // | ||
+ | // Driver moteur - NodeCU | ||
+ | const int enA = D7; //wemos D7 | ||
+ | const int in1 = D6; //wemos D6 | ||
+ | const int in2 = D5; //wemos D5 | ||
+ | |||
+ | int noporte = 1; | ||
+ | IPAddress porte_ip(192, | ||
+ | //IPAddress porte_ip(192, | ||
+ | const char* nomhost = " | ||
+ | IPAddress MonitIP(192, | ||
+ | char* OSCVar = "/ | ||
+ | const unsigned int inPort = 9081; | ||
+ | const unsigned int MonitPort = 9998; // suivi normal | ||
+ | |||
+ | const char* ssid1 = " | ||
+ | const char* password1 = " | ||
+ | const char* ssid2 = " | ||
+ | const char* password2 = " | ||
+ | const char* ssid3 = " | ||
+ | const char* password3 = " | ||
+ | const char* ssid4 = " | ||
+ | const char* password4 = " | ||
+ | |||
+ | /////// FIN ////////////////////////////////////////////// | ||
+ | ////////////////////////////////////////////////////////// | ||
+ | IPAddress mask(255, 255, 255, 0); | ||
+ | //IPAddress passerelle(192, | ||
+ | IPAddress passerelle(192, | ||
+ | const char DEVICE_NAME[] = " | ||
+ | //D0-16 | ||
+ | //D1 5 | ||
+ | //D2 4 up (led) | ||
+ | //D1 0 up bouton ferme | ||
+ | //D2 2 up bouton ouvre | ||
+ | //D5 14 in2 / | ||
+ | //D6 12 in1 / -> L298N platine | ||
+ | //D7 13 enA / | ||
+ | //D8 15 down | ||
+ | //└─ $ ▶ ./osc.py send 192.168.0.121: | ||
+ | bool ouvert = false; | ||
+ | bool ferme = false; | ||
+ | bool ouvre_en_cours = false; | ||
+ | bool ferme_en_cours = false; | ||
+ | float temps_maxi = 30000; // temps maxi ouverture porte | ||
+ | float temps_milli | ||
+ | uint64_t minute_dodo = 5; // min ESP.deepSleep(1000000 * 60 * (uint64_t)min); | ||
+ | float temps_debut = 0; | ||
+ | |||
+ | WiFiUDP Udp; // A UDP instance to let us send and receive packets over UDP | ||
+ | |||
+ | |||
+ | void dodo() { | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | Serial.print(" | ||
+ | Serial.println((float)minute_dodo); | ||
+ | // Connect D0 to RST to wake up ! | ||
+ | ESP.deepSleep(minute_dodo * 60 * 1000000); | ||
+ | } | ||
+ | //converts the pin to an osc address | ||
+ | char * numToOSCAddress(int pin) { | ||
+ | static char s[10]; | ||
+ | int i = 9; | ||
+ | |||
+ | s[i--] = ' | ||
+ | do | ||
+ | { | ||
+ | s[i] = " | ||
+ | --i; | ||
+ | pin /= 10; | ||
+ | } | ||
+ | while (pin && i); | ||
+ | s[i] = '/'; | ||
+ | return & | ||
+ | } | ||
+ | |||
+ | void MonitMsg(char debugbla[], int debugint) { | ||
+ | sprintf(OSCVar, | ||
+ | OSCMessage envoi(OSCVar); | ||
+ | // | ||
+ | envoi.add(debugint); | ||
+ | |||
+ | Udp.beginPacket(MonitIP, | ||
+ | envoi.send(Udp); | ||
+ | Udp.endPacket(); | ||
+ | envoi.empty(); | ||
+ | } | ||
+ | void Envoyer_status(OSCMessage & msg) { | ||
+ | if (ouvert == true ) | ||
+ | if (ferme == true ) | ||
+ | } | ||
+ | void Ouvre(OSCMessage & msg) { | ||
+ | Serial.print(" | ||
+ | if (digitalRead(D2) == LOW && ouvert == false) { | ||
+ | analogWrite(enA, | ||
+ | MonitMsg(" | ||
+ | ouvert = true; | ||
+ | ferme = false; | ||
+ | Serial.println(" | ||
+ | } else { | ||
+ | digitalWrite(in1, | ||
+ | digitalWrite(in2, | ||
+ | analogWrite(enA, | ||
+ | temps_debut = millis(); // on arme le temps pour stop si trop long | ||
+ | MonitMsg(" | ||
+ | ouvre_en_cours = true; | ||
+ | ferme_en_cours = false; | ||
+ | } | ||
+ | } | ||
+ | void Ferme(OSCMessage & msg) { | ||
+ | Serial.print(" | ||
+ | if (digitalRead(D1) == LOW && ferme == false) { | ||
+ | analogWrite(enA, | ||
+ | MonitMsg(" | ||
+ | ouvert = false; | ||
+ | ferme = true; | ||
+ | Serial.println(" | ||
+ | |||
+ | } else { | ||
+ | digitalWrite(in1, | ||
+ | digitalWrite(in2, | ||
+ | analogWrite(enA, | ||
+ | temps_debut = millis(); // on arme le temps pour stop si trop long | ||
+ | MonitMsg(" | ||
+ | ouvre_en_cours = false; | ||
+ | ferme_en_cours = true; | ||
+ | } | ||
+ | } | ||
+ | void Arreter(OSCMessage & msg) { | ||
+ | analogWrite(enA, | ||
+ | digitalWrite(in1, | ||
+ | digitalWrite(in2, | ||
+ | Serial.println(" | ||
+ | ouvre_en_cours = false; | ||
+ | ferme_en_cours = false; | ||
+ | } | ||
+ | void setup(void) { | ||
+ | Serial.begin(115200); | ||
+ | //set led pin as output | ||
+ | pinMode(enA, | ||
+ | pinMode(in1, | ||
+ | pinMode(in2, | ||
+ | pinMode(D2, INPUT_PULLUP); | ||
+ | pinMode(D1, INPUT_PULLUP); | ||
+ | Serial.println((int32_t)ESP.getChipId()); | ||
+ | delay(1000); | ||
+ | //int BoutonParam = analogRead(A0); | ||
+ | // start ticker with 0.5 because we start in AP mode and try to connect | ||
+ | // | ||
+ | // a cause de OSC sur purdata on garde que des float ! | ||
+ | Serial.println(F("/ | ||
+ | Serial.println(F("/ | ||
+ | Serial.println(F("/ | ||
+ | |||
+ | temps_milli = millis(); | ||
+ | pinMode(D0, WAKEUP_PULLUP); | ||
+ | |||
+ | WiFi.disconnect(); | ||
+ | WiFi.mode(WIFI_STA); | ||
+ | / | ||
+ | wifiMulti.addAP(ssid2, | ||
+ | wifiMulti.addAP(ssid3, | ||
+ | wifiMulti.addAP(ssid4, | ||
+ | Serial.print(" | ||
+ | Serial.println(ssid1); | ||
+ | Serial.println(ssid2); | ||
+ | Serial.println(ssid3); | ||
+ | Serial.println(ssid4); | ||
+ | */ | ||
+ | WiFi.hostname(nomhost); | ||
+ | WiFi.begin(ssid2, | ||
+ | |||
+ | WiFi.config(porte_ip, | ||
+ | //while (wifiMulti.run() != WL_CONNECTED) { | ||
+ | while (WiFi.status() != WL_CONNECTED) { | ||
+ | |||
+ | delay(500); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | Serial.println(F(" | ||
+ | Serial.println(WiFi.localIP()); | ||
+ | Serial.println(F(" | ||
+ | Serial.print(WiFi.hostname()); | ||
+ | // Serial.println(F(" | ||
+ | Serial.println(F(" | ||
+ | Serial.print(F(" | ||
+ | Serial.println(inPort); | ||
+ | delay(100); | ||
+ | Udp.begin(inPort); | ||
+ | Serial.print(F(" | ||
+ | Serial.println(Udp.localPort()); | ||
+ | |||
+ | // Set up mDNS responder: | ||
+ | // - first argument is the domain name, in this example | ||
+ | // the fully-qualified domain name is " | ||
+ | // - second argument is the IP address to advertise | ||
+ | // we send our IP address on the WiFi network | ||
+ | if (!MDNS.begin(WiFi.hostname())) { | ||
+ | Serial.println(" | ||
+ | } | ||
+ | Serial.println(" | ||
+ | |||
+ | if (analogRead(A0) > 10) Ouvre; | ||
+ | } | ||
+ | void loop() { | ||
+ | //////////// | ||
+ | //reads and dispatches the incoming message | ||
+ | OSCMessage msgIN; | ||
+ | |||
+ | int size; | ||
+ | //char puce_char[] = " | ||
+ | if ( (size = Udp.parsePacket()) > 0) | ||
+ | { | ||
+ | while (size--) | ||
+ | msgIN.fill(Udp.read()); | ||
+ | if (!msgIN.hasError()) { | ||
+ | msgIN.dispatch("/ | ||
+ | msgIN.dispatch("/ | ||
+ | msgIN.dispatch("/ | ||
+ | msgIN.dispatch("/ | ||
+ | Serial.println(size); | ||
+ | } else { | ||
+ | Serial.print(" | ||
+ | Serial.println(msgIN.getError()); | ||
+ | } | ||
+ | Udp.flush(); | ||
+ | } | ||
+ | if (digitalRead(D2) == LOW ) { | ||
+ | analogWrite(enA, | ||
+ | ouvre_en_cours = false; | ||
+ | MonitMsg(" | ||
+ | ouvert = true; | ||
+ | ferme = false; | ||
+ | } | ||
+ | if (digitalRead(D1) == LOW ) { | ||
+ | analogWrite(enA, | ||
+ | ferme_en_cours = false; | ||
+ | MonitMsg(" | ||
+ | ferme = true; | ||
+ | ouvert = false; | ||
+ | } | ||
+ | //if (ouvre_en_cours || ferme_en_cours) Serial.println(millis() - temps_debut); | ||
+ | if (digitalRead(D2) == LOW ) Serial.println(" | ||
+ | if (digitalRead(D1) == LOW ) Serial.println(" | ||
+ | |||
+ | if (ouvre_en_cours == true) Serial.println (" | ||
+ | if (ferme_en_cours == true) Serial.println (" | ||
+ | |||
+ | delay(500); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | J' | ||
+ | |||
+ | Mais je l' | ||
===== Wemos motor shield ===== | ===== Wemos motor shield ===== | ||
Ligne 30: | Ligne 329: | ||
===== Prog du moment ===== | ===== Prog du moment ===== | ||
+ | **Sur la platine driver wemos moteur** | ||
<code c> | <code c> | ||
- | /* Poulpidou | + | /* Poulpidou |
gepeto@du-libre.org 2018 | gepeto@du-libre.org 2018 | ||
commande de porte de poulaillé , commande par Wifi / OSC | commande de porte de poulaillé , commande par Wifi / OSC |