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, | ||
+ | |||
+ | attention au temps ms d' | ||
+ | |||
+ | j'y ai un début de fonction OSC | ||
+ | |||
+ | < | ||
+ | /* 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 < | ||
+ | #include < | ||
+ | //#include < | ||
+ | //#include < | ||
+ | // OSC | ||
+ | //#include < | ||
+ | //#include < | ||
+ | //#include < | ||
+ | //#include < | ||
+ | |||
+ | // | ||
+ | /////////////////////////////////////////////////////////// | ||
+ | // DEFINITION DU diaporobot A MODIFIER // | ||
+ | |||
+ | // int sortie[9] | ||
+ | // 0,1,2... ok pour 1,2,4,5,6,7 pas 0 3 8 | ||
+ | int sortie[9] | ||
+ | |||
+ | int tiroir[6] | ||
+ | int sens[6] | ||
+ | int freq_mini[6] | ||
+ | int freq_maxi[6] | ||
+ | int idx_diapo[6] | ||
+ | int freq_diapo[6] | ||
+ | int idx_bcl_diapo[6] = {1, 1, 1, 1, 1, 1}; // num de la boucle en cours | ||
+ | |||
+ | uint32_t bton_court | ||
+ | uint32_t bton_long = 1000 ; //temps ms d' | ||
+ | |||
+ | // SI OSC | ||
+ | // nom DIAPOROBOT-1 pour IP 192.168.0.121 | ||
+ | // DIAPOROBOT-2 pour IP 192.168.0.122 | ||
+ | // | ||
+ | const char* nomhost = " | ||
+ | |||
+ | IPAddress diaporobot_ip(192, | ||
+ | |||
+ | char osc_port[6] = " | ||
+ | const char* ssid = " | ||
+ | const char* password = " | ||
+ | |||
+ | /////// FIN ////////////////////////////////////////////// | ||
+ | ////////////////////////////////////////////////////////// | ||
+ | /*IPAddress mask(255, 255, 255, 0); | ||
+ | IPAddress passerelle(192, | ||
+ | |||
+ | const char DEVICE_NAME[] = " | ||
+ | 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--] = ' | ||
+ | do | ||
+ | { | ||
+ | s[i] = " | ||
+ | --i; | ||
+ | pin /= 10; | ||
+ | } | ||
+ | while (pin && i); | ||
+ | s[i] = '/'; | ||
+ | return &s[i]; | ||
+ | } | ||
+ | void saveConfigCallback () { | ||
+ | Serial.println(" | ||
+ | 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] = idx; | ||
+ | } | ||
+ | |||
+ | void arreter(OSCMessage & msg) { | ||
+ | |||
+ | } | ||
+ | */ | ||
+ | ////////////////// | ||
+ | /* | ||
+ | void diapo_boucle(OSCMessage & msg) { | ||
+ | Serial.println("/ | ||
+ | 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, | ||
+ | // | ||
+ | // | ||
+ | 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(" | ||
+ | Serial.println(F(" | ||
+ | |||
+ | for (int i = 0; i <= 8; i++) { // //ok pour 1,2,4,5,6,7 | ||
+ | if ( i == 3 || i == 8) continue ; | ||
+ | pinMode(sortie[i], | ||
+ | // | ||
+ | digitalWrite(sortie[i], | ||
+ | |||
+ | } | ||
+ | // | ||
+ | /* on fixe tout pour installation | ||
+ | |||
+ | WiFiManager wifiManager; | ||
+ | if (BoutonParam >= 15) { | ||
+ | Serial.println(F(" | ||
+ | wifiManager.resetSettings(); | ||
+ | Serial.println(F(" | ||
+ | // | ||
+ | //set custom ip for portal | ||
+ | // | ||
+ | } | ||
+ | //fetches ssid and pass from eeprom and tries to connect | ||
+ | //if it does not connect it starts an access point with the specified name | ||
+ | // | ||
+ | //and goes into a blocking loop awaiting configuration | ||
+ | wifiManager.autoConnect(DEVICE_NAME); | ||
+ | //or use this for auto generated name ESP + ChipID | ||
+ | // | ||
+ | |||
+ | */ | ||
+ | WiFi.disconnect(); | ||
+ | /* | ||
+ | Serial.print(F(" | ||
+ | Serial.println(ssid); | ||
+ | WiFi.begin(ssid, | ||
+ | WiFi.mode(WIFI_STA); | ||
+ | WiFi.hostname(nomhost); | ||
+ | WiFi.config(diaporobot_ip, | ||
+ | while (WiFi.status() != WL_CONNECTED) { | ||
+ | delay(500); | ||
+ | Serial.print(" | ||
+ | } | ||
+ | osc_port_int = atoi(osc_port); | ||
+ | Serial.println(F(" | ||
+ | Serial.println(WiFi.localIP()); | ||
+ | Serial.println(WiFi.hostname()); | ||
+ | Serial.print(F(" | ||
+ | Serial.println(osc_port); | ||
+ | delay(100); | ||
+ | Udp.begin(osc_port_int); | ||
+ | Serial.print(F(" | ||
+ | Serial.println(Udp.localPort()); | ||
+ | */ | ||
+ | // | ||
+ | for (int idx = 1; idx <= 4; idx++) { | ||
+ | freq_diapo[idx] | ||
+ | // | ||
+ | // | ||
+ | digitalWrite(sortie[idx], | ||
+ | Serial.print(" | ||
+ | Serial.println(sortie[idx]); | ||
+ | } | ||
+ | } | ||
+ | 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("/ | ||
+ | Serial.println(size); | ||
+ | } else { | ||
+ | error = msgIN.getError(); | ||
+ | Serial.print(" | ||
+ | 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(" | ||
+ | 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], | ||
+ | Serial.print(" | ||
+ | Serial.print(sortie[i]); | ||
+ | Serial.print(" | ||
+ | if (sens[i] > 0) { | ||
+ | Serial.print(" | ||
+ | delay(bton_court); | ||
+ | } | ||
+ | else { | ||
+ | Serial.print(" | ||
+ | delay(bton_long); | ||
+ | } | ||
+ | digitalWrite(sortie[i], | ||
+ | |||
+ | idx_diapo[i] += 1; | ||
+ | idx_bcl_diapo[i] = 0; | ||
+ | Serial.print(" | ||
+ | freq_diapo[i] = (int)random(freq_mini[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(" | ||
+ | } | ||
+ | Serial.println(" | ||
+ | } | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | ===== Version arduino ===== | ||
+ | **Sortie 9, | ||
+ | |||
+ | < | ||
+ | /* Arduino Uno | ||
+ | | ||
+ | | ||
+ | */ | ||
+ | |||
+ | |||
+ | // ESP8266 int sortie[9] | ||
+ | // 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] | ||
+ | |||
+ | int tiroir[9] | ||
+ | int sens[9] | ||
+ | |||
+ | |||
+ | int freq_mini[9] | ||
+ | int freq_maxi[9] | ||
+ | |||
+ | int idx_diapo[9] | ||
+ | int freq_diapo[9] | ||
+ | int idx_bcl_diapo[9] = {1, 1, 1, 1, 1, 1}; // num de la boucle en cours | ||
+ | |||
+ | uint32_t bton_court | ||
+ | uint32_t bton_long = 1000 ; //temps ms d' | ||
+ | |||
+ | |||
+ | |||
+ | 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], | ||
+ | // | ||
+ | digitalWrite(sortie[i], | ||
+ | Serial.print(" | ||
+ | Serial.print(sortie[i]); | ||
+ | } | ||
+ | Serial.println("" | ||
+ | Serial.println(" | ||
+ | for (int i = 1; i <= nbr_relais; i++) { | ||
+ | delay(1000); | ||
+ | digitalWrite(sortie[i], | ||
+ | delay(bton_court); | ||
+ | digitalWrite(sortie[i], | ||
+ | delay(bton_court); | ||
+ | digitalWrite(sortie[i], | ||
+ | } | ||
+ | Serial.println(" | ||
+ | for (int idx = 1; idx <= nbr_relais; idx++) { | ||
+ | freq_diapo[idx] | ||
+ | // | ||
+ | // | ||
+ | digitalWrite(sortie[idx], | ||
+ | Serial.print(" | ||
+ | Serial.print(sortie[idx]); | ||
+ | Serial.print(" | ||
+ | Serial.println(freq_diapo[idx]); | ||
+ | } | ||
+ | Serial.println(" | ||
+ | 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(" | ||
+ | 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], | ||
+ | Serial.print(" | ||
+ | Serial.print(sortie[i]); | ||
+ | Serial.print(" | ||
+ | if (sens[i] > 0) { | ||
+ | Serial.print(" | ||
+ | delay(bton_court); | ||
+ | } | ||
+ | else { | ||
+ | Serial.print(" | ||
+ | delay(bton_long); | ||
+ | } | ||
+ | digitalWrite(sortie[i], | ||
+ | |||
+ | idx_diapo[i] += 1; | ||
+ | idx_bcl_diapo[i] = 0; | ||
+ | Serial.print(" | ||
+ | freq_diapo[i] = (int)random(freq_mini[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(" | ||
+ | } | ||
+ | Serial.println(" | ||
+ | } | ||
+ | Serial.println(" | ||
+ | } | ||
+ | </ |
esp8266/relais-diapo.txt · Dernière modification : 2024/02/09 17:10 de 127.0.0.1