Show Posts
Pages: 1 2 [3]
31  Development / Other Hardware Development / Re: Christmas Lights Control System -Arduino Mega - 16 Channel Relay Board on: December 08, 2012, 04:22:31 pm
Here is the last of the project build videos, will have another video or two of it running with my lights later.

http://www.youtube.com/watch?v=kqm_ts3lvGU&feature=youtu.be
32  Development / Other Hardware Development / Re: Christmas Lights Control System -Arduino Mega - 16 Channel Relay Board on: December 08, 2012, 03:05:33 pm
BTW the project is done, there will be new videos up on youtube tonight.
33  Development / Other Hardware Development / Re: Christmas Lights Control System -Arduino Mega - 16 Channel Relay Board on: December 08, 2012, 03:04:16 pm
Here is an update to the code.  I've added a power on self test that runs through each channel one at a time turning it on for 1.5 seconds.

Code:
#define CHANNEL01  2
#define CHANNEL02  3
#define CHANNEL03  4
#define CHANNEL04  5
#define CHANNEL05  6
#define CHANNEL06  7
#define CHANNEL07  8
#define CHANNEL08  9
#define CHANNEL09  10
#define CHANNEL10  11
#define CHANNEL11  12
#define CHANNEL12  13
#define CHANNEL13  44
#define CHANNEL14  45
#define CHANNEL15  46
#define CHANNEL16  47

#define RANDOM_MODE_PININ 52
#define RANDOM_MODE_PINOUT 53
#define RANDOM_MODE_SPEED 1000

int channels[] = {CHANNEL01,CHANNEL02,CHANNEL03,CHANNEL04,CHANNEL05,CHANNEL06,CHANNEL07,CHANNEL08,CHANNEL09,
CHANNEL10,CHANNEL11,CHANNEL12,CHANNEL13,CHANNEL14,CHANNEL15,CHANNEL16};

#define CHANNEL_COUNT 16
#define VIXEN_COM_SPEED 57600
#define PC_COM_SPEED 57600

boolean startingVixen = true;

void setup()
{
  Serial.begin(PC_COM_SPEED);
  Serial1.begin(VIXEN_COM_SPEED);
 
  pinMode(CHANNEL01,OUTPUT);
  pinMode(CHANNEL02,OUTPUT);
  pinMode(CHANNEL03,OUTPUT);
  pinMode(CHANNEL04,OUTPUT);
  pinMode(CHANNEL05,OUTPUT);
  pinMode(CHANNEL06,OUTPUT);
  pinMode(CHANNEL07,OUTPUT);
  pinMode(CHANNEL08,OUTPUT);
  pinMode(CHANNEL09,OUTPUT);
  pinMode(CHANNEL10,OUTPUT);
  pinMode(CHANNEL11,OUTPUT);
  pinMode(CHANNEL12,OUTPUT);
  pinMode(CHANNEL13,OUTPUT);
  pinMode(CHANNEL14,OUTPUT);
  pinMode(CHANNEL15,OUTPUT);
  pinMode(CHANNEL16,OUTPUT);
 
  // set up the switch for Vixen or Random mode
  pinMode(RANDOM_MODE_PININ, INPUT);
  digitalWrite(RANDOM_MODE_PININ,HIGH); // turn on the internal pull-up resistor
  pinMode(RANDOM_MODE_PINOUT, OUTPUT);
 
  turnLightsOff(); 
  powerOnSelfTest();
}

// !!!! note the PWM values that need to be sent to the relay board are reversed from the
// values comming in from Vixen.  Vixen 0-255 (off-on), Relays 255-0 (off-on)

void loop()
{
  if(digitalRead(RANDOM_MODE_PININ)==LOW){ // blink at random mode
    startingVixen=true;
    doRandomLights();
  }else{ // play from Vixen mode
    if(startingVixen==true)
      turnLightsOff();
    readFromVixen();
  }
}

void powerOnSelfTest()
{
    Serial.println("Power on self test running.");
    for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
      analogWrite(channels[channelIndex], 0); // turn on one channel at a time
      delay(1500); // wait 1.5 seconds
      analogWrite(channels[channelIndex], 255);
    }
    turnLightsOff();
}

void turnLightsOff()
{
  //turn them all off
  for(int channelIndex=0;channelIndex<16;channelIndex++){
    analogWrite(channels[channelIndex], 255);
  }
}

void doRandomLights()
{
    randomSeed(analogRead(0));
    Serial.println("Writting random values.");
    for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
      int randNumber = random(255);
      randNumber = map(randNumber, 0, 255, 255, 0);
      analogWrite(channels[channelIndex], randNumber);
      Serial.print(randNumber, DEC);
      Serial.print(",");
    }
    Serial.println("");
    delay(random(100,RANDOM_MODE_SPEED));
}

void outputToLights(unsigned char* buffer)
{
    for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
      analogWrite(channels[channelIndex], buffer[channelIndex]);
      Serial.print(buffer[channelIndex], DEC);
      Serial.print(",");
    }
    Serial.println("");
}

void readFromVixen()
{
  Serial.println("Waiting for data from Vixen.");
  startingVixen = false;
  char *footer="VIXEN_END";
  unsigned char buffer[CHANNEL_COUNT];
  char buffer2[CHANNEL_COUNT];
  int index=0;
  unsigned long time = millis();

  waitForVixenHeader();
  while (true) {
    int inByte = Serial1.read();
    if(inByte==-1){
      if(index==0 && millis()-time>1000) // we haven't read anything in a second
        return;
      continue;
    }
    time = millis();
    int lightByte = map(inByte, 0, 255, 255, 0);
    buffer[index] = lightByte;
    buffer2[index] = inByte;
    buffer[index+1] = 0;
    buffer2[index+1] = 0;
    index++;
    if(index==9 && strcmp(footer,buffer2)==0){
      Serial.println(footer);
      return;
    }
    else if(index==CHANNEL_COUNT){
      outputToLights(buffer);
      index=0;
    }
  }
  Serial.println("");
}

void waitForVixenHeader()
{
  char *header="VIXEN_START";
  char buffer[12];
  int index = 0;
  unsigned long time = millis();

  while (true) {
    int inByte = Serial1.read();
    if(inByte==-1){
      if(index==0 && millis()-time>1000) // we haven't read anything in a second
        return;
      continue;
    }
    time = millis();
    buffer[index] = inByte;
    if(buffer[index]!=header[index]) {// not the right sequence restart
      index=-1;
    }
    buffer[index+1] = 0; // add null
    index++;
    if(index==11 && strcmp(header,buffer)==0){
      Serial.println(header);
      return;
    }
  }
}

34  Development / Other Hardware Development / Re: Christmas Lights Control System -Arduino Mega - 16 Channel Relay Board on: December 08, 2012, 03:03:16 pm
Yep, i put them in the array so I could easily rearrange the channels.  I get you point though. smiley
35  Development / Other Hardware Development / Re: Christmas Lights Control System -Arduino Mega - 16 Channel Relay Board on: December 07, 2012, 09:46:35 pm
Here is the Arduino 1.0.1 code for controlling the lights via Vixen.  It also includes a random mode for when you just want the lights to do something without having to have a Vixen program running.

Code:
#define CHANNEL01  2
#define CHANNEL02  3
#define CHANNEL03  4
#define CHANNEL04  5
#define CHANNEL05  6
#define CHANNEL06  7
#define CHANNEL07  8
#define CHANNEL08  9
#define CHANNEL09  10
#define CHANNEL10  11
#define CHANNEL11  12
#define CHANNEL12  13
#define CHANNEL13  44
#define CHANNEL14  45
#define CHANNEL15  46
#define CHANNEL16  47

#define RANDOM_MODE_PININ 52
#define RANDOM_MODE_PINOUT 53
#define RANDOM_MODE_SPEED 1000

int channels[] = {CHANNEL01,CHANNEL02,CHANNEL03,CHANNEL04,CHANNEL05,CHANNEL06,CHANNEL07,CHANNEL08,CHANNEL09,
CHANNEL10,CHANNEL11,CHANNEL12,CHANNEL13,CHANNEL14,CHANNEL15,CHANNEL16};

#define CHANNEL_COUNT 16
#define VIXEN_COM_SPEED 57600
#define PC_COM_SPEED 57600

boolean startingVixen = true;

void setup()
{
  Serial.begin(PC_COM_SPEED);
  Serial1.begin(VIXEN_COM_SPEED);
 
  pinMode(CHANNEL01,OUTPUT);
  pinMode(CHANNEL02,OUTPUT);
  pinMode(CHANNEL03,OUTPUT);
  pinMode(CHANNEL04,OUTPUT);
  pinMode(CHANNEL05,OUTPUT);
  pinMode(CHANNEL06,OUTPUT);
  pinMode(CHANNEL07,OUTPUT);
  pinMode(CHANNEL08,OUTPUT);
  pinMode(CHANNEL09,OUTPUT);
  pinMode(CHANNEL10,OUTPUT);
  pinMode(CHANNEL11,OUTPUT);
  pinMode(CHANNEL12,OUTPUT);
  pinMode(CHANNEL13,OUTPUT);
  pinMode(CHANNEL14,OUTPUT);
  pinMode(CHANNEL15,OUTPUT);
  pinMode(CHANNEL16,OUTPUT);
 
  // set up the switch for Vixen or Random mode
  pinMode(RANDOM_MODE_PININ, INPUT);
  digitalWrite(RANDOM_MODE_PININ,HIGH); // turn on the internal pull-up resistor
  pinMode(RANDOM_MODE_PINOUT, OUTPUT);
 
  turnLightsOff(); 
}

void loop()
{
  if(digitalRead(RANDOM_MODE_PININ)==LOW){ // blink at random mode
    startingVixen=true;
    doRandomLights();
  }else{ // play from Vixen mode
    if(startingVixen==true)
      turnLightsOff();
    readFromVixen();
  }
}

void turnLightsOff()
{
  //turn them all off
  for(int channelIndex=0;channelIndex<16;channelIndex++){
    analogWrite(channels[channelIndex], 0);
  }
}

void doRandomLights()
{
    randomSeed(analogRead(0));
    Serial.println("Writting random values.");
    for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
      int randNumber = random(255);
      analogWrite(channels[channelIndex], randNumber);
      Serial.print(randNumber, DEC);
      Serial.print(",");
    }
    Serial.println("");
    delay(random(100,RANDOM_MODE_SPEED));
}

void outputToLights(unsigned char* buffer)
{
    for(int channelIndex=0;channelIndex<CHANNEL_COUNT;channelIndex++){
      analogWrite(channels[channelIndex], buffer[channelIndex]);
      Serial.print(buffer[channelIndex], DEC);
      Serial.print(",");
    }
    Serial.println("");
}

void readFromVixen()
{
  Serial.println("Waiting for data from Vixen.");
  startingVixen = false;
  char *footer="VIXEN_END";
  unsigned char buffer[CHANNEL_COUNT];
  char buffer2[CHANNEL_COUNT];
  int index=0;
  unsigned long time = millis();

  waitForVixenHeader();
  while (true) {
    int inByte = Serial1.read();
    if(inByte==-1){
      if(index==0 && millis()-time>1000) // we haven't read anything in a second
        return;
      continue;
    }
    time = millis();
    buffer[index] = inByte;
    buffer2[index] = inByte;
    buffer[index+1] = 0;
    buffer2[index+1] = 0;
    index++;
    if(index==9 && strcmp(footer,buffer2)==0){
      Serial.println(footer);
      return;
    }
    else if(index==CHANNEL_COUNT){
      outputToLights(buffer);
      index=0;
    }
  }
  Serial.println("");
}

void waitForVixenHeader()
{
  char *header="VIXEN_START";
  char buffer[12];
  int index = 0;
  unsigned long time = millis();

  while (true) {
    int inByte = Serial1.read();
    if(inByte==-1){
      if(index==0 && millis()-time>1000) // we haven't read anything in a second
        return;
      continue;
    }
    time = millis();
    buffer[index] = inByte;
    if(buffer[index]!=header[index]) {// not the right sequence restart
      index=-1;
    }
    buffer[index+1] = 0; // add null
    index++;
    if(index==11 && strcmp(header,buffer)==0){
      Serial.println(header);
      return;
    }
  }
}



36  Development / Other Hardware Development / Re: Christmas Lights Control System -Arduino Mega - 16 Channel Relay Board on: December 06, 2012, 10:14:24 pm
I'm up to part 7 now.  Light show is in the near future.

http://www.youtube.com/watch?v=O8RZFEsQImk&feature=youtu.be
37  Development / Other Hardware Development / Re: Estimated market for shield boards on: December 03, 2012, 11:51:22 pm
If you can produce something better than what is out there, do it.  There are some of us that would rather pay higher prices for better products.  Provide good docs and support and you should be able to make some money.
38  Development / Other Hardware Development / Christmas Lights Control System -Arduino Mega - 16 Channel Relay Board on: December 03, 2012, 11:37:24 pm
I hope this is the right area to share this.

Occasionally in order to get myself motivated to finish an existing project I need to jump onto another project for a break.  In this case I’ve been trying to get motivated to finish up my latest robot project for some time now and just can’t seem to get it done.  So, I’ve started a new project which is fun and will be fairly easy to complete, a Christmas lights controller with synchronized music.  You can buy these kinds of systems but building it is really the fun part for me.

The intent is to use an Arduino Mega 2560 microcontroller board (http://arduino.cc/en/Main/ArduinoBoardMega ), a 16-Channel 12V Relay Module and the Vixen software package (http://vixenlights.com ).

Vixen is a .NET based software package that lets you create lighting sequences to music.  It has a plug-in architecture for developers to create custom plug-ins for outputting the data for the sequences in whatever format that is needed.  It also allows you to define the number of “channels” to control lights on.  Basically a channel can be thought of as a single string of lights.  You can perform various types of commands against each channel for each “frame” of the sequence.  The cool part is you can define the number of frames per second, so you might say I want 10 frames per second, this allows you to command each channel to do something different 10 times every second.

The arduino will be pumped data from the Vixen software, running on a PC, via a USB serial connection. This data will tell the Arduino which lights to turn on and off via the relay module for each frame of the sequence. The relay module will do this by turning power on and off to 16 separate 120V AC wall outlets.  In order to do things like have a string of lights be at half brightness the data from vixen will send the channel a value of 128 (the value range for a channel is 0-255 off-fully on), the arduino will then use PWM (pulse width modulation, nothing more than turning something on/off really fast) to flip the relay for that channel on/off fast enough to make the lights look like they are at half brightness.

I'm fairly sure the hardware part isn't going to be a big problem. More likely the use of the data coming from Vixen into the Arduino and controlling the relays at a fast speed will probably cause me the most trouble.

Here is my YouTube channel were I am posting videos of my progress: http://www.youtube.com/user/zparticle

Here are the first videos I have put up:

Christmas Lights Control System - Part 1 -
Christmas Lights Control System - Part 2-1 -
Christmas Lights Control System - Part 2-2 -
Christmas Lights Control System - Part 2-3 -
Christmas Lights Control System - Part 3-1 -
Christmas Lights Control System - Part 3-2 -
Christmas Lights Control System - Part 4-1 -

If you are wondering about the weird numbering it's because I don't have decent video editing software on my Windows machine and I don't want to deal with my Mac.  I welcome any ideas on improvements. I'm already getting prepared for the relays not being able to switch fast enough to do fades.  If that turns out to be the case I will continue the series with videos using dimming circuits with random phase TRIACs.

Oh, and if I'm using the wrong terminology in the videos, please let me know.
39  Using Arduino / Displays / Re: Seeed studio TFT touch shield, what gives? on: November 22, 2012, 05:34:20 pm
If you need a simple GUI library for the v1 SeeedStudio 2.8" TFT Touch Screen check out this lib I just put up:

http://code.google.com/p/touch-screen-menu-library/

also you can see a little video of it at:

http://www.youtube.com/watch?v=sOUUsHCkTHI&feature=youtu.be
40  Using Arduino / Programming Questions / Re: arduino 2.8'' TFT Touch Shield seeed on: November 22, 2012, 05:33:57 pm
If you need a simple GUI library for the v1 SeeedStudio 2.8" TFT Touch Screen check out this lib I just put up:

http://code.google.com/p/touch-screen-menu-library/

also you can see a little video of it at:

http://www.youtube.com/watch?v=sOUUsHCkTHI&feature=youtu.be
41  Using Arduino / Displays / Re: Seeedino Touch Screen V1.0 from Radio Shack on: November 22, 2012, 04:58:34 pm
If you need a simple GUI library for the v1 SeeedStudio 2.8" TFT Touch Screen check out this lib I just put up:

http://code.google.com/p/touch-screen-menu-library/

also you can see a little video of it at:

http://www.youtube.com/watch?v=sOUUsHCkTHI&feature=youtu.be
Pages: 1 2 [3]