Arduino e1.31 to Drive Relays

DiddyDaveUK

New elf
Joined
Feb 25, 2019
Messages
6
Hi all..... I'm a little green when it comes to things like this. I'm ok with the Xlights part and I currently have a show with WS2812b and WS2811 LED's BUT I would also like to bring in single colour light leds ( one's you buy off the shelf type ) and connect them to a rely. I currently have 2 relay boards ( 8x on each board ). I was given this code by Keith last year but never got to use it. I would like to ask a BIGGGG favour for those of us that are a little hazy on how this sketch works and connects to Xlights. Would it be possible for someone to create a video on how to set one of these up...?

Many Thanks
DiddyDave
 

scottbob09

New elf
Joined
Dec 2, 2020
Messages
1
a few things, watch your shield stacking. High probability of a short on the Ethernet solder joints. Otherwise, use a good IP and an unused low numbered universe for it. I picked 3.
I only had a 4 channel to test with. So I made the universe accordingly sized. No changes to e131 universe on the Arduino. Leave as is.
Also, on my UNO, I needed to use 2, 5 ,6 , 7 as my first 4 pins.
changes:

Code:
#define NUM_RELAYS 4 //total number of relays used
int Relay[] = {2, 5, 6, 7,}; //Relay Pins array

The errant comma at the end doesn't seem to matter.
Then in testing, make sure "don't send data to unused outputs" is checked. Uncheck all things on the left.
Find your board in the list on the left, click to activate. For me, that was 4 channels. Then select "Chase". And finally..
Check to activate "Output to lights"


works.PNG
 

Elecgreg

New elf
Joined
Dec 11, 2020
Messages
28
Location
The Rock
Have been looking at this code and it appears to be good for what I want however would someone with some better knowledge than I please help with the ethernet side I have made some changes to the code and it worked however when trying the xlights test it would not work.

I have begun to thing it is impossible to control my AC lights without spending a huge amount of money and really do not want to do that.

I tried to use Kieth's coded however only was able to get 16 relays to operate and a lot of fuss in the way it needed old software to get that to happen so this will work with the latest Arduino ide but when looking into it the code would not run the xlights test function or do they need to be assigned to lights in the layout before they will work. I have made a change to the pwr on test and it works however the use of pin 10 on the Arduio uno remains high so only 7 relays can be used with the shield also tried to connect an enc28j60 but that didn't happen. Would not ping.

Level of frustration is building and getting anxious to make something work completely.

sorry if this sound a little like a rant but have had a really bad day today
 

stevelee

Apprentice elf
Joined
Dec 27, 2020
Messages
77
Location
Bathurst
Have been looking at this code and it appears to be good for what I want however would someone with some better knowledge than I please help with the ethernet side I have made some changes to the code and it worked however when trying the xlights test it would not work.

I have begun to thing it is impossible to control my AC lights without spending a huge amount of money and really do not want to do that.

I tried to use Kieth's coded however only was able to get 16 relays to operate and a lot of fuss in the way it needed old software to get that to happen so this will work with the latest Arduino ide but when looking into it the code would not run the xlights test function or do they need to be assigned to lights in the layout before they will work. I have made a change to the pwr on test and it works however the use of pin 10 on the Arduio uno remains high so only 7 relays can be used with the shield also tried to connect an enc28j60 but that didn't happen. Would not ping.

Level of frustration is building and getting anxious to make something work completely.

sorry if this sound a little like a rant but have had a really bad day today
Someone put me onto these. They control relays using WS2811. I’m looking into getting one to control a linear actuator. The link is for their dc one. They do an AC one too.

 
Joined
Feb 18, 2023
Messages
1
I am trying to take this code beyond my know how maybe someone can help.

I would like this code instead of relays to start other code. An example is Artnet U1C1 to start a code that I wrote and works that turn on relay 1-3 then turns off relay when pressure is met and fuel level is met. Then Artnet U1C2 is the firing channel but that channel is only active if there is pressure in the tank and there is a pilot lite.
 

esphotographie

New elf
Joined
Dec 2, 2023
Messages
1
bonjour a tous, voila j ai un atmega avec un ws5100 ethernet et 16 relais avec vixen 3 , tout marche bien sauf sauf que ma carte fait un reset régulièrementement et ça refonctionne et ça courament ,une idée ?
voici mon code


Code:
#include <SPI.h> //Bibliothèque standard
#include <Ethernet.h> //Bibliothèque standard
#include <EthernetUdp.h> //Bibliothèque standard
 
 
/* définit le sous-réseau et l’univers souhaités (le premier univers est 0)
sACN commence avec l’univers 1 donc soustraire 1 de l’univers sACN
pour obtenir DMX_UNIVERSE. */
#define ARTNET_SUBNET 0 //defualt subnet vaut 0. Ne devrait pas avoir besoin d’être changé.
#define ARTNET_UNIVERSE 0 //premier univers utilisé
#define E131_SUBNET 0 //defualt subnet vaut 0. Ne devrait pas avoir besoin d’être changé.
#define ETHERNET_BUFFER_MAX 640
#define ARTNET_ARTDMX 0x5000
#define ARTNET_ARTPOLL 0x2000
#define ARTNET_PORT 0x1936 //port standard
#define ARTNET_START_ADDRESS 18 //L’octet 18 du paquet contient les valeurs du canal 1.
#define E131_PORT 5568 //port standard
#define E131_START_ADDRESS 126 //L’octet 126 du paquet contient les valeurs du canal 1. Le décalage est défini sur un a priori.
#define STATUS_LED 13 //nous indique quand nous recevons des données
#define SDCARD_CONTROL 4 //réglez la broche 4 sur haute pour désactiver l’interface de la carte SD sur le bouclier WiFi
#define NUM_RELAYS 30 //nombre total de relais utilisés
 
canal int ; Incrément de canal
 
Réseau de broches de relais
int Relais[] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51} ;
 
Configuration de la minuterie
Compteur de courant d’octets volatils = 0 ; Compteur pour la réception des données
octet previouscounter = 0 ; Compteur pour la réception des données
unsigned long currentDelay = 0 ; valeur temporelle actuelle pour la réception ArtNet et E1.31
 
Ethernet Configuration
octet mac[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} ;
IPAddress ip(192, 168, 1, 213) ; Adresse IP du bouclier Ethernet
 
tampon pour contenir les données E1.31 et Artnet
unsigned char packetBuffer[ETHERNET_BUFFER_MAX] ;
 
Une instance EthernetUDP pour nous permettre d’envoyer et de recevoir des paquets via UDP
aUDP crée un socket pour un port Art-Net
suUDP crée un socket pour sACN qui est unicast à l’adresse IP
EthernetUDP aUDP ;
EthernetUDP suUDP ;
 
void setup()
{
pinMode(STATUS_LED, SORTIE) ; Voyant d’état d’initialisation
pinMode(SDCARD_CONTROL, SORTIE) ; Initialiser la broche 4
digitalWrite(SDCARD_CONTROL, HIGH) ; Réglez la broche 4 sur élevée car nous n’utilisons pas l’interface de la carte SD
for(int a = 0 ; a < NUM_RELAYS ; a++) //boucle pour initialiser les broches de contrôle du relais
  {
pinMode(Relais[a], SORTIE) ; Initialiser les broches de sortie du relais
écriturenumérique(Relais[a], HAUT) ; Réglez les broches sur High pour Off
  }
Ethernet.begin(mac,ip) ; Initialiser le bouclier Ethernet
aUDP.begin(ARTNET_PORT) ; Ouvrir le port Artnet
suUDP.begin(E131_PORT) ; Ouvrir le port E1.31
série.begin(9600) ; Série pour le débogage
POSTE() ; Exécuter la fonction d’auto-test de mise sous tension
Serial.println(« Installation terminée ») ; Impression terminée
}
 
/* artDMXReceived vérifie l’univers et le sous-réseau
transmet les données aux relais */
 
void artDMXReceived(unsigned char* pbuff)
{
  if ( (pbuff[14] & 0xF) == ARTNET_UNIVERSE )
  {
    if ( (pbuff[14] >> 8) == ARTNET_SUBNET )
    {
canal = 0 ; Réinitialiser le décalage du canal à 0 à chaque fois dans la boucle
boucle active/désactive le relais en fonction de la valeur du canal à partir de l’adresse de départ Artnet
for(int b = 0 ; b < NUM_RELAYS ; b++)
      {
if(pbuff[ARTNET_START_ADDRESS + canal] > 127) //si la valeur du canal est supérieure à 127
      {
écriturenumérique(Relais[b], FAIBLE) ; Activer le relais
      }
autre
      {
écriturenumérique(Relais[b], HAUT) ; sinon, éteignez-le
      }
canal++ ; Augmentez le décalage du canal de 1 à chaque fois que vous traversez la boucle for
      }
    }
  }
} //end artDMXReceived
 
/* artNetOpCode vérifie que le paquet est bien Art-Net
et renvoie l’opcode indiquant de quel type de message Art-Net il s’agit. */
 
int artNetOpCode(unsigned char* pbuff)
{
Test de chaîne = String((char*)pbuff) ;
if ( test.equals(« Art-Net ») )
  {
    if ( pbuff[11] >= 14 )
{ //version du protocole [10] hi byte [11] lo byte
retour pbuff[9] *256 + pbuff[8] ; opcode lo octet en premier
    }
  }
 
renvoie 0 ;
}
 
/* sacnDMXReceived vérifie l’univers et le sous-réseau
Envoie les données aux relais */
 
void sacnDMXReceived(unsigned char* pbuff, int count)
{
    if ( pbuff[113] == E131_SUBNET )
  {
int addressOffset = 125 ; Les 125 premiers octets du paquet sont des informations d’en-tête
if ( pbuff[addressOffset] == 0 ) //le code de début doit être 0
      {
canal = 0 ; Réinitialiser le décalage du canal à 0 à chaque fois dans la boucle
boucle allume/éteint le relais en fonction de la valeur du canal à partir de l’adresse de départ E1.31
for(int c = 0 ; c < NUM_RELAYS ; c++)
      {
if(pbuff[E131_START_ADDRESS + canal] > 127) //si la valeur du canal est supérieure à 127
      {
écriturenumérique(Relais[c], FAIBLE) ; Activer le relais
      }
autre
      {
écriturenumérique(Relais[c], HAUT) ; Désactiver le relais
      }
canal++ ; Incrémenter le décalage du canal de 1
      }
      }
      }
    } //end sacnDMXReceived
    
 
 
vérifie si le paquet est des données E1.31
int checkACNHeaders(unsigned char* messagein, int messagelength)
{
  if ( messagein[1] == 0x10 && messagein[4] == 0x41 && messagein[12] == 0x37)
  {   
int addresscount = messagein[123] * 256 + messagein[124] ; Nombre de valeurs plus code de départ
adresse de retourcount -1 ; Renvoie le nombre de valeurs contenues dans le paquet.
    }
renvoie 0 ;
}
 
/************************************************************************
 
La boucle principale vérifie et lit les paquets des deux ports Ethernet UDP
connexions de prises. Lorsqu’un paquet est reçu, il est vérifié pour voir si
il est valide, puis l’une des fonctions DMXReceived est appelée, envoyant
les valeurs DMX à la sortie. Il y a aussi une minuterie pour exécuter une veille
programme si aucune donnée n’est reçue pendant 30 secondes.
 
*************************************************************************/
 
void loop()
{
if(currentcounter != previouscounter) //la valeur a-t-elle changé ?
  {
currentDelay = millis() ; stocker le temps écoulé depuis que la valeur a augmenté
previouscounter = compteur de courant ; Définir la valeur précédente égale à la valeur actuelle
  }
 
if(millis() - currentDelay > 90000) //le temps écoulé depuis le changement de valeur est-il supérieur à 30 secondes ?
  {
écriturenumérique(STATUS_LED, FAIBLE) ; éteignez la LED. Ne pas recevoir E1.31 ou ArtNet.
  }
 
vérifiez d’abord si un paquet est disponible sur le port Art-Net
int packetSize = aUDP.parsePacket() ;
if( taille_paquet )
  {
aUDP.read(paquetTampon, ETHERNET_BUFFER_MAX) ;
/* Après avoir lu le paquet dans la mémoire tampon, assurez-vous que
qu’il s’agit d’un paquet Art-Net et récupère l’opcode qui
indique de quel type de message il s’agit */
int opcode = artNetOpCode(packetBuffer) ;
    if ( opcode == ARTNET_ARTDMX )
    {
Serial.println(« Paquet ArtNet reçu ») ;
artDMXReceived(packetBuffer) ;
compteur de courant++ ; Augmente le compteur de 1 à chaque fois
digitalWrite(STATUS_LED, HIGH) ; allumer le voyant d’état
    }
  }
autre
    {
/* puis, s’il n’y a toujours pas de paquet, vérifiez si un paquet
est disponible sur le port de monodiffusion sACN */
packetSize = suUDP.parsePacket() ;
if( taille_paquet )
    {
suUDP.read(packetBuffer, ETHERNET_BUFFER_MAX) ;
/* Après avoir lu le paquet dans la mémoire tampon, assurez-vous que
qu’il s’agit d’un paquet sACN valide.*/
int count = checkACNHeaders(packetBuffer, packetSize) ;
      if ( count )
      {
Serial.println(« E131 Paquet reçu ») ;
sacnDMXReceived(packetBuffer, nombre) ;
compteur de courant++ ; Augmente le compteur de 1 à chaque fois
digitalWrite(STATUS_LED, HIGH) ; allumer le voyant d’état
      }
    }
    
    }
 
} //Boucle de fin
 
Fonction d’auto-test de mise sous tension pour s’assurer que tout est correctement connecté.
void POST()
{
écriturenumérique(Relais[0], BAS) ;
retard(1000) ;
écriturenumérique(Relais[0], ÉLEVÉ) ;
écriturenumérique(Relais[1], BAS) ;
retard(1000) ;
écriturenumérique(Relais[1], ÉLEVÉ) ;
écriturenumérique(Relais[2], BAS) ;
retard(1000) ;
écriturenumérique(Relais[2], HAUT) ;
écriturenumérique(Relais[3], FAIBLE) ;
retard(1000) ;
écriturenumérique(Relais[3], ÉLEVÉ) ;
écriturenumérique(Relais[4], BAS) ;
retard(1000) ;
écriturenumérique(Relais[4], HAUT) ;
digitalWrite(Relais[5], FAIBLE) ;
retard(1000) ;
écriturenumérique(Relais[5], ÉLEVÉ) ;
écriturenumérique(Relais[6], FAIBLE) ;
retard(1000) ;
écriturenumérique(Relais[6], HAUT) ;
écriturenumérique(Relais[7], BAS) ;
retard(1000) ;
écriturenumérique(Relais[7], HAUT) ;
écriturenumérique(Relais[8], BAS) ;
retard(1000) ;
digitalWrite(Relais[8], HIGH) ;
écriturenumérique(Relais[9], BAS) ;
retard(1000) ;
écriturenumérique(Relais[9], HAUT) ;
écriturenumérique(Relais[10], BAS) ;
retard(1000) ;
écriturenumérique(Relais[10], HAUT) ;
écriturenumérique(Relais[11], BAS) ;
retard(1000) ;
écriturenumérique(Relais[11], HAUT) ;
écriturenumérique(Relais[12], BAS) ;
retard(1000) ;
digitalWrite(Relais[12], HIGH) ;
écriturenumérique(Relais[13], FAIBLE) ;
retard(1000) ;
digitalWrite(Relais[13], HIGH) ;
écriturenumérique(Relais[14], BAS) ;
retard(1000) ;
digitalWrite(Relais[14], HIGH) ;
écriturenumérique(Relais[15], BAS) ;
retard(1000) ;
écriturenumérique(Relais[15], HAUT) ;
écriturenumérique(Relais[16], BAS) ;
retard(1000) ;
écriturenumérique(Relais[16], HAUT) ;
écriturenumérique(Relais[17], BAS) ;
retard(1000) ;
écriturenumérique(Relais[17], ÉLEVÉ) ;
écriturenumérique(Relais[18], BAS) ;
retard(1000) ;
écriturenumérique(Relais[18], ÉLEVÉ) ;
écriturenumérique(Relais[19], BAS) ;
retard(1000) ;
écriturenumérique(Relais[19], HAUT) ;
écriturenumérique(Relais[20], BAS) ;
retard(1000) ;
écriturenumérique(Relais[20], HAUT) ;
écriturenumérique(Relais[21], BAS) ;
retard(1000) ;
écriturenumérique(Relais[21], ÉLEVÉ) ;
écriturenumérique(Relais[22], BAS) ;
retard(1000) ;
écriturenumérique(Relais[22], HAUT) ;
écriturenumérique(Relais[23], BAS) ;
retard(1000) ;
écriturenumérique(Relais[23], HAUT) ;
écriturenumérique(Relais[24], BAS) ;
retard(1000) ;
digitalWrite(Relais[24], HIGH) ;
écriturenumérique(Relais[25], BAS) ;
retard(1000) ;
écriturenumérique(Relais[25], HAUT) ;
écriturenumérique(Relais[26], BAS) ;
retard(1000) ;
digitalWrite(Relais[26], HIGH) ;
écriturenumérique(Relais[27], BAS) ;
retard(1000) ;
écriturenumérique(Relais[27], ÉLEVÉ) ;
écriturenumérique(Relais[28], BAS) ;
retard(1000) ;
écriturenumérique(Relais[28], HAUT) ;
écriturenumérique(Relais[29], BAS) ;
retard(1000) ;
écriturenumérique(Relais[29], ÉLEVÉ) ;
écriturenumérique(Relais[30], BAS) ;
retard(1000) ;
écriturenumérique(Relais[30], HAUT) ;
Serial.println(« POST terminé ») ;
}
 

MikeKrebs

Full time elf
Joined
Dec 8, 2014
Messages
164
hello everyone, here I have an atmega with a ws5100 ethernet and 16 relays with vixen 3, everything works well except that my card does a reset regularly and it works again and that regularly, any idea? here is my code
What kind of reset do you think you are getting?
Does the reset happen at xx minutes?
 

MikeKrebs

Full time elf
Joined
Dec 8, 2014
Messages
164
If you have the serial.println enabled while running, I would turn that off.
 
Top