Kerminy HackerSpace

Outils du site


ateliers:ouverture_de_portes

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
Prochaine révisionLes deux révisions suivantes
ateliers:ouverture_de_portes [2021/09/30 19:42] gepetoateliers:ouverture_de_portes [2021/10/01 12:44] gepeto
Ligne 9: Ligne 9:
 {{:ateliers:l298n.jpeg?400|}} ou {{:ateliers:wemos_motor_shield_hcwemo0010_diagram.png?400|}} {{:ateliers:l298n.jpeg?400|}} ou {{:ateliers:wemos_motor_shield_hcwemo0010_diagram.png?400|}}
  
-Je pars sur la platine wemos sur TB6612 qui encaisse le moteur choisi (0,5A 12V) avec une autre platine d'alimentation [[https://www.wemos.cc/en/latest/d1_mini_shield/dc_power.html|DC shield]] le tout sur une wemos D1 pro, plus simple compacte et avec une bonne portée.+Je pars maintenant sur la L298N 
 + 
 +**Connexion** 
 +  * D1 bouton Fermé  D1->bouton->GND 
 +  * D2 bouton Ouvert D2->bouton->GND 
 +  * D5 -> In2                      / 
 +  * D6 -> In1                      / L298N 
 +  * D7 -> Ain (enable / vitesse)   / 
 +  * 5V -> 5V                       / 
 +  * moteur 500mA en A 
 + 
 +Commande OSC par exemple ./osc.py send 192.168.1.31:9081 /ouvre 
 + 
 +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,2,4,5,6,
 + 
 +  Matériel: ESP Wemos + platine wemos alimentation = platine L298N Driver moteurs 
 + 
 +*/ 
 +#include <ESP8266WiFi.h> 
 +//#include <ESP8266WiFiMulti.h> 
 +#include <ESP8266mDNS.h> 
 + 
 +#include <WiFiUdp.h> 
 +//#include <DNSServer.h> 
 +// OSC 
 +#include <OSCMessage.h> 
 +#include <OSCBundle.h> 
 +#include <OSCData.h> 
 +// 
 + 
 +//ESP8266WiFiMulti wifiMulti; 
 + 
 +//Brochage 
 +// 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, 168, 43, 121); 
 +//IPAddress porte_ip(192, 168, 0, 121); 
 +const char* nomhost = "porte-1"; 
 +IPAddress MonitIP(192, 168, 0, 99); // IP et port du moniteur 
 +char* OSCVar = "/LOCO-XX                      "; 
 +const unsigned int inPort = 9081; 
 +const unsigned int MonitPort = 9998; // suivi normal 
 + 
 +const char* ssid1 = "NORD"; 
 +const char* password1 = "blabla"; 
 +const char* ssid2 = "SUD"; 
 +const char* password2 = "blabla"; 
 +const char* ssid3 = "kerminy"; 
 +const char* password3 = "blabla"; 
 +const char* ssid4 = "BIBLIOTEQUE"; 
 +const char* password4 = "blabla"; 
 + 
 +/////// FIN ////////////////////////////////////////////// 
 +////////////////////////////////////////////////////////// 
 +IPAddress mask(255, 255, 255, 0); 
 +//IPAddress passerelle(192, 168, 1, 80); 
 +IPAddress passerelle(192, 168, 1, 13); 
 +const char DEVICE_NAME[] = "PORTE"; 
 +//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:9005 /ouvre ... 
 +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   = 0;   // 
 +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, HIGH);  // Turn the LED off by making the voltage HIGH 
 +  Serial.print("dodo min :"); 
 +  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--] = '\0'; 
 +  do 
 +  { 
 +    s[i] = "0123456789"[pin % 10]; 
 +    --i; 
 +    pin /= 10; 
 +  } 
 +  while (pin && i); 
 +  s[i] = '/'; 
 +  return &s[i]; 
 +
 + 
 +void MonitMsg(char debugbla[], int debugint) { 
 +  sprintf(OSCVar, "/PORTE-%d/%s", noporte, debugbla); 
 +  OSCMessage envoi(OSCVar); 
 +  //envoi.add(debugbla); 
 +  envoi.add(debugint); 
 + 
 +  Udp.beginPacket(MonitIP, MonitPort); 
 +  envoi.send(Udp); 
 +  Udp.endPacket(); 
 +  envoi.empty(); 
 +
 +void Envoyer_status(OSCMessage & msg) { 
 +  if (ouvert == true )     MonitMsg("OUVERT OK", 1); 
 +  if (ferme == true )     MonitMsg("FERME OK", 1); 
 +
 +void Ouvre(OSCMessage & msg) { 
 +  Serial.print("Ouvre"); 
 +  if (digitalRead(D2) == LOW && ouvert == false) { 
 +    analogWrite(enA, 0); // stop 
 +    MonitMsg("OUVRE OK", temps_debut); 
 +    ouvert = true; 
 +    ferme = false; 
 +    Serial.println(" en butee"); 
 +  } else { 
 +    digitalWrite(in1, LOW); 
 +    digitalWrite(in2, HIGH); 
 +    analogWrite(enA, 100); 
 +    temps_debut = millis(); // on arme le temps pour stop si trop long 
 +    MonitMsg("OUVRE", temps_debut); 
 +    ouvre_en_cours = true; 
 +    ferme_en_cours = false; 
 +  } 
 +
 +void Ferme(OSCMessage & msg) { 
 +  Serial.print("Ferme"); 
 +  if (digitalRead(D1) == LOW && ferme == false) { 
 +    analogWrite(enA, 0); // stop 
 +    MonitMsg("FERME OK", temps_debut); 
 +    ouvert = false; 
 +    ferme = true; 
 +    Serial.println(" en butee"); 
 + 
 +  } else { 
 +    digitalWrite(in1, HIGH); 
 +    digitalWrite(in2, LOW); 
 +    analogWrite(enA, 100); 
 +    temps_debut = millis(); // on arme le temps pour stop si trop long 
 +    MonitMsg("FERME", temps_debut); 
 +    ouvre_en_cours = false; 
 +    ferme_en_cours = true; 
 +  } 
 +
 +void Arreter(OSCMessage & msg) { 
 +  analogWrite(enA, 0); 
 +  digitalWrite(in1, LOW); 
 +  digitalWrite(in2, LOW); 
 +  Serial.println("Stop"); 
 +  ouvre_en_cours = false; 
 +  ferme_en_cours = false; 
 +
 +void setup(void) { 
 +  Serial.begin(115200); 
 +  //set led pin as output 
 +  pinMode(enA, OUTPUT); 
 +  pinMode(in1, OUTPUT); 
 +  pinMode(in2, OUTPUT); 
 +  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 
 +  //ticker.attach(0.6, tick);// clignote 
 +  // a cause de OSC sur purdata on garde que des float ! 
 +  Serial.println(F("/ouvert")); 
 +  Serial.println(F("/ferme")); 
 +  Serial.println(F("/status")); 
 + 
 +  temps_milli = millis(); 
 +  pinMode(D0, WAKEUP_PULLUP); 
 + 
 +  WiFi.disconnect(); 
 +  WiFi.mode(WIFI_STA); 
 +  /*wifiMulti.addAP(ssid1, password1); 
 +    wifiMulti.addAP(ssid2, password2); 
 +    wifiMulti.addAP(ssid3, password3); 
 +    wifiMulti.addAP(ssid4, password4); 
 +    Serial.print("tente "); 
 +    Serial.println(ssid1); 
 +    Serial.println(ssid2); 
 +    Serial.println(ssid3); 
 +    Serial.println(ssid4); 
 +  */ 
 +  WiFi.hostname(nomhost);      // DHCP Hostname (useful for finding device for static lease) 
 +  WiFi.begin(ssid2, password1); 
 + 
 +  WiFi.config(porte_ip, passerelle, mask);  // (DNS not required) 
 +  //while (wifiMulti.run() != WL_CONNECTED) { 
 +  while (WiFi.status() != WL_CONNECTED) { 
 + 
 +    delay(500); 
 +    Serial.print("."); 
 +  } 
 +  Serial.println(F("TOUT OK WiFi connected! IP address: ")); 
 +  Serial.println(WiFi.localIP()); 
 +  Serial.println(F(" ")); 
 +  Serial.print(WiFi.hostname()); 
 +  //  Serial.println(F(".local"));porte-1.kerminy.org 
 +  Serial.println(F(".local ou porte-1.kerminy.org")); 
 +  Serial.print(F("sur port :")); 
 +  Serial.println(inPort); 
 +  delay(100); 
 +  Udp.begin(inPort); 
 +  Serial.print(F("Local port: ")); 
 +  Serial.println(Udp.localPort()); 
 + 
 +  // Set up mDNS responder: 
 +  // - first argument is the domain name, in this example 
 +  //   the fully-qualified domain name is "esp8266.local" 
 +  // - second argument is the IP address to advertise 
 +  //   we send our IP address on the WiFi network 
 +  if (!MDNS.begin(WiFi.hostname())) { 
 +    Serial.println("Error setting up MDNS responder!"); 
 +  } 
 +  Serial.println("mDNS responder started"); 
 + 
 +  if (analogRead(A0) > 10) Ouvre; 
 +
 +void loop() { 
 +  //////////// OSC //////////////////////// 
 +  //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("/ouvre", Ouvre); 
 +      msgIN.dispatch("/ferme", Ferme); 
 +      msgIN.dispatch("/status", Envoyer_status); 
 +      msgIN.dispatch("/stop", Arreter); 
 +      Serial.println(size); 
 +    } else { 
 +      Serial.print("error: "); 
 +      Serial.println(msgIN.getError()); 
 +    } 
 +    Udp.flush(); 
 +  } 
 +  if (digitalRead(D2) == LOW  ) { 
 +    analogWrite(enA, 0); // stop 
 +    ouvre_en_cours = false; 
 +    MonitMsg("OUVERT OK", temps_debut); 
 +    ouvert = true; 
 +    ferme = false; 
 +  } 
 +  if (digitalRead(D1) == LOW ) { 
 +    analogWrite(enA, 0); // stop 
 +    ferme_en_cours = false; 
 +    MonitMsg("FERME OK", temps_debut); 
 +    ferme = true; 
 +    ouvert = false; 
 +  } 
 +  //if (ouvre_en_cours || ferme_en_cours) Serial.println(millis() - temps_debut); 
 +  if (digitalRead(D2) == LOW ) Serial.println("OUVERT"); 
 +  if (digitalRead(D1) == LOW ) Serial.println("FERME"); 
 + 
 +  if (ouvre_en_cours == true) Serial.println ("0uvre en cours"); 
 +  if (ferme_en_cours == true) Serial.println ("Ferme en cours"); 
 + 
 +  delay(500); 
 +
 +</code> 
 + 
 +J'etais parti sur la platine wemos sur TB6612 qui encaisse le moteur choisi (0,5A 12V) avec une autre platine d'alimentation [[https://www.wemos.cc/en/latest/d1_mini_shield/dc_power.html|DC shield]] le tout sur une wemos D1 pro, plus simple compacte et avec une bonne portée. 
 + 
 +Mais je l'abandonne suite a de nombreux bug, elle se plante trop souvent
  
 ===== 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 V2.0
   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
ateliers/ouverture_de_portes.txt · Dernière modification : 2024/02/08 17:20 de 127.0.0.1