Advertisement
NapsterMP3

DMX para ARTNET UNO

Aug 31st, 2017
716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1.  
  2. /*
  3. Chaned some things for Arduino 1.0
  4.  
  5. ARTNET SENDER
  6.  
  7. This SCRIPT allows you to use arduino with ethernet shield or wifi shield and send dmx artnet data.
  8. Up to you to use logics for channels as you want.
  9.  
  10. It works with Arduino 023 software
  11.  
  12. If you have implemented ameliorations to this sketch, please, contribute by sending back modifications, ameliorations, derivative sketch.
  13. It will be a pleasure to let them accessible to community
  14.  
  15. This sketch is part of white cat lighting board suite: /http://www.le-chat-noir-numerique.fr
  16. wich is sending data to many different types of devices, and includes a direct communication in serial also with arduino as devices
  17. You may find whitecat interresting because its theatre based logic ( cuelist and automations) AND live oriented ( masters, midi, etc)
  18.  
  19. (c)Christoph Guillermet
  20. http://www.le-chat-noir-numerique.fr
  21. karistouf@yahoo.fr
  22. */
  23. #include <DMXSerial.h>
  24. #include <SPI.h> // needed for Arduino versions later than 0018
  25. #include <Ethernet.h>
  26. #include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
  27.  
  28. //MAC and IP of the ethernet shield
  29. //MAC adress of the ethershield is stamped down the shield
  30. //to translate it from hexa decimal to decimal, use: http://www.frankdevelopper.com/outils/convertisseur.php
  31.  
  32. //TO EDIT:
  33. // the next two variables are set when a packet is received
  34. byte destination_Ip[]= { 255,255,255,255 }; // the ip to send data, 255,255,255,255 is broadcast sending
  35. // art net parameters
  36. unsigned int localPort = 6454; // artnet UDP port is by default 6454
  37. const int DMX_Universe=0;//universe is from 0 to 15, subnet is not used
  38. const int number_of_channels=512; //512 for 512 channels, MAX=512
  39.  
  40. //HARDWARE
  41. byte mac[] = { 144, 162, 218, 00, 16, 96 };//the mac adress of ethernet shield or uno shield board
  42. byte ip[] = { 192,168,0,90 };// the IP adress of your device, that should be in same universe of the network you are using, here: 192.168.1.x
  43.  
  44. //ART-NET variables
  45. char ArtNetHead[8]="Art-Net";
  46. const int art_net_header_size=17;
  47.  
  48. short OpOutput= 0x5000 ;//output
  49.  
  50. byte buffer_dmx[number_of_channels]; //buffer used for DMX data
  51.  
  52. EthernetUDP Udp;
  53.  
  54. //Artnet PACKET
  55. byte ArtDmxBuffer[(art_net_header_size+number_of_channels)+8+1];
  56.  
  57. int d=0;
  58. int W5100_RESET_PIN = 3;
  59. void setup() {
  60. pinMode(W5100_RESET_PIN, OUTPUT);
  61. digitalWrite(W5100_RESET_PIN, LOW);
  62. delay(100);
  63. digitalWrite(W5100_RESET_PIN, HIGH);
  64.  
  65. delay(1000);
  66. DMXSerial.init(DMXReceiver);
  67. //initialise artnet header
  68. construct_arnet_packet();
  69. // démarrage ethernet et serveur UDP
  70. Ethernet.begin(mac,ip);
  71. Udp.begin(localPort);
  72. }
  73.  
  74. void loop() {
  75.  
  76. unsigned long lastPacket = DMXSerial.noDataSince();
  77.  
  78. if (lastPacket < 5000) {
  79. for (int i=1;i<513;i++){
  80. buffer_dmx[d]=byte(DMXSerial.read(i));
  81. d=d+1;
  82. }
  83. d=0;
  84. }
  85.  
  86. construct_arnet_packet();
  87.  
  88. Udp.beginPacket(destination_Ip, localPort);
  89. Udp.write(ArtDmxBuffer,(art_net_header_size+number_of_channels+1)); // was Udp.sendPacket
  90. Udp.endPacket();
  91.  
  92. // delay(40);
  93. }
  94.  
  95. void construct_arnet_packet()
  96. {
  97. //preparation pour tests
  98. for (int i=0;i<7;i++)
  99. {
  100. ArtDmxBuffer[i]=ArtNetHead[i];
  101. }
  102.  
  103. //Operator code low byte first
  104. ArtDmxBuffer[8]=OpOutput;
  105. ArtDmxBuffer[9]= OpOutput >> 8;
  106. //protocole
  107. ArtDmxBuffer[10]=0;
  108. ArtDmxBuffer[11]=14;
  109. //sequence
  110. ArtDmxBuffer[12]=0;
  111. //physical
  112. ArtDmxBuffer[13] = 0;
  113. // universe
  114. ArtDmxBuffer[14]= DMX_Universe;//or 0
  115. ArtDmxBuffer[15]= DMX_Universe>> 8;
  116. //data length
  117. ArtDmxBuffer[16] = number_of_channels>> 8;
  118. ArtDmxBuffer[17] = number_of_channels;
  119.  
  120. for (int t= 0;t<number_of_channels;t++)
  121. {
  122. ArtDmxBuffer[t+art_net_header_size+1]=buffer_dmx[t];
  123. }
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement