artnet to dmx output

Status
Not open for further replies.

Nick1802

Well-known member
hey all,
while im on a stand still with my last project (misses wont let me spend anymore money for now on it). i have decided i would try to make a artnet to dmx node as well, at lest the code anyway as i dont have any MAX485 chip laying around to use im hoping someone out there does.

i have used a lot of code from the artnet to octo thead http://forum.pjrc.com/threads/24688-Artnet-to-OctoWS2811?
and i think i have changed all the octo code to Dmxsimple and it compiles too.

if anyone out there could read through it and see if there is anything i haven't done or even test the code?

Code:
#include <stdlib.h>      
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>
#include <DmxSimple.h>

#define bytes_to_short(h,l) ( ((h << 8) & 0xff00) | (l & 0x00FF) );

byte mac[] = { 
  0x04, 0xE9, 0xe5, 0x00, 0x69, 0xa9} 
; //the mac adress in HEX of ethernet module/shield
byte ip[] = { 
  192, 168, 0  , 15}; // the IP adress of your device, that should be in same universe of the network you are using
unsigned int localPort = 6454;      // DO NOT CHANGE artnet UDP port is by default 6454

//---------------artnet and buffers------------//
const int first_universe_number = 1;//CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as zero.
const int universeSize = 512;//CHANGE FOR YOUR SETUP
const int number_of_channels= universeSize;//dont change
byte channel_buffer[number_of_channels];//buffer to store filetered DMX data//SHOULD BE SAME AS number_of_channels
byte buff2[40000];// increase buffer for filtered data to cover size of your total array(removed art-net header)
const int MAX_BUFFER_UDP = 768;//leave as is
char packetBuffer[MAX_BUFFER_UDP]; //buffer to store incoming data
short incoming_universe=0; //leave as is (if suspect uni number issues, try changing first_uni number above first.
const int start_address=0; // 0 if you want to read from channel 1
const int art_net_header_size = 17;

EthernetUDP Udp;

void setup() {
  Serial.begin(115200);
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);
  DmxSimple.usePin(3);
  DmxSimple.maxChannel(universeSize);
  delay(250);
  Serial.println("end of setup");
  Serial.println("waiting for incoming Artnet to start");
}

void loop() {

  int packetSize = Udp.parsePacket();
  if(packetSize)
  { 
    Serial.print("Received packet of size ");//all print can be removed if not debugging
    Serial.println(packetSize);

    Udp.read(packetBuffer,MAX_BUFFER_UDP);
    //can comment out serial print if not debugging
    Serial.print(packetBuffer);// all print can be removed if not debugging
    Serial.print("  "); 

    //-------read incoming universe and sequence number and check for data series-------------//
    incoming_universe=bytes_to_short(packetBuffer[15],packetBuffer[14])

      //-----this section can be commented out if not debugging   
      Serial.print("universe number = ");
    Serial.print(incoming_universe);  
    byte sequence = packetBuffer[12];  
    Serial.print("  ");
    Serial.print("sequence n0. = ");
    Serial.println(sequence);
    //finshing printing to serial to check packets

    //read incoming universe and put into buffer
    for(int i=start_address;i< number_of_channels;i++) {
      channel_buffer[i-start_address]= byte(packetBuffer[i+art_net_header_size+1]);
    }

    //------put into the right part of the display buffer----//
    for(int i=0;i<number_of_channels;i++){
      buff2[i+((incoming_universe-first_universe_number)*number_of_channels)]= channel_buffer[i-start_address];
    }       
    for(int i = 0; i < number_of_channels ; i++) {
      DmxSimple.write(i,buff2[i]);
    }
  }  
}

in time i would like to make this a 3 or even 4 port node but have no idea how to get DmxSimple to do more then 1 universe
 
Status
Not open for further replies.
Back
Top