Skip to content

Instantly share code, notes, and snippets.

@hpwit
Last active December 28, 2018 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hpwit/79cb0fcf0848466479ea4ff7a10db8a1 to your computer and use it in GitHub Desktop.
Save hpwit/79cb0fcf0848466479ea4ff7a10db8a1 to your computer and use it in GitHub Desktop.
Adaptation for up to 31 universes
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#define WSout1 2 // Pin GPIO2
#define WSout2 2
#define WSout3 2
#define WSout4 2
//#define WSout5 2
#define WSbit1 (1<<WSout1)
#define WSbit2 (1<<WSout2)
#define WSbit3 (1<<WSout3)
#define WSbit4 (1<<WSout4)
//#define WSbit5 (1<<WSout5)
// ARTNET CODES
#define ARTNET_DATA 0x50
#define ARTNET_POLL 0x20
#define ARTNET_POLL_REPLY 0x21
#define ARTNET_PORT 6454
#define ARTNET_HEADER 17
#define NUM_UNIVERSES 8
#define SIZE_UNIVERSE 170 //in pixels
#define NUM_LEDS 1280
#define MAX_ARTNET_SIZE 600
WiFiUDP udp;
uint8_t leds[NUM_LEDS*3]; //3 bytes per pixels
uint8_t hData[MAX_ARTNET_SIZE]; //[ARTNET_HEADER + 1];
uint8_t net = 0;
uint8_t subnet = 3;
uint32_t sync=0;
const char* ssid = "";
const char* password = "";
IPAddress local_ip(192,168, 1, 115);
IPAddress gateway_ip(192,168, 1, 1);
IPAddress subnet_ip(255, 255, 255, 0);
void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
WiFi.config(local_ip, gateway_ip, subnet_ip);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
udp.begin(ARTNET_PORT); // Open ArtNet port
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
//is is necessary as all your PIN are the same ?
pinMode(WSout1, OUTPUT);
//Create the Mask for the sync
sync=(1<<NUM_UNIVERSES)-1;
}
void displayleds() {
uint32_t writeBits;
uint8_t bitMask, time;
os_intr_lock();
for (uint16_t t = 0; t < NUM_LEDS*3; t++) { // outer loop counting bytes
bitMask = 0x80;
while (bitMask) {
// time=0ns : start by setting bit on
time = 4;
while (time--) {
WRITE_PERI_REG( 0x60000304, WSbit1 ); // do ON bits // T=0
}
if ( leds[t] & bitMask ) {
writeBits = 0; // if this is a '1' keep the on time on for longer, so dont write an off bit
}
else {
writeBits = WSbit1; // else it must be a zero, so write the off bit !
}
time = 4;
while (time--) {
WRITE_PERI_REG( 0x60000308, writeBits ); // do OFF bits // T='0' time 350ns
}
time = 6;
while (time--) {
WRITE_PERI_REG( 0x60000308, WSbit1 ); // switch all bits off T='1' time 700ns
}
// end of bite write time=1250ns
bitMask >>= 1;
}
}
os_intr_unlock();
}
void loop() {
uint32_t syncval=0;
while(syncval!=sync) {
if (udp.parsePacket()) {
udp.read(hData, MAX_ARTNET_SIZE);
if ( hData[0] == 'A' && hData[1] == 'r' && hData[2] == 't' && hData[3] == '-' && hData[4] == 'N' && hData[5] == 'e' && hData[6] == 't') {
if ( hData[8] == 0x00 && hData[9] == ARTNET_DATA && hData[15] == net ) {
int incomingUniverse=(hData[14])-(subnet<<4); //we retrieve the universe
int size=(hData[16] << 8) + (hData[17]);
if(size>0)
{
if(incomingUniverse<NUM_UNIVERSES) //to avoid any issue
{
memcpy(&leds[SIZE_UNIVERSE*3*incomingUniverse],hData + ARTNET_HEADER + 1,size);//to use if your first universe has the number 0
//memcpy(&leds[SIZE_UNIVERSE*3(incomingUniverse-1)],hData + ARTNET_HEADER + 1,size); //to use if your first universe has the number 1
} //if(currentuniverse<NUM_UNIVERSES)
if(incomingUniverse==0) //to use if your first universe has the number 0
//if(incomingUniverse==1) //to use if your first universe has the number 1
{
syncval=0; //we restart when we recieve the first universe
}
else
{
syncval=syncval | (1<<incomingUniverse);//to use if your first universe has the number 0
//syncval=syncval | (1<<(incomingUniverse-1)); //to use if your first universe has the number 1
}
}
} // if Artnet Data
}
}
}//end while
displayleds();
}
@Diegorabbia
Copy link

holla , funciona con ws2811 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment