here is the code i’ve been messing with…
/
created January 4th, 2014
by Claude Heintz
modified by: Jared Alexander
This code is in the public domain.
sACN E 1.31 is a public standard published by the PLASA technical standards program
http://tsp.plasa.org/tsp/documents/published_docs.php
Requires Arduino Ethernet Shield.
Modifed to use the lastest version of EthernetUdp library included in Arduino 1.0.5-r2. No need to install other libraries.
Receives E1.31 date (sACN) and outputs to WS2811 pixels using FastLED library.
Includes timer to run standby program when not receiving data and init program to test pixels each time board boots.
/
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <FastLED.h>
#define NUM_LEDS 192 //number of pixels
CRGB leds[NUM_LEDS]; //pixel array
byte current_hue; //hue value for rainbow effect
byte ledNumber; //current led Pixel being used for rainbow effect
// enter desired universe and subnet (sACN first universe is 1)
#define DMX_SUBNET 0
#define DMX_UNIVERSE 1
#define SACN_PORT 5568
#define SACN_BUFFER_MAX 640
const byte channelwidth = 3; //3 channels per pixel
byte channel; //channel number for each pixel RGB
volatile byte currentcounter = 0; //counter for data reception
byte previouscounter = 0; //counter for data reception
unsigned long now = 0; //current time value
//the initial ip and MAC address will get changed by beginMulti
//the multicast ip address should correspond to the desired universe/subnet
byte mac[] = {0x90, 0xA2, 0xDA, 0x0F, 0x2A, 0xBC}; //MAC address of ethernet shield
IPAddress ip(192, 168, 1, 240); //IP address of ethernet shield
IPAddress mip(239, 255, 0, 1); //defauly multicast IP for E1.31
// buffers for receiving and sending data
unsigned char packetBuffer[SACN_BUFFER_MAX]; //buffer to hold incoming packet,
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
//set this to 1 to print messages to serial, 0 to skip
int verbose = 1;
//setup initializes Ethernet, opens the UDP port and initializes pixels
void setup()
{
LEDS.setBrightness(255); //Default LED Brightness
LEDS.addLeds<WS2811,14>(leds, NUM_LEDS); //using 12 volt WS2811 LED Pixels connected to pin 6
Ethernet.begin(mac,ip);
Udp.begin(SACN_PORT);
if ( verbose )
{
Serial.begin(9600);
}
initTest(); //test to make sure pixels are working
} //end setup
void sacnDMXReceived(unsigned char* pbuff, int count)
{
if ( verbose )
{
Serial.println(“DMX Packet Received”);
}
if ( pbuff[113] == DMX_SUBNET )
{
if ( pbuff[114] == DMX_UNIVERSE )
{
int addressOffset = 125;
if ( pbuff[addressOffset] == 0 )
{ //start code must be 0
channel = 1; //reset DMX channel assignment to 1 each time through loop.
for (int i = 0; i < NUM_LEDS; i++) //loop to assign 3 channels to each pixel
{
leds[i] = CRGB(pbuff[addressOffset + channel], pbuff[addressOffset + (channel +1)], pbuff[addressOffset + (channel +2)]);
channel +=channelwidth; //increase last channel number by channel width
}
}
}
}
FastLED.show(); //send data to pixels
}
//checks to see if packet is E1.31 data
int checkACNHeaders(unsigned char* messagein, int messagelength)
{
if ( messagein[1] == 0x10 )
{ //header
String test = String((char*)&messagein[4]);
if ( test.equals(“ASC-E1.17”) )
{
int rootsizeflags = messagein[16] * 256 + messagein[17];
if ( (0x7000 + messagelength-16) == rootsizeflags )
{
int framingsizeflags = messagein[38] * 256 + messagein[39];
if ( (0x7000 + messagelength-38) == framingsizeflags )
{
int dmpsizeflags = messagein[115] * 256 + messagein[116];
if ( (0x7000 + messagelength-115) == dmpsizeflags )
{
int addresscount = messagein[123] * 256 + messagein[124]; // number of addresses plus start code
if ( (messagelength-125) == addresscount )
{
return addresscount;
}
}
}
}
}
}
return 0;
}
void loop()
{
int packetSize = Udp.parsePacket(); //store UPD packet
//timer to check if receiving data
if(currentcounter != previouscounter) //has the counter changed?
{
now = millis(); //store the time since the counter has increased
previouscounter = currentcounter; //set the previous value equal to the current value
}
if((millis() - now) > 5000) //is the time since the counter changed greater than 5 seconds?
{
noReceive(); //not receiving data. Run no receive function
}
if(packetSize)
{
Udp.read(packetBuffer,SACN_BUFFER_MAX); //read UDP packet
int count = checkACNHeaders(packetBuffer, packetSize);
if (count)
{
sacnDMXReceived(packetBuffer, count); //process data function
currentcounter++; //increase counter by 1 each time through
}
}
}
void initTest() //runs at board boot to make sure pixels are working
{
LEDS.showColor(CRGB(255, 0, 0)); //turn all pixels on red
delay(1000);
LEDS.showColor(CRGB(0, 255, 0)); //turn all pixels on green
delay(1000);
LEDS.showColor(CRGB(0, 0, 255)); //turn all pixels on blue
delay(1000);
LEDS.showColor(CRGB(0, 0, 0)); //turn all pixels off
}
void noReceive()
{
//simple rainbow fade
for(ledNumber = 0; ledNumber < NUM_LEDS; ledNumber++)
{
leds[ledNumber] = CHSV(current_hue, 255, 255); //set current LED pixel to hue
FastLED.show(); //show color
//delay(5); //very short delay
leds[ledNumber] = CHSV(current_hue-10, 255, 255); //set same LED pixel to hue value - 10
current_hue += 10; //increase hue value by 10
}
}