/* * Code modifié par SB 13/10/2023 * Code ok //verifier si le clignotement de la LED ne bloque pas le DMX (sinon le retirer * * Controle en Wifi par un PC utlisant QLC+ des éléments branché sur bus DMX * Un module DMX/UART grove est cablé sur un M5StickCplus * * This example will receive multiple universes via Artnet and control a strip of ws2811 leds via Adafruit's NeoPixel library: https://github.com/adafruit/Adafruit_NeoPixel This example may be copied under the terms of the MIT license, see the LICENSE file for details */ #include #include #include #include #define LED 10 //Wifi settings const char* ssid = "default";//a verifier const char* password = "";//a verifier //DMX setting /* First, lets define the hardware pins that we are using with our ESP32. We need to define which pin is transmitting data and which pin is receiving data. DMX circuits also often need to be told when we are transmitting and when we are receiving data. We can do this by defining an enable pin. */ int transmitPin = 33; int receivePin = 32; int enablePin = 21; /* Make sure to double-check that these pins are compatible with your ESP32! Some ESP32s, such as the ESP32-WROVER series, do not allow you to read or write data on pins 16 or 17, so it's always good to read the manuals. */ /* Next, lets decide which DMX port to use. The ESP32 has either 2 or 3 ports. Port 0 is typically used to transmit serial data back to your Serial Monitor, so we shouldn't use that port. Lets use port 1! */ dmx_port_t dmxPort = 1; /* Now we want somewhere to store our DMX data. Since a single packet of DMX data can be up to 513 bytes long, we want our array to be at least that long. This library knows that the max DMX packet size is 513, so we can fill in the array size with `DMX_PACKET_SIZE`. */ byte dataDMX[DMX_PACKET_SIZE]; byte valDMX = 0;//valeur DMX /* This variable will allow us to update our packet and print to the Serial Monitor at a regular interval. */ unsigned long lastUpdate = millis(); //fin DMXsetting // Artnet settings ArtnetWifi artnet; const int startUniverse = 1; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0. // connect to wifi – returns true if successful or false if not bool ConnectWifi(void) { bool state = true; int i = 0; WiFi.begin(ssid, password); Serial.println(""); Serial.println("Connecting to WiFi"); // Wait for connection Serial.print("Connecting"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); if (i > 20){ state = false; break; } i++; } if (state){ Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); } else { Serial.println(""); Serial.println("Connection failed."); } return state; } /***************************************************************************************/ void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data) { /* Get the current time since boot in milliseconds so that we can find out how long it has been since we last updated data and printed to the Serial Monitor. */ unsigned long now = millis(); if (now - lastUpdate >= 1000) { //SB dmx_write(dmxPort, data, DMX_PACKET_SIZE); /* Log our changes to the Serial Monitor. */ lastUpdate = now; } /* Now we can transmit the DMX packet! */ dmx_send(dmxPort, DMX_PACKET_SIZE); /* We can do some other work here if we want. */ /* If we have no more work to do, we will wait until we are done sending our DMX packet. */ dmx_wait_sent(dmxPort, DMX_TIMEOUT_TICK); }//onDmxFrame /********************************************************************************/ void setup() { Serial.begin(115200); pinMode(LED, OUTPUT); ConnectWifi(); artnet.begin(); //M5 Lcd M5.begin(); M5.Lcd.setRotation(3); M5.Lcd.setTextSize(2); M5.Lcd.setCursor(20,2); M5.Lcd.println("DMX connect"); M5.Lcd.println("par ARTNET Wifi"); M5.Lcd.println(" version 231013"); //affichage vers LCD adresseIP IPAddress ipAdr; ipAdr = WiFi.localIP(); M5.Lcd.fillRect(0,110,240,25,BLACK); M5.Lcd.setCursor(0,110); M5.Lcd.setTextSize(2); M5.Lcd.setTextColor(BLUE); M5.Lcd.printf("IP:%u.%u.%u.%u\n\r",ipAdr[0],ipAdr[1],ipAdr[2],ipAdr[3]); /* Set the DMX hardware pins to the pins that we want to use. */ dmx_set_pin(dmxPort, transmitPin, receivePin, enablePin); /* Now we can install the DMX driver! We'll tell it which DMX port to use and which interrupt priority it should have. If you aren't sure which interrupt priority to use, you can use the macro `DMX_DEFAULT_INTR_FLAG` to set the interrupt to its default settings.*/ dmx_driver_install(dmxPort, DMX_DEFAULT_INTR_FLAGS); // this will be called for each packet received artnet.setArtDmxCallback(onDmxFrame); } void loop() { // we call the read function inside the loop artnet.read(); digitalWrite(LED, HIGH); delay(500); digitalWrite(LED, LOW); delay(500); //Serial.print("arnetLength="); Serial.println(artnet.getLength()); }