UDP to send artnet Data

Hello,
So I have been working on a project andhave successfully managed to read a UDP string from packet sender to send out artnet data that is successfully read by artnetominator

However I have been going round in circles with the next step;
The sketch works to send a hard value on receiving data however i would like it to fade from 0 (or pre defined value) to the temp_val

currently the snippet below will send a value of 100 to buffer_dmx[1] which is the first channel. what would be the best approach to get this to fade from 0 - 100 over 5 seconds for example ?

The full code it attached below.

void SendArtnet(){
      if(strcmp(packetBuffer,"Test")==0){
      Serial.println("message recieved Channel 1");
      int temp_val=1;  
  {
    buffer_dmx[1]=byte(temp_val*100);
/*
Chaned some things for Arduino 1.0

ARTNET SENDER

*/

#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>       // UDP library from: bjoern@cs.stanford.edu 12/30/2008

//MAC and IP of the ethernet shield
//MAC adress of the ethershield is stamped down the shield
//to translate it from hexa decimal to decimal, use: http://www.frankdevelopper.com/outils/convertisseur.php

//TO EDIT:
// the next two variables are set when a packet is received
byte destination_Ip[]= {   255,255,255,255 };        // the ip to send data, 255,255,255,255 is broadcast sending
// art net parameters
unsigned int localPort = 6454;      // artnet UDP port is by default 6454
const int DMX_Universe=0;//universe is from 0 to 15, subnet is not used
const int number_of_channels=4; //512 for 512 channels, MAX=512


// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  // buffer to hold incoming packet,
//char ReplyBuffer[] = "acknowledged";        // a string to send back

//HARDWARE
byte mac[] = {  144, 162, 218, 00, 16, 96  };//the mac adress of ethernet shield or uno shield board
byte ip[] = {   2,0,0,116 };// the IP adress of your device, that should be in same universe of the network you are using, here: 192.168.1.x

//ART-NET variables
char ArtNetHead[8]="Art-Net";
const int art_net_header_size=17;

short OpOutput= 0x5000 ;//output

byte buffer_dmx[number_of_channels]; //buffer used for DMX data

EthernetUDP Udp;

//Artnet PACKET
byte  ArtDmxBuffer[(art_net_header_size+number_of_channels)+8+1];




void setup() {

  //initialise artnet header
  construct_arnet_packet();
  // démarrage ethernet et serveur UDP
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);

    // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
}
}

void loop() {
  
   SendArtnet();
   construct_arnet_packet();
 
   
   Udp.beginPacket(destination_Ip, localPort);
   Udp.write(ArtDmxBuffer,(art_net_header_size+number_of_channels+1)); // was Udp.sendPacket
   Udp.endPacket();
    
   delay(40);

     // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
   Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
   for (int i=0; i < 4; i++) {
      Serial.print(remote[i], DEC);
    if (i < 3) {
      // Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer);


  }

}


void SendArtnet(){
      if(strcmp(packetBuffer,"Test")==0){
      Serial.println("message recieved Channel 1");
      int temp_val=1;  
      int temp_val1=2;
  {
    buffer_dmx[1]=byte(temp_val*100);
    buffer_dmx[2]=byte(temp_val*10);
    

    Serial.println(buffer_dmx[1]);
    
  }
      
  }


      if(strcmp(packetBuffer,"Test2")==0){
      Serial.println("message recieved Channel 2");
      int temp_val=1;  
      int temp_val1=2;
  {
    buffer_dmx[1]=byte(temp_val*10);
    buffer_dmx[2]=byte(temp_val*10);
    
  }
      }
        delay(10);
    for(int i=0;i<UDP_TX_PACKET_MAX_SIZE;i++) packetBuffer[i] = 0;
}



void construct_arnet_packet()
{
     //preparation pour tests
    for (int i=0;i<7;i++)
    {
    ArtDmxBuffer[i]=ArtNetHead[i];
    }   

    //Operator code low byte first  
     ArtDmxBuffer[8]=OpOutput;
     ArtDmxBuffer[9]= OpOutput >> 8;
     //protocole
     ArtDmxBuffer[10]=0;
     ArtDmxBuffer[11]=14;
     //sequence
     ArtDmxBuffer[12]=0;
     //physical 
     ArtDmxBuffer[13] = 0;
     // universe 
     ArtDmxBuffer[14]= DMX_Universe;//or 0
     ArtDmxBuffer[15]= DMX_Universe>> 8;
     //data length
     ArtDmxBuffer[16] = number_of_channels>> 8;
     ArtDmxBuffer[17] = number_of_channels;
   
     for (int t= 0;t<number_of_channels;t++)
     {
       ArtDmxBuffer[t+art_net_header_size+1]=buffer_dmx[t];    
     }
     
}

lots of credit to Christoph Guillermet for the artnet implimenation

update;
with this code

void SendArtnet(){
      if(strcmp(packetBuffer,"Test")==0){
      Serial.println("message recieved Channel 1");
      static int value=0;
    value = (value + 1) % 255;
    for (int i=0; i<255; i++);

    Serial.println(value);
    delay (30);
  {
  buffer_dmx[1]=byte(value);
    } 
  }

It will increase each time i send the UDP string which is great, and I see the limitations of it now, however is there a way on receiving the string it runs a loop inside this void to count from 0 - 255? and upon reaching this value stops ?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.