diff --git a/examples/DMX_Send/DMX_Send.ino b/examples/DMX_Send/DMX_Send.ino index b4cdf00..f9b3584 100644 --- a/examples/DMX_Send/DMX_Send.ino +++ b/examples/DMX_Send/DMX_Send.ino @@ -4,9 +4,11 @@ // Copyright (C) 2015 Rick // This work is licensed under a GNU style license. // -// Last change: Marcel Seerig (edited by Marcel Seerig) +// Last change: Musti (edited by Musti) // // Documentation and samples are available at https://github.com/Rickgg/ESP-Dmx +// Connect GPIO02 - TDX1 to MAX3485 or other driver chip to interface devices +// Pin is defined in library // - - - - - #include @@ -14,7 +16,8 @@ DMXESPSerial dmx; void setup() { - dmx.init(); // initialization + dmx.init(); // initialization for first 32 addresses by default + //dmx.init(512) // initialization for complete bus delay(200); // wait a while (not necessary) } @@ -24,7 +27,7 @@ void loop() { dmx.write(1, 255); // channal 1 on dmx.update(); // update the DMX bus delay(1000); // wait for 1s - + dmx.write(1, 0); dmx.write(2, 255); dmx.update(); diff --git a/examples/RGB_DMX/README.md b/examples/RGB_DMX/README.md new file mode 100644 index 0000000..5e23000 --- /dev/null +++ b/examples/RGB_DMX/README.md @@ -0,0 +1,9 @@ +# RGB DMX example # + +This example implements a web interface based on websockets and allows user to enter the channel and set RGB values, sent on the configured channel and two sequential ones as per general implementation practice in DMX. + +You require and external RS485 driver IC to interface standard DMX equipment. + +To use thix example [ESP-Dmx](https://github.com/IRNAS/ESP-Dmx) and [arduinoWebSockets](https://github.com/Links2004/arduinoWebSockets) libraties are required. + +![interface](rgbdmx.png) diff --git a/examples/RGB_DMX/RGB_DMX.ino b/examples/RGB_DMX/RGB_DMX.ino new file mode 100644 index 0000000..0c99b57 --- /dev/null +++ b/examples/RGB_DMX/RGB_DMX.ino @@ -0,0 +1,125 @@ +/* This example joins two useful libraries for ESP8266 WiFi Module + * Websockets library for interfacing from either web interface or + * some external application and DMX library for controlling + * devices on a DMX bus. + * + * Install these libraries: + * https://github.com/Links2004/arduinoWebSockets + * https://github.com/Rickgg/ESP-Dmx + * + * Web interface allow one to set the channel and control an RGB + * light, assuming channels for colors follow one after eachother + * + * How to use: + * 1) Change WiFi settings accordingly to connect to your network + * 2) Connect an RS485 driver chip to GPIO02( D4 on Nodemcu 1.0) + * 3) Check out the serial output for IP or + * visit http://rgbdmx.local if your device supports mDNS and + * you are in the same local network + +Copyright Institute IRNAS Rače 2016 - info@irnas.eu + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. +You should have received a copy of the GNU General Public License +along with this program. If not, see .*/ + + +#include +#include +#include +#include +#include +#include +#include + +// WiFi network settings +const char* ssid = "SSID"; +const char* password = "password"; + +DMXESPSerial dmx; +ESP8266WiFiMulti WiFiMulti; +ESP8266WebServer server = ESP8266WebServer(80); +WebSocketsServer webSocket = WebSocketsServer(81); + +void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t lenght) { + switch(type) { + case WStype_DISCONNECTED: + Serial.println("Disconnected!"); + break; + case WStype_CONNECTED: + Serial.println("Client connected!"); + // send message to client + webSocket.sendTXT(num, "Connected"); + break; + case WStype_TEXT: + // # is the start for this data + if(payload[0] == '#') { + //data received is comma separated, thats why we do pEnd+1 to start next value + char * pEnd; + uint32_t address = strtol ((const char *) &payload[1],&pEnd,16); + uint32_t red = strtol ((const char *) pEnd+1,&pEnd,16); + uint32_t green = strtol ((const char *) pEnd+1,&pEnd,16); + uint32_t blue = strtol ((const char *) pEnd+1,&pEnd,16); + //write to DMX bus + dmx.write(address, red); + dmx.write(address+1, green); + dmx.write(address+2, blue); + dmx.update(); + } + break; + } +} + +void setup() { + Serial.begin(115200); + Serial.println(); + + // connect to WiFi + WiFi.hostname("rgbdmx"); + WiFi.mode(WIFI_STA); + WiFi.begin(ssid, password); + // wait for connection to be established + while(WiFi.waitForConnectResult() != WL_CONNECTED){ + WiFi.begin(ssid, password); + Serial.println("WiFi connection failed, retrying."); + delay(500); + } + + // start webSocket server + webSocket.begin(); + webSocket.onEvent(webSocketEvent); + + if(MDNS.begin("rgbdmx")) { + Serial.println("MDNS responder started"); + } + + // handle index + server.on("/", []() { + // send index.html + server.send(200, "text/html", "LED Control:

Starting address:
R:
G:
B:
"); + }); + + server.begin(); + MDNS.addService("http", "tcp", 80); + MDNS.addService("ws", "tcp", 81); + + dmx.init(512); // initialize with bus length + + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); + Serial.print("RSSI: "); + Serial.print(WiFi.RSSI()); + Serial.println(" dBm"); +} + +void loop() { + webSocket.loop(); + server.handleClient(); +} diff --git a/examples/RGB_DMX/rgbdmx.png b/examples/RGB_DMX/rgbdmx.png new file mode 100644 index 0000000..5c270a8 Binary files /dev/null and b/examples/RGB_DMX/rgbdmx.png differ