Outils pour utilisateurs

Outils du site


esp8266:relais-diapo
no way to compare when less than two revisions

Différences

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


esp8266:relais-diapo [2024/02/09 17:10] (Version actuelle) – créée - modification externe 127.0.0.1
Ligne 1: Ligne 1:
 +====== 4 relais pour commande de projecteurs de diapo en mode aléatoire ======
 +===== Version ESP8266 =====
 +  * esp Wemos mini D1
 +  * Platine 4 relais
 +on se branche sur la fiche du projecteur 2,3 , détrompeur en bas, en commençant a gauche, impulsion courte pour diapo suivante , longue pour diapo précédente. Le tiroir contient 50 diapositives
  
 +Sur les sorties 2,0,13,14  => D4,D3,D7,D5
 +
 +attention au temps ms d'appui bouton pour diapo suivante et precedente selon le projecteur
 +
 +j'y ai un début de fonction OSC
 +
 +<code>
 +/* Diaporobot
 +  gepeto@du-libre.org 2020
 +  Automate de commande de relais
 +  pour des impulsions de commande
 +  pour 4 projecteurs de diapositives
 +
 +  Matériel: ESP Wemos + platine 4 relais
 +*/
 +#include <FS.h>
 +#include <ESP8266WiFi.h>
 +//#include <WiFiUdp.h>
 +//#include <DNSServer.h>
 +// OSC
 +//#include <OSCMessage.h>
 +//#include <OSCBundle.h>
 +//#include <OSCData.h>
 +//#include <WiFiManager.h>
 +
 +//
 +///////////////////////////////////////////////////////////
 +// DEFINITION DU diaporobot A MODIFIER //
 +
 +// int sortie[9]    = {16, 5, 4, 0, 2, 14, 12, 13, 15}; // sortie possible
 +// 0,1,2... ok pour 1,2,4,5,6,7 pas 0 3 8
 +int sortie[9]    = {15, 2, 0, 13, 14, 5, 12, 13, 4};
 +
 +int tiroir[6]        = {50, 50, 50, 50, 50, 50}; // nbr de diapo dans les chargeurs
 +int sens[6]          = {1, 1, 1, 1, 1, 1}; //sens de passage du tiroir
 +int freq_mini[6]     = {30, 30, 30, 30, 30, 30}; // min 30s entre 2 diapo
 +int freq_maxi[6]     = {180, 180, 180, 180, 180, 180}; // max 180
 +int idx_diapo[6]     = {1, 1, 1, 1, 1, 1}; // index dans le chargeur de diapo
 +int freq_diapo[6]    = {1, 1, 1, 1, 1, 1}; // nbr ( s)  entre 2 diapo
 +int idx_bcl_diapo[6] = {1, 1, 1, 1, 1, 1}; // num de la boucle en cours
 +
 +uint32_t bton_court   = 200 ; //temps ms d'appui bouton pour diapo suivante
 +uint32_t bton_long = 1000 ; //temps ms d'appui bouton pour diapo precedente
 +
 +//  SI OSC
 +//  nom DIAPOROBOT-1 pour IP 192.168.0.121
 +//      DIAPOROBOT-2 pour IP 192.168.0.122   etc
 +//
 +const char* nomhost = "DIAPOROBOT-1";
 +
 +IPAddress diaporobot_ip(192, 168, 0, 121);
 +
 +char osc_port[6] = "9005"; // si besoin
 +const char* ssid     = "SNHACK";
 +const char* password = "opopop";
 +
 +/////// FIN //////////////////////////////////////////////
 +//////////////////////////////////////////////////////////
 +/*IPAddress mask(255, 255, 255, 0);
 +  IPAddress passerelle(192, 168, 0, 1);
 +
 +  const char DEVICE_NAME[] = "DIAPOROBOT";
 +  int osc_port_int = 0;
 +
 +  WiFiUDP Udp;     // A UDP instance to let us send and receive packets over UDP
 +  const IPAddress outIp(192, 168, 1, 3);     // remote IP to receive OSC
 +  IPAddress _ip;
 +  OSCErrorCode error;
 +  bool shouldSaveConfig = true;
 +*/
 +/*
 +  //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 saveConfigCallback () {
 +  Serial.println("Should save config");
 +  shouldSaveConfig = true;
 +  }
 +  void mod_idx_bcl(OSCMessage & msg) {// IDX ff projo position dans le chargeur
 +  long proj = (long) msg.getFloat(0);
 +  long idx = (long) msg.getFloat(1);
 +  if (idx <= 0 || idx >= tiroir)   idx_diapo[proj] = 1;
 +  idx_diapo[proj] = idx;
 +  }
 +
 +  void arreter(OSCMessage & msg) {
 +
 +  }
 +*/
 +////////////////// OSC commandes//////////////
 +/*
 +  void diapo_boucle(OSCMessage & msg) {
 +  Serial.println("/DIAPO");
 +  long dia = (long) msg.getFloat(0);
 +  if (dia <= 0 || dia >= 5) {
 +    dia = 1;
 +  }
 +  if (dia == 1) {
 +    tk_bcl_diapo_1.detach();
 +    tk_bcl_diapo_1.attach_ms(1000 * dia, pulse_dia_pin_1);
 +  }
 +  if (dia == 2) {
 +    tk_bcl_diapo_2.detach();
 +    tk_bcl_diapo_2.attach_ms(1000 * dia, pulse_dia_pin_2);
 +  }
 +  if (dia == 3) {
 +    tk_bcl_diapo_3.detach();
 +    tk_bcl_diapo_3.attach_ms(1000 * dia, pulse_dia_pin_3);
 +  }
 +  if (dia == 4) {
 +    tk_bcl_diapo_4.detach();
 +    tk_bcl_diapo_4.attach_ms(1000 * dia, pulse_dia_pin_4);
 +  }
 +  }
 +*/
 +
 +void setup(void) {
 +  Serial.begin(115200);
 +  //set led pin as output
 +  pinMode(BUILTIN_LED, OUTPUT);
 +  //pinMode(Bouton_init, INPUT);
 +  //BoutonParam = HIGH;
 +  Serial.println((int32_t)ESP.getChipId());
 +  delay(1000);
 +  int BoutonParam = analogRead(A0);
 +
 +  // a cause de OSC sur purdata on garde que des float !
 +  Serial.println(F("sorties :  2,0,13,14"));
 +  Serial.println(F("init des sorties"));
 +
 +  for (int i = 0; i <= 8; i++) { //  //ok pour 1,2,4,5,6,7
 +    if ( i == 3 || i == 8) continue ;
 +    pinMode(sortie[i], OUTPUT);
 +    //analogWrite(sortie[i], 0);
 +    digitalWrite(sortie[i], HIGH);
 +
 +  }
 +  //WiFiManager
 +  /* on fixe tout pour installation
 +
 +    WiFiManager wifiManager;
 +    if (BoutonParam >= 15) {
 +    Serial.println(F("PARAM "));    //reset saved settings
 +    wifiManager.resetSettings();
 +    Serial.println(F("WIfi param reset "));
 +    //ticker.attach_ms(1000*0.2, tick);
 +    //set custom ip for portal
 +    //wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
 +    }
 +    //fetches ssid and pass from eeprom and tries to connect
 +    //if it does not connect it starts an access point with the specified name
 +    //here  "AutoConnectAP"
 +    //and goes into a blocking loop awaiting configuration
 +    wifiManager.autoConnect(DEVICE_NAME);
 +    //or use this for auto generated name ESP + ChipID
 +    //wifiManager.autoConnect();
 +
 +  */
 +  WiFi.disconnect();
 +  /*
 +    Serial.print(F("ssid : "));
 +    Serial.println(ssid);
 +    WiFi.begin(ssid, password);
 +    WiFi.mode(WIFI_STA);
 +    WiFi.hostname(nomhost);      // DHCP Hostname (useful for finding device for static lease)
 +    WiFi.config(diaporobot_ip, passerelle, mask);  // (DNS not required)
 +    while (WiFi.status() != WL_CONNECTED) {
 +    delay(500);
 +    Serial.print(".");
 +    }
 +    osc_port_int = atoi(osc_port);
 +    Serial.println(F("TOUT OK WiFi connected! IP address: "));
 +    Serial.println(WiFi.localIP());
 +    Serial.println(WiFi.hostname());
 +    Serial.print(F("sur port :"));
 +    Serial.println(osc_port);
 +    delay(100);
 +    Udp.begin(osc_port_int);
 +    Serial.print(F("Local port: "));
 +    Serial.println(Udp.localPort());
 +  */
 +  //
 +  for (int idx = 1; idx <= 4; idx++) {
 +    freq_diapo[idx]        = (int)random(freq_mini[idx], freq_maxi[idx]); // frequence
 +    //idx_bcl_diapo[idx]     = 1;                        // nbr de boucle en cours
 +    //idx_diapo[idx]         = 1;                        // position dans le chargeur
 +    digitalWrite(sortie[idx], HIGH);
 +    Serial.print(" sortie: ");
 +    Serial.println(sortie[idx]);
 +  }
 +}
 +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("/IDX", mod_idx_bcl); // /IDX ff projo position_diapo_ds le chargeur
 +      msgIN.dispatch("/stop", arreter);
 +      Serial.println(size);
 +    } else {
 +      error = msgIN.getError();
 +      Serial.print("error: ");
 +      Serial.println(error);
 +    }
 +    Udp.flush();
 +    }
 +  */
 +
 +  /// une boucle fait 1 en gros seconde
 +  delay(1000);
 +
 +  for (int i = 1; i <= 4; i++) {
 +
 +    if (sens[i] < 0) Serial.print("-");
 +    Serial.print(idx_diapo[i]);
 +    Serial.print("\t");
 +    Serial.print(idx_bcl_diapo[i]);
 +    Serial.print("/");
 +    Serial.print(freq_diapo[i]);
 +
 +    if (idx_bcl_diapo[i] == freq_diapo[i] ) { //  frequence ok?
 +      digitalWrite(sortie[i], LOW);
 +      Serial.print(" ");
 +      Serial.print(sortie[i]);
 +      Serial.print(" ");
 +      if (sens[i] > 0) {
 +        Serial.print(" AVV ");
 +        delay(bton_court);
 +      }
 +      else {
 +        Serial.print(" ARR ");
 +        delay(bton_long);
 +      }
 +      digitalWrite(sortie[i], HIGH);
 +
 +      idx_diapo[i] += 1;
 +      idx_bcl_diapo[i] = 0;
 +      Serial.print(" chg bcl ");
 +      freq_diapo[i] = (int)random(freq_mini[i], freq_maxi[i]);
 +      Serial.print(freq_diapo[i]);
 +    }
 +    idx_bcl_diapo[i] += 1;
 +
 +    if (idx_diapo[i] >= tiroir[i]) { // si arrive au bout du chargeur change de sens
 +      idx_diapo[i] = 1;
 +      sens[i] = -sens[i];
 +      Serial.print(" tiroir");
 +    }
 +    Serial.println(".");
 +  }
 +  Serial.println("---");
 +}
 +
 +</code>
 +===== Version arduino =====
 +**Sortie 9,10,11,13**
 +
 +<code>
 +/* Arduino Uno
 +  commande alléatoire de relais pour projecteur de diapo
 +  1 ou 2 carte de 4 relais
 + */
 +
 + 
 +// ESP8266 int sortie[9]    = {16, 5, 4, 0, 2, 14, 12, 13, 15}; // sortie possible
 +// 0,1,2... ok pour 1,2,4,5,6,7 pas 0 3 8
 +
 +int nbr_relais = 4; // si une carte 4 relais
 +
 +int sortie[9]    = {13, 9, 10, 11, 13, 13, 11, 13, 13};
 +
 +int tiroir[9]        = {50, 50, 50, 50, 50, 50}; // nbr de diapo dans les chargeurs
 +int sens[9]          = {1, 1, 1, 1, 1, 1}; //sens de passage du tiroir
 +
 +
 +int freq_mini[9]     = {30, 30, 30, 30, 30, 30}; // min 30s entre 2 diapo
 +int freq_maxi[9]     = {180, 180, 180, 180, 180, 180}; // max 180
 +
 +int idx_diapo[9]     = {1, 1, 1, 1, 1, 1}; // index dans le chargeur de diapo
 +int freq_diapo[9]    = {1, 1, 1, 1, 1, 1}; // nbr ( s)  entre 2 diapo
 +int idx_bcl_diapo[9] = {1, 1, 1, 1, 1, 1}; // num de la boucle en cours
 +
 +uint32_t bton_court   = 200 ; //temps ms d'appui bouton pour diapo suivante
 +uint32_t bton_long = 1000 ; //temps ms d'appui bouton pour diapo precedente
 +
 +
 +
 +void setup() {
 +  Serial.begin(115200);
 +
 +  for (int i = 0; i <= nbr_relais; i++) { //  //ok pour 1,2,4,5,6,7
 +    // ESP if ( i == 3 || i == 8) continue ;
 +    pinMode(sortie[i], OUTPUT);
 +    //analogWrite(sortie[i], 0);
 +    digitalWrite(sortie[i], HIGH);
 +    Serial.print(" ");
 +    Serial.print(sortie[i]);
 +  }
 +  Serial.println("");
 +  Serial.println("Test");
 +  for (int i = 1; i <= nbr_relais; i++) {
 +    delay(1000);
 +    digitalWrite(sortie[i], HIGH);
 +    delay(bton_court);
 +    digitalWrite(sortie[i], LOW);
 +    delay(bton_court);
 +    digitalWrite(sortie[i], HIGH);
 +  }
 +  Serial.println("init random");
 +  for (int idx = 1; idx <= nbr_relais; idx++) {
 +    freq_diapo[idx]        = (int)random(freq_mini[idx], freq_maxi[idx]); // frequence
 +    //idx_bcl_diapo[idx]     = 1;                        // nbr de boucle en cours
 +    //idx_diapo[idx]         = 1;                        // position dans le chargeur
 +    digitalWrite(sortie[idx], HIGH);
 +    Serial.print(" sortie: ");
 +    Serial.print(sortie[idx]);
 +    Serial.print(" delai: ");
 +    Serial.println(freq_diapo[idx]);
 +  }
 +  Serial.println("10s");
 +  delay(10000);
 +}
 +
 +void loop() {
 +  delay(1000);
 +
 +  for (int i = 1; i <= nbr_relais; i++) {
 +
 +    if (sens[i] < 0) Serial.print("-");
 +    Serial.print(idx_diapo[i]);
 +    Serial.print("\t");
 +    Serial.print(idx_bcl_diapo[i]);
 +    Serial.print("/");
 +    Serial.print(freq_diapo[i]);
 +
 +    if (idx_bcl_diapo[i] == freq_diapo[i] ) { //  frequence ok?
 +      digitalWrite(sortie[i], LOW);
 +      Serial.print(" ");
 +      Serial.print(sortie[i]);
 +      Serial.print(" ");
 +      if (sens[i] > 0) {
 +        Serial.print(" AVV ");
 +        delay(bton_court);
 +      }
 +      else {
 +        Serial.print(" ARR ");
 +        delay(bton_long);
 +      }
 +      digitalWrite(sortie[i], HIGH);
 +
 +      idx_diapo[i] += 1;
 +      idx_bcl_diapo[i] = 0;
 +      Serial.print(" chg bcl ");
 +      freq_diapo[i] = (int)random(freq_mini[i], freq_maxi[i]);
 +      Serial.print(freq_diapo[i]);
 +    }
 +    idx_bcl_diapo[i] += 1;
 +
 +    if (idx_diapo[i] >= tiroir[i]) { // si arrive au bout du chargeur change de sens
 +      idx_diapo[i] = 1;
 +      sens[i] = -sens[i];
 +      Serial.print(" tiroir");
 +    }
 +    Serial.println(".");
 +  }
 +  Serial.println("---");
 +}
 +</code>
esp8266/relais-diapo.txt · Dernière modification : 2024/02/09 17:10 de 127.0.0.1