Using Xlight with an Arduino MEGA

Mathissou01

New member
Hello everyone, so I try to control a led strip WS2815 12V with my arduino and everything is correct.
I tried to use vixen to make a light show and found that Vixen is not very powerful and not full of animation like Xlight.
So I tried to use Xlight but I dont know how to connect my Arduino to Xlight.
I found nothing clear , no tutorials that can help me.

I found a code on the "DoItYourself" forum but dont know which pin to put the data on the arduino with this code and what setting to put on Xlight in the controller settings.

Can anyone help me please ! :cool:

Here the code:

// This code was written by Click that moment.

// To adapt the code to your case, just change this top section, with the #define lines.


// Includes the watchdog timer library

#include <avr/wdt.h>


// This sets how many channels will vixen be sending. Can be set to any number from 1 to 48 for Arduino Mega, and 1 to 18 for Arduino Uno.

#define CHANNEL_COUNT 10


// speed for the com port for talking with vixen. From 9600 to 115200. Use the same speed as set in Vixen.

#define VIXEN_COM_SPEED 57600


// Timeout waiting for serial input before going to random mode (in milliseconds).

#define TIME_OUT 1000


// If the relays turn On and Off opposite to Vixen sequence, change "#define MODE NOT_INVERTED" for "#define MODE INVERTED"

#define NOT_INVERTED 0

#define INVERTED 1

#define MODE NOT_INVERTED


// which pins control which channels

// You can change these assignment to use different pins, but be very careful to not repeat the same pin number for 2 channels.

// DO NOT use pings 0 and 1, as those are for the serial port to talk to the computer.

#define CH01 2

#define CH02 3

#define CH03 4

#define CH04 5

#define CH05 6

#define CH06 7

#define CH07 8

#define CH08 9

#define CH09 10

#define CH10 11

#define CH11 12

#define CH12 13

#define CH13 A0

#define CH14 A1

#define CH15 A2

#define CH16 A3

#define CH17 A4

#define CH18 A5

// Up to here for Arduino uno.

#define CH19 A6

#define CH20 A7

#define CH21 A8

#define CH22 A9

#define CH23 A10

#define CH24 A11

#define CH25 A12

#define CH26 A13

#define CH27 A14

#define CH28 A15

#define CH29 22

#define CH30 23

#define CH31 24

#define CH32 25

#define CH33 26

#define CH34 27

#define CH35 28

#define CH36 29

#define CH37 30

#define CH38 31

#define CH39 32

#define CH40 33

#define CH41 34

#define CH42 35

#define CH43 36

#define CH44 37

#define CH45 38

#define CH46 39

#define CH47 40

#define CH48 41


int channels[] = {CH01, CH02, CH03, CH04, CH05 , CH06, CH07, CH08, CH09,

CH10, CH11, CH12, CH13, CH14, CH15, CH16, CH17, CH18, CH19, CH20, CH21, CH22,

CH23, CH24, CH25, CH26, CH27, CH28, CH29, CH30, CH31, CH32, CH33, CH34, CH35,

CH36, CH37, CH38, CH39, CH40, CH41, CH42, CH43, CH44, CH45, CH46, CH47, CH48
};


int incomingByte[CHANNEL_COUNT];


int i = 0; // Loop counter

volatile unsigned long timer_a = 0; // new line


//setup the pins/ inputs & outputs

void setup() {


// enable the watchdog timer with a time of 1 second. If the board freezes, it will reset itself after 1 second.

wdt_enable(WDTO_1S);


// specifically for the UNO

sei();


// initalize PWM Channels / Pins

for (i = 0; i < CHANNEL_COUNT; i++) {

pinMode(channels, OUTPUT);

}


// set all the realys to off to start with

if (MODE == NOT_INVERTED) {

for (i = 0; i < CHANNEL_COUNT; i++) {

digitalWrite(channels, LOW);


}

}


else {

for (i = 0; i < CHANNEL_COUNT; i++) {

digitalWrite(channels, HIGH);

}

}


testSequence();


// set up Serial according to the speed defined above.

Serial.begin(VIXEN_COM_SPEED);

}


void loop()

{

if (Serial.available() >= (CHANNEL_COUNT + 2)) {

wdt_reset(); // resets the watchdog

timer_a = millis (); // new line

int uno = Serial.read();

if (uno == 126) {


int dos = Serial.read();

if (dos == 33) {


for (i = 0; i < CHANNEL_COUNT; i++) {

// read each byte

incomingByte = Serial.read();

}

if (MODE == NOT_INVERTED) {

for (i = 0; i < CHANNEL_COUNT; i++) {

int value = incomingByte;

if (value <= 127) {

digitalWrite(channels, LOW);

}

else {

digitalWrite(channels, HIGH);

}

}

}

else {

for (i = 0; i < CHANNEL_COUNT; i++) {

int value = incomingByte;

if (value < 127) {

digitalWrite(channels, HIGH);

}

else {

digitalWrite(channels, LOW);

}

}

}


}

}

}

// Random mode code. Random mode starts if no serial input has been received in TIME_OUT millisenconds

else {

wdt_reset(); // resets the watchdog

unsigned long diff = millis() - timer_a;

if (diff >= TIME_OUT) {

timer_a = millis ();

int random_a = 0;

for (i = 0; i < CHANNEL_COUNT; i++) {

random_a = random(0, 2);

if (random_a == 0) {

digitalWrite(channels, LOW);

}

else {

digitalWrite(channels, HIGH);

}

}

}

}

}


void testSequence() {


if (MODE == NOT_INVERTED) {

for (i = 0; i < CHANNEL_COUNT; i++) {

wdt_reset(); // resets the watchdog

digitalWrite(channels, HIGH);

delay (500);

digitalWrite(channels, LOW);

}

}


else {

for (i = 0; i < CHANNEL_COUNT; i++) {

wdt_reset(); // resets the watchdog

digitalWrite(channels, LOW);

delay (500);

digitalWrite(channels, HIGH);

}

}

}
 
Your incoming data's coming in on your serial line. You have access to 48 channels of output data--straight on/off, probably going to some solid-state relays.
 
Your incoming data's coming in on your serial line. You have access to 48 channels of output data--straight on/off, probably going to some solid-state relays.

My led strip has a ground , 12V + , a data line and a backup line.
So i just need to use the data line.I copy this code but I know this code is for a light system with many channels and relay but me I just have my arduino that is connected to my led strip with one data channel like the PIN 6 of the arduino

So I dont know what do I have to change in the code , and how to connect it to Xlight
 
Oooooh.

Apples and oranges. This sketch does not include any WS281x libraries. It won't do WS2815 -- only straight on/off. I don't think this is a fit.
 
Sorry, it's the first time I write on the forum and use google translate. I uploaded this sketch presented at the beginning. arduino mega runs the "testSequence". in hereall normal. When I start VIXEN nothing happens. I tried with the USB cable with which I program Arduino, I used a USB to RS232 TTL converter but it does not work. Some moments when the music is stopped the LED flashes and at some times that the music is on the LED does not work. Thanks for your help.
Gabry59

Scusate, ? la prima volta che scrivo sul forum e uso google traduttore. Ho caricato questo sketch presentato all'inizio. arduino mega esegue il "testSequence". in quitutto normale. Quando avvio VIXEN non succede niente.
Ho provato con il cavo USB con il quale programmo Arduino, ho usato un convertitore da USB a RS232 TTL ma non funziona.
Alcuni momenti quando la musica ? ferma il LED lampeggia e in alcuni momenti che la musica ? accesa il LED non funzona.
Grazie dell'aiuto.
 
Last edited:
So this post seems to have moved from XLights to Vixen.

From Vixen you would simply connect your Mega board to the computer using its onboard USB, I'm not following why you need a separate converter. Make sure the board is connected (and has a COM port assigned, you can check in device manager) before you start Vixen. Also make sure you don't have the Arduino IDE open as this will lock the COM port. Can you post an image of your Vixen configuration for this controller (i.e. the properties of the 'generic serial' controller you have added?

What are you trying to control? WS2811 pixels? LED strip (3 colour, with dimming)? Relays? As others have mentioned, the sketch may / may not be suitable. If you have WS2815 LED strip then the sketch you have posted is totally unsuitable.

The sketch is expecting a 'header' of -!, make sure this is configured in Vixen

The number of channels configured needs to match what's in your Vixen controller setup, appears to be 10 in the sketch, Make sure you baud rate in Vixen matches what's in the sketch (57600)
 
Last edited:
'So this post seems to have moved from XLights to Vixen.'
I apologize for my mistake, I will try to post it on the right title
 
If this was solved, disregard this post...

I found myself in the same shoes as you, as Vixen doesn't have the same custom matrix capabilities as xLights does. I had to scramble to find any information I could about using xLights with Generic Serial/an Arduino. This is what I've learned in relation to your post:

If you are operating an led strip, then you can use most of your pins. I like using pin 3, but other pins like pin 6 should work. If you set the prefix as "<" and postfix as ">", then it'll output as <RGBRGBRGBRGB...>. This code should work. Took me a while to develop it, because it's hard debugging when you can't read the serial line, but it seems to work pretty well for me. Set up a generic serial controller at the desired COM port and this code should work!

#include <FastLED.h>
#define LED_PIN 3 //Change this for your pin
#define NUM_LEDS 100 // Change for your number of pixels
#include <stdlib.h>

CRGB leds[NUM_LEDS];
const int numNodes = NUM_LEDS * 3;

void setup() {
FastLED.addLeds<WS2811, LED_PIN, RGB>(leds, NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 500);
FastLED.setBrightness(30);
FastLED.setMaxRefreshRate(0);
FastLED.clear();
FastLED.show();
Serial.begin(128000); // Change this for your baud rate
}
void loop() {
while (Serial.available() > 0)
{

int inByte = Serial.read();

if (inByte == '<') {
if (Serial.read() != '>') {
byte byteBuffer[numNodes];
Serial.readBytes(byteBuffer, numNodes);
for (int i = 0; i < NUM_LEDS; i++) {
leds.r = byteBuffer[i*3];
leds.g = byteBuffer[i*3+1];
leds.b = byteBuffer[i*3+2];
}
FastLED.show();
}
}
}
}
 
Last edited:
There are software applications which you can use (try eltima.com) for analysing serial port traffic. I have used these in the past when I was struggling with some Vixen / Arduino implementations. These will allow you to view exactly what the raw byte data looks like therefore how to work with it in any Arduino sketches.
 
I didn't use that specific one, but I did use something similar, but it wouldn't work because the COM port was busy. Anyways, I was able to get it to work eventually, and I used some of my lights to show me what was being outputted and stuff.
 
Back
Top