Author Topic: SSR and arduino  (Read 411 times)

Offline Gammohr

  • Newbie
  • *
  • Posts: 3
    • View Profile
SSR and arduino
« on: September 15, 2020, 11:47:03 AM »
I cannot get xlights to control my relays.  I read about many people that have done this.  I have the relays working great with vixen but not with xlights.  Do I set up the adruino as a generic serial like in vixen?  Renard? DMX?  Also, when I go to layout and set up a model, it won't let me change from ws2811 to anything else (I was told to change it to renard).  Can anyone give me the steps to setting up my arduino controlling relays with xlights?  I really want to use xlights instead of xixen.  Thank you.

Offline keithsw1111

  • Administrator
  • Hero Member
  • *****
  • Posts: 2733
    • View Profile
    • Kellyville Christmas Lights
Re: SSR and arduino
« Reply #1 on: September 18, 2020, 07:41:50 PM »
It all depends on your arduino sketch. You need to match protocols so xLights sends what your sketch expects.

Offline Gammohr

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: SSR and arduino
« Reply #2 on: September 19, 2020, 08:48:36 PM »
This is the arduino sketch I am trying to use.  Any thoughts/advice would be greatly appreciated.

_____________________________________________

// 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 8

// 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


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

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);
}
}
}

Offline Sixty

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: SSR and arduino
« Reply #3 on: September 24, 2020, 10:31:55 AM »
It looks like you're using serial communication and turning that into digital outputs.  So, I suggest you stick a multimeter on one of your outputs and have xLights set alternate all your channels between on and off...then measure your pin outputs on the controller to figure out whether they are being turned on or off.  I'm not the xLights expert nor am I an expert with C/C++.  But, measuring an output is pretty easy and that will tell you whether or not your outputs are doing what you expect the Uno to be doing.  And, like what was already suggested, make sure the protocol is what you expect it to be.  I haven't googled your library to determine what AVR/WDT is.  But, you should probably follow whatever that library tells you to as far as the protocol goes...

And, good luck!