Thursday, January 1, 2015

Arduino Christmas Light Sequencer

I've always enjoyed watching those Youtube videos where someone has sequenced all their Christmas lights to music. Some are very elaborate. I wonder, what could I do with a Arduino and a SainSmart 8 relay board? I found a project on Instructables where a guy built his own relay board. Since I already have one from SainSmart, that eliminated half the complexity of the project right there. He already had the relay timing worked out, so I needed to figure out what notes to play, and put those notes into his sketch so that they played in sequence with the lights. I pulled up some sheet music only, and started a spread sheet, where each note is an event. I broke down the song into it's 57 notes, listed the word parts that go with each note, figured out the frequency of each note, and inserted the appropriate Tone / noTone pairs in the code.

Video posted below the code.

Arduino 2560 (you can use a UNO just as easily)
SainSmart 8 Channel Relay (16 channel available)
Piezo Module
Christmas Tree Light Strings (up to 8, or 16, can link up to 3 end to end)
After Christmas sales on light strings are awesome!

Note to Frequency List
Joy to the World sheet music
Virtual Piano

Connections:

on Relay board:
Gnd to Arduino Gnd
VCC to; Arduino +5
IN1-8 to Arduino 12-5

Piezo:
- to Arduino Gnd
S to Arduino 4 (I'm using a Mega 2560)

Christmas Light Strings:

Cut one wire that goes from the plug to the first light in the string. Loop it through one of the relays on the board, using the Normally Open and Common contact in series with that cut wire. See our previous relay post for details.

Code:

int tree1 = 5;
int tree2 = 6;
int tree3 = 7;
int tree4 = 8;
int tree5 = 9;
int tree6 = 10;
int tree7 = 11;
int tree8 = 12;
int s = 150;
int ds = 225;
int e = 300;
int de = 450;
int q = 600;
int dq = 900;
int h = 1200;
int dh = 1800;


int pPin = 4;

void setup()
{
  pinMode(tree1, OUTPUT);
  pinMode(tree2, OUTPUT);
  pinMode(tree3, OUTPUT);
  pinMode(tree4, OUTPUT);
  pinMode(tree5, OUTPUT);
  pinMode(tree6, OUTPUT);
  pinMode(tree7, OUTPUT);
  pinMode(tree8, OUTPUT);
  digitalWrite(tree1,LOW);
  delay(1000);
  digitalWrite(tree2,LOW);
  delay(1000);
  digitalWrite(tree3,LOW);
  delay(1000);
  digitalWrite(tree4,LOW);
  delay(1000);
  digitalWrite(tree5,LOW);
  delay(1000);
  digitalWrite(tree6,LOW);
  delay(1000);
  digitalWrite(tree7,LOW);
  delay(1000);
  digitalWrite(tree8,LOW);
  delay(1000);
  digitalWrite(tree1,HIGH);
  digitalWrite(tree2,HIGH);
  digitalWrite(tree3,HIGH);
  digitalWrite(tree4,HIGH);
  digitalWrite(tree5,HIGH);
  digitalWrite(tree6,HIGH);
  digitalWrite(tree7,HIGH);
  digitalWrite(tree8,HIGH);

}

void loop()
{


  // event 1
  noTone(pPin);
    digitalWrite(tree1, LOW);
  digitalWrite(tree8, LOW);
  tone(pPin, 261.63); // c4
  delay(q);
  noTone(pPin);
  digitalWrite(tree1, HIGH);
  digitalWrite(tree8, HIGH);
  // event 2
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);
  tone(pPin, 246.94);  // b3
  delay(de);
  noTone(pPin);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  // event 3
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);
  tone(pPin, 220); // a3
  delay(s);
  noTone(pPin);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  // event 4
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);
  tone(pPin, 196); // g3
  delay(1050);
  noTone(pPin);
  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  // event 5
  digitalWrite(tree1, LOW);
  digitalWrite(tree8, LOW);
  tone(pPin, 174.61); //f3
  delay(s);
  noTone(pPin);
  digitalWrite(tree1, HIGH);
  digitalWrite(tree8, HIGH);
  // event 6
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);
  tone(pPin, 164.81); //e3
  delay(q);
  noTone(pPin);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  // event 7
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);
  tone(pPin, 146.83); // d3
  delay(q);
  noTone(pPin);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  // event 8
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);
  tone(pPin, 130.81); //c3
  delay(dq);
  noTone(pPin);
  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  // event 9
  digitalWrite(tree1, LOW);
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);
  digitalWrite(tree8, LOW);
  tone(pPin, 196); // g3
  delay(e);
  noTone(pPin);
  digitalWrite(tree1, HIGH);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  digitalWrite(tree8, HIGH);
  // event 10
  digitalWrite(tree2, LOW);
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);
  digitalWrite(tree7, LOW);
  tone(pPin, 220); // a3
  delay(dq);
  noTone(pPin);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  digitalWrite(tree7, HIGH);
  // event 11
  digitalWrite(tree1, LOW);
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);
  digitalWrite(tree8, LOW);
  tone(pPin, 220);  // a3
  delay(e);
  noTone(pPin);
  digitalWrite(tree1, HIGH);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  digitalWrite(tree8, HIGH);
  // event 12
  digitalWrite(tree3, LOW);
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);
  digitalWrite(tree6, LOW);
  tone(pPin, 246.94); //b3
  delay(dq);
  noTone(pPin);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  digitalWrite(tree6, HIGH);
  // event 13
  digitalWrite(tree1, LOW);
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);
  digitalWrite(tree8, LOW);
  tone(pPin, 246.94);  //b3
  delay(e);
  noTone(pPin);
  digitalWrite(tree1, HIGH);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  digitalWrite(tree8, HIGH);
  // event 14
  digitalWrite(tree1, LOW);
  digitalWrite(tree2, LOW);
  digitalWrite(tree3, LOW);
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);
  digitalWrite(tree6, LOW);
  digitalWrite(tree7, LOW);
  digitalWrite(tree8, LOW);
  tone(pPin, 261.63); //c4
  delay(dq);
  noTone(pPin);
  digitalWrite(tree1, HIGH);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  digitalWrite(tree6, HIGH);
  digitalWrite(tree7, HIGH);
  digitalWrite(tree8, HIGH);
  // event 15
  digitalWrite(tree8, LOW);
  tone(pPin, 261.63); //c4
  delay(e);
  noTone(pPin);
  digitalWrite(tree8, HIGH);
  // event 16
  digitalWrite(tree1, LOW);
  tone(pPin, 261.63); //c4
  delay(e);
  noTone(pPin);
  digitalWrite(tree1, HIGH);
  // event 17
  digitalWrite(tree7, LOW);
  tone(pPin, 246.94); //b3
  delay(e);
  noTone(pPin);
  digitalWrite(tree7, HIGH);
  // event 18
  digitalWrite(tree2, LOW);
  tone(pPin, 220); //a3
  delay(e);
  noTone(pPin);
  digitalWrite(tree2, HIGH);
  // event 19
  digitalWrite(tree6, LOW);
  tone(pPin, 196); //g3
  delay(e);
  noTone(pPin);
  digitalWrite(tree6, HIGH);
  // event 20
  digitalWrite(tree3, LOW);
  tone(pPin, 196); //g3
  delay(de);
  noTone(pPin);
  digitalWrite(tree3, HIGH);
  // event 21
  digitalWrite(tree5, LOW);
  tone(pPin, 174.61); //f3
  delay(s);
  noTone(pPin);
  digitalWrite(tree5, HIGH);
  // event 22
  digitalWrite(tree4, LOW);
  tone(pPin, 164.81); //e3
  delay(e);
  noTone(pPin);
  digitalWrite(tree4, HIGH);
  // event 23
  digitalWrite(tree8, LOW);
  tone(pPin, 261.63); //c4
  delay(e);
  noTone(pPin);
  digitalWrite(tree8, HIGH);
  // event 24
  digitalWrite(tree1, LOW);
  tone(pPin, 261.63); //c4
  delay(e);
  noTone(pPin);
  digitalWrite(tree1, HIGH);
  // event 25
  digitalWrite(tree7, LOW);
  tone(pPin, 246.94); //b3
  delay(e);
  noTone(pPin);
  digitalWrite(tree7, HIGH);
  // event 26
  digitalWrite(tree2, LOW);
  tone(pPin, 220); //a3
  delay(e);
  noTone(pPin);
  digitalWrite(tree2, HIGH);
  // event 27
  digitalWrite(tree6, LOW);
  tone(pPin, 196); //g3
  delay(e);
  noTone(pPin);
  digitalWrite(tree6, HIGH);
  // event 27
  digitalWrite(tree3, LOW);
  tone(pPin, 196); //g3
  delay(de);
  noTone(pPin);
  digitalWrite(tree3, HIGH);
  // event 29
  digitalWrite(tree5, LOW);
  tone(pPin, 174.61); //f3
  delay(s);
  noTone(pPin);
  digitalWrite(tree5, HIGH);
  // event 30
  digitalWrite(tree4, LOW);
  tone(pPin, 164.81); //e3
  delay(e);
  noTone(pPin);
  digitalWrite(tree4, HIGH);
  // event 31
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);
  tone(pPin, 164.81); //e3
  delay(e);
  noTone(pPin);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  // event 32
  digitalWrite(tree1, LOW);
  digitalWrite(tree8, LOW);
  tone(pPin, 164.81); //e3
  delay(e);
  noTone(pPin);
  digitalWrite(tree1, HIGH);
  digitalWrite(tree8, HIGH);
  // event 33
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);
  tone(pPin, 164.81); //e3
  delay(e);
  noTone(pPin);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  // event 34
  digitalWrite(tree1, LOW);
  digitalWrite(tree8, LOW);
  tone(pPin, 164.81); //e3
  delay(e);
  noTone(pPin);
  digitalWrite(tree1, HIGH);
  digitalWrite(tree8, HIGH);
  // event 35
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);
  tone(pPin, 164.81); //e3
  delay(75);
  noTone(pPin);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  // event 36
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);
  tone(pPin, 174.61); //f3
  delay(75);
  noTone(pPin);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  // event 37
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);
  tone(pPin, 196); //g3
  delay(dq);
  noTone(pPin);
  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  // event 38
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);
  tone(pPin, 174.61); //f3
  delay(75);
  noTone(pPin);
  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  // event 39
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);
  tone(pPin, 164.81); //e3
  delay(75);
  noTone(pPin);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  // event 40
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);
  tone(pPin, 146.83); //d3
  delay(e);
  noTone(pPin);
  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  // event 41
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);
  tone(pPin, 146.83); //d3
  delay(e);
  noTone(pPin);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  // event 42
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);
  tone(pPin, 146.83); //d3
  delay(e);
  noTone(pPin);
  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  // event 43
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);
  tone(pPin, 146.83); //d3
  delay(75);
  noTone(pPin);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  // event 44
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);
  tone(pPin, 164.81); //e3
  delay(75);
  noTone(pPin);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  // event 45
  digitalWrite(tree1, LOW);
  digitalWrite(tree8, LOW);
  tone(pPin, 174.61); //f3
  delay(dq);
  noTone(pPin);
  digitalWrite(tree1, HIGH);
  digitalWrite(tree8, HIGH);
  // event 46
  digitalWrite(tree1, LOW);
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);
  digitalWrite(tree8, LOW);
  tone(pPin, 164.81); //e3
  delay(75);
  noTone(pPin);
  digitalWrite(tree1, HIGH);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  digitalWrite(tree8, HIGH);
  // event 47
  digitalWrite(tree2, LOW);
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);
  digitalWrite(tree7, LOW);
  tone(pPin, 146.83); //d3
  delay(75);
  noTone(pPin);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  digitalWrite(tree7, HIGH);
  // event 48
  digitalWrite(tree3, LOW);
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);
  digitalWrite(tree6, LOW);
  tone(pPin, 130.81); //c3
  delay(e);
  noTone(pPin);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  digitalWrite(tree6, HIGH);
  // event 49
  digitalWrite(tree1, LOW);
  digitalWrite(tree2, LOW);
  digitalWrite(tree3, LOW);
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);
  digitalWrite(tree6, LOW);
  digitalWrite(tree7, LOW);
  digitalWrite(tree8, LOW);
  tone(pPin, 261.63); //c4
  delay(q);
  noTone(pPin);
  digitalWrite(tree1, HIGH);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  digitalWrite(tree6, HIGH);
  digitalWrite(tree7, HIGH);
  digitalWrite(tree8, HIGH);
  // event 50
  digitalWrite(tree1, LOW);
  digitalWrite(tree8, LOW);
  tone(pPin, 220); //a3
  delay(e);
  noTone(pPin);
  digitalWrite(tree1, HIGH);
  digitalWrite(tree8, HIGH);
  // event 51
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);
  tone(pPin, 196); //g3
  delay(de);
  noTone(pPin);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  // event 52
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);
  tone(pPin, 174.61); //f3
  delay(s);
  noTone(pPin);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  // event 53
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);
  tone(pPin, 164.81); //e3
  delay(e);
  noTone(pPin);
  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  // event 54
  digitalWrite(tree3, LOW);
  digitalWrite(tree6, LOW);
  tone(pPin, 174.61); //f3
  delay(e);
  noTone(pPin);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree6, HIGH);
  // event 55
  digitalWrite(tree2, LOW);
  digitalWrite(tree7, LOW);
  tone(pPin, 164.81); //e3
  delay(q);
  noTone(pPin);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree7, HIGH);
  // event 56
  digitalWrite(tree1, LOW);
  digitalWrite(tree8, LOW);
  tone(pPin, 146.83); //d3
  delay(q);
  noTone(pPin);
  digitalWrite(tree1, HIGH);
  digitalWrite(tree8, HIGH);
  // event 57
  digitalWrite(tree1, LOW);
  digitalWrite(tree2, LOW);
  digitalWrite(tree3, LOW);
  digitalWrite(tree4, LOW);
  digitalWrite(tree5, LOW);
  digitalWrite(tree6, LOW);
  digitalWrite(tree7, LOW);
  digitalWrite(tree8, LOW);
  tone(pPin, 130.81); //c3
  delay(h);
  noTone(pPin);
  digitalWrite(tree1, HIGH);
  digitalWrite(tree2, HIGH);
  digitalWrite(tree3, HIGH);
  digitalWrite(tree4, HIGH);
  digitalWrite(tree5, HIGH);
  digitalWrite(tree6, HIGH);
  digitalWrite(tree7, HIGH);
  digitalWrite(tree8, HIGH);
  delay(10000);

}



Tuesday, December 30, 2014

Programming the Leixen VV-898 with CHIRP

Previously I posted about manually programming the new Leixen VV-898 from Radioddity, and tonight had the opportunity to program the radio using CHIRP and the programming cable Radioddity just sent me. I downloaded CHIRP, plugged in the cable, and downloaded the settings from my radio. I made a couple of changes, and uploaded the changes back to the radio. What follows are the steps I took, and a video of my setup. Enjoy!


  • Install the CHIRP software 
  • If you get a message that the software may not have installed properly, just override and click the button to tell it that it did.
  • Plug in usb cable into the computer, wait for prolific driver to install (can take a few minutes). then plug the other end into the radio (microphone jack)
  • Now run the chirp program (it will be on your programs menu)
  • Click "Radio" on the menu, and choose "Download from radio"
  • You will be asked for the port number, vendor (Leixen), and the model (VV-898). click ok.
  • A "cloning from radio" progress bar pops up.
  • When it's done, the radio will play a  tune, and a spreadsheet of your settings will show.
  • Make changes per your repeater requirements. 
  • Click radio on the menu, and upload your changes back to the radio.
Official CHIRP Documentation - http://chirp.danplanet.com/projects/chirp/wiki/Beginners_Guide

Video:

D Shell connectors, DB-9's and other Nonsense

30 + years in IT, and I remember many tech's and computer folks talking about DB-9 serial connectors. I needed a d connector for a joystick to Arduino project, and found to my amazement we've been calling them wrong for years (ok, so I kinda remember the correct terminology, but the wrong ones were so commonly used). The Joystick uses a DA-15, the Serial a DE-9, and the printer used a DB-25. D stood for the shape of the shell, the second letter (A, B, C, or D) stood for the size, and the numeral, the number of pins or sockets. VGA is a DE-15HD, or High Density.

http://en.wikipedia.org/wiki/D-subminiature


I don't even want to get into the "RJ-45" Connector naming issue, but I guess I will. Ethernet does not use a RJ-45 connector. Ethernet uses a 8P8C connector. a RJ-45 is a mechanically-keyed variation of the 8P8C body with an extra tab that prevents it from mating with other connectors, used in telecom applications.

http://en.wikipedia.org/wiki/Registered_jack#RJ45

Hope this sheds some light on issues you never knew were an issue, LOL