Skip navigation

Arduino

4 Posts authored by: Frederick Vandenbosch Top Member

Previous posts in this project:

 

 

Introduction

 

OK, this will be the final post for the Internet of Holiday Lights RoadTest Plus. It's been fun, frustrating, collaborative, etc ...

  • Fun, because I really enjoyed working with the Yun. I love Arduinos and the Yun's wireless programming and network connectivity just make it even better!
  • Frustrating, because I didn't get to where I wanted to be, due to unforeseen difficulties with the build.
  • Collaborative, because of the sharing and teaming up for special features.

 

Get ready for some picture overload! (the gallery function would've come in handy )

 

Building the Tree

 

The biggest (and hardest as turned out) part of this project was the build. I wanted to make a Christmas tree with both classic and modern elements.

 

The idea was to hollow a log and stuff the electronics inside. Unfortunately, hollowing the log did not work as planned, and my tools were not suited for this kind of work. I ended up going for an alternative with a plastic cylinder for the base after having wasted too much time on the log.

IMG_5672.JPGIMG_5724.JPGIMG_5725.JPG

The tree itself was easier. Using threaded rods cuts in different lengths, I created a tree structure with branches. The expectation was to have a long LED strip go from branch to branch in a spiral shape. This lead to the next problem with the build: the strip was not rigid enough to keep the spiral shape and would just hang loosely. To solve that issue, I came up with the idea to use some fence wire to which the LED strip would be attached. That worked.

IMG_5727.JPGIMG_5730.JPGDSCN3171.JPG

Finally, all the wires needed to be guided to the base of the tree and hidden as wel as possible. Zip ties came in extremely handy!

The tree is ready! It's not late for Christmas 2014, it's just ready a bit early for Christmas 2015

DSCN3174.JPGDSCN3175.JPGDSCN3176.JPG

Now, where do I store this until Christmas ... ?

 

Conclusion

 

We are now the proud owners of a digital Christmas tree which can be controlled either manually using our smartphone or tablet or automatically depending on the Christmas song that is currently playing.

 

Oh ... I almost forgot. It also tells me when other fellow e14 members' project is online!

 

This was fun building, I hope you had fun reading!

Previous posts in this project:

 

 

Introduction

 

One of the features I wanted to implement in this project, was to have the Christmas tree change colors and animations based on the title of the song that is being played at that moment.

The idea is to stream from an internet radio station, parse the song title and find certain keywords. Depending on the keyword, a combination of colors and animations would be applied.

 

Music

 

The play the music, I'm using the Raspberry Pi on which I'm running openHAB. Using MPD and MPC it is possible to play an internet radio stream and depending on the channel, obtain the title and performer.

 

Installing MPD (Music Player Daemon) and MPC (Music Player Controller) is easy:

pi@HolidayLights ~ $ sudo apt-get install mpd mpc







 

Once it is installed, it is possible to add an internet radio station to the playlist.

pi@HolidayLights ~ $ sudo mpc add http://helsinki.radiostreamlive.com/radiosantaclaus_mp3-high







 

The next thing to do, is to start playing the item in the playlist:

pi@HolidayLights ~ $ sudo mpc play
http://helsinki.radiostreamlive.com/radiosantaclaus_mp3-high
[playing] #1/1   0:00/0:00 (0%)
volume:  0%   repeat: off   random: off   single: off   consume: off







 

Once the item is playing, the status can be queried. This should provide information on the song as well. This specific command will be useful to parse the song title from.

pi@HolidayLights ~ $ sudo mpc status
Radio Santa Claus: Mariah Carey - O Holy Night
[playing] #1/1   0:03/0:00 (0%)
volume:  0%   repeat: off   random: off   single: off   consume: off







 

OK, with this, the music is taken care of, and the song information is available for further processing ... let's do that now!

 

Parsing

 

To process the song title, I'm using a Python script, called from openHAB using the "exec" binding.

 

The script takes care of parsing the song title from the "mpc status" command's output. This is the script:

 

pi@HolidayLights /opt/openhab/addons $ cat /home/pi/xmasradio.py

#!/usr/bin/env python
import subprocess

output = subprocess.check_output("mpc status | grep 'Radio Santa Claus:'", shell=True, stderr=subprocess.STDOUT)
output = output[output.find("-")+2:]

print output






 

Executing the script manually returns the following:

 

pi@HolidayLights ~ $ sudo ./xmasradio.py
All I Want For Christmas Is You

 

To do the same, but from openHAB, an entry is added to the items and the sitemap to call the script and bind to its output.

 

Item:

String xmasSong "Current song [%s]" (All) {exec="<[/home/pi/xmasradio.py:10000:REGEX((.*?))]"}





 

Sitemap:

        Frame label="Song" {
                Text item=xmasSong
        }





 

The result in the openHAB GUI:

Screen Shot 2015-01-21 at 19.40.27.png

 

Checking the openHAB logs, the song titles are properly updated with every new song:


2015-01-21 18:36:25 - xmasSong state updated to Oh Holy Night
2015-01-21 18:36:38 - xmasSong state updated to Oh Holy Night
2015-01-21 18:36:52 - xmasSong state updated to When My Heart Finds Christmas
2015-01-21 18:37:05 - xmasSong state updated to When My Heart Finds Christmas
2015-01-21 18:37:19 - xmasSong state updated to When My Heart Finds Christmas
2015-01-21 18:37:31 - xmasSong state updated to When My Heart Finds Christmas
2015-01-21 18:37:45 - xmasSong state updated to When My Heart Finds Christmas
2015-01-21 18:37:58 - xmasSong state updated to When My Heart Finds Christmas
2015-01-21 18:38:11 - xmasSong state updated to Visit now: radiosantaclaus.com -
2015-01-21 18:38:31 - xmasSong state updated to When My Heart Finds Christmas
2015-01-21 18:38:49 - xmasSong state updated to When My Heart Finds Christmas
2015-01-21 18:39:06 - xmasSong state updated to When My Heart Finds Christmas
2015-01-21 18:39:21 - xmasSong state updated to When My Heart Finds Christmas
2015-01-21 18:39:40 - xmasSong state updated to When My Heart Finds Christmas
2015-01-21 18:40:02 - xmasSong state updated to When My Heart Finds Christmas
2015-01-21 18:40:16 - xmasSong state updated to When My Heart Finds Christmas
2015-01-21 18:40:32 - xmasSong state updated to When My Heart Finds Christmas
2015-01-21 18:40:47 - xmasSong state updated to When My Heart Finds Christmas
2015-01-21 18:41:00 - xmasSong state updated to When My Heart Finds Christmas
2015-01-21 18:41:14 - xmasSong state updated to All I Want For Christmas (Is My Two Front Teeth)
2015-01-21 18:41:28 - xmasSong state updated to Visit now: radiosantaclaus.com -
2015-01-21 18:41:42 - xmasSong state updated to All I Want For Christmas (Is My Two Front Teeth)
2015-01-21 18:41:55 - xmasSong state updated to All I Want For Christmas (Is My Two Front Teeth)
2015-01-21 18:42:10 - xmasSong state updated to All I Want For Christmas (Is My Two Front Teeth)
2015-01-21 18:42:23 - xmasSong state updated to All I Want For Christmas (Is My Two Front Teeth)
2015-01-21 18:42:37 - xmasSong state updated to All I Want For Christmas (Is My Two Front Teeth)
2015-01-21 18:42:53 - xmasSong state updated to All I Want For Christmas (Is My Two Front Teeth)
2015-01-21 18:43:07 - xmasSong state updated to All I Want For Christmas (Is My Two Front Teeth)
2015-01-21 18:43:20 - xmasSong state updated to All I Want For Christmas (Is My Two Front Teeth)
2015-01-21 18:43:35 - xmasSong state updated to All I Want For Christmas (Is My Two Front Teeth)
2015-01-21 18:43:48 - xmasSong state updated to All I Want For Christmas (Is My Two Front Teeth)
2015-01-21 18:44:03 - xmasSong state updated to Sleigh Ride
2015-01-21 18:44:17 - xmasSong state updated to Sleigh Ride
2015-01-21 18:44:30 - xmasSong state updated to Sleigh Ride
2015-01-21 18:44:44 - xmasSong state updated to Sleigh Ride
2015-01-21 18:44:57 - xmasSong state updated to Visit now: radiosantaclaus.com -
2015-01-21 18:45:10 - xmasSong state updated to Sleigh Ride
2015-01-21 18:45:23 - xmasSong state updated to Sleigh Ride
2015-01-21 18:45:36 - xmasSong state updated to Sleigh Ride
2015-01-21 18:45:51 - xmasSong state updated to Sleigh Ride
2015-01-21 18:46:02 - xmasSong state updated to Merry Christmas For Everyone
2015-01-21 18:46:15 - xmasSong state updated to Merry Christmas For Everyone
2015-01-21 18:46:29 - xmasSong state updated to Merry Christmas For Everyone
2015-01-21 18:46:40 - xmasSong state updated to Merry Christmas For Everyone
2015-01-21 18:46:55 - xmasSong state updated to Merry Christmas For Everyone





 

Action

 

With the song title parsed, it's time to do something with it and have some pretty colors light up

 

An openHAB rule is in charge of identifying keywords and changing the colors based on those keywords. The rule could look like this, but can be customised at will:

 

rule "Parse Song Title"
when
        Item xmasSong changed
then
        var song = xmasSong.state.toString.trim
        logInfo("FILE", "Song: " + song)


        if(song.contains("radiosantaclaus")) {
                // do nothing, not a song title
                logInfo("FILE", "Match for 'radiosantaclaus', skip")
        } else if(song.contains("Christmas")) {
                logInfo("FILE", "Match for 'Christmas'")
                sendCommand( TreeLightColor, "255,0,0" )
                sendCommand( TopperLightColor, "0,255,20" )
                sendCommand( TopperLightColor2, "0,0,0" )
        } else if(song.contains("Santa")) {
                logInfo("FILE", "Match for 'Santa'")
                sendCommand( TreeLightColor, "255,0,0" )
                sendCommand( TopperLightColor, "255,255,255" )
                sendCommand( TopperLightColor2, "0,0,0" )
        } else if(song.contains("Snow")) {
                logInfo("FILE","Match for 'Snow'")
                sendCommand( TreeLightColor, "255,255,255" )
                sendCommand( TopperLightColor, "255,255,255" )
                sendCommand( TopperLightColor2, "0,0,0" )
        } else {
                logInfo("FILE","No match")
                sendCommand( TreeLightColor, "0,255,0" )
                sendCommand( TopperLightColor, "255,0,0" )
                sendCommand( TopperLightColor2, "0,0,0" )
        }
end




 

I gradually added more keywords and matching colors as songs played and I discovered more song titles.

The song titles are logged, and when there is no match, this is also reported. This allows me to check back later and add keywords for those songs as well.

 

2015-01-21 20:33:02.148 [INFO ] [org.openhab.model.script.FILE ] - Song: Silent Night
2015-01-21 20:33:03.653 [INFO ] [org.openhab.model.script.FILE ] - Match for 'Night'
2015-01-21 20:34:15.824 [INFO ] [org.openhab.model.script.FILE ] - Song: Visit now: radiosantaclaus.com -
2015-01-21 20:34:16.206 [INFO ] [org.openhab.model.script.FILE ] - Match for 'radiosantaclaus', skip
2015-01-21 20:34:40.592 [INFO ] [org.openhab.model.script.FILE ] - Song: Silent Night
2015-01-21 20:34:40.780 [INFO ] [org.openhab.model.script.FILE ] - Match for 'Night'
2015-01-21 20:36:44.820 [INFO ] [org.openhab.model.script.FILE ] - Song: Frosty The Snowman
2015-01-21 20:36:45.263 [INFO ] [org.openhab.model.script.FILE ] - Match for 'Snow'
2015-01-21 20:37:48.321 [INFO ] [org.openhab.model.script.FILE ] - Song: Visit now: radiosantaclaus.com -
2015-01-21 20:37:48.350 [INFO ] [org.openhab.model.script.FILE ] - Match for 'radiosantaclaus', skip
2015-01-21 20:38:00.437 [INFO ] [org.openhab.model.script.FILE ] - Song: Frosty The Snowman
2015-01-21 20:38:00.596 [INFO ] [org.openhab.model.script.FILE ] - Match for 'Snow'
2015-01-21 20:41:05.943 [INFO ] [org.openhab.model.script.FILE ] - Song: Visit now: radiosantaclaus.com -
2015-01-21 20:41:05.965 [INFO ] [org.openhab.model.script.FILE ] - Match for 'radiosantaclaus', skip
2015-01-21 20:41:31.507 [INFO ] [org.openhab.model.script.FILE ] - Song: Frosty The Snowman
2015-01-21 20:41:31.541 [INFO ] [org.openhab.model.script.FILE ] - Match for 'Snow'
2015-01-21 20:42:45.844 [INFO ] [org.openhab.model.script.FILE ] - Song: Under The Christmas Tree
2015-01-21 20:42:46.168 [INFO ] [org.openhab.model.script.FILE ] - Match for 'Christmas'




 

In the logging above, you'll see some titles return a matching keyword and others don't. There is also the occasional radio channel name appearing instead of the song title. This is filtered out and skipped.

 

The tree happily reacts to the changes in keywords and changes colors automatically:

DSCN3182.JPGDSCN3180.JPGDSCN3186.JPGDSCN3188.JPG

 

I'll be covering the actual build of the tree in my next and final post! Stay tuned! (here: [Christmas Tree] Internet of Holiday Lights - Finished Build)

Previous posts in this project:

 

 

Introduction

 

With the holiday period over, I finally have some time to focus on my projects again.

For this post, I worked on the star which will go on top of my digital Christmas tree.

 

NeoPixel Star

 

I originally intended to use an LED strip, which I would cut into pieces and place in a star shape, but I then came across the NeoPixel Sticks from Adafruit.

One stick has eight LEDs which are placed very close to each other. They seemed perfect for the job.

 

Based on some measurements, I created a simple 3D printed star to test the positioning of the sticks. You'll notice the different branches are a bit off center. That is to compensate for the fact that the pixels themselves are not centered on the stick either.


After that, I modified the star to be able to clip the sticks on and pass the wires for power and data.

IMG_5588.JPG

With the holder tested and fitting, I soldered the connections between the sticks, resulting in one strip consisting of five sticks.

To test the construction, I loaded the default "strandtest" sketch from the NeoPixel library and configured the proper number of pixels.

DSCN3158.JPG

 

 

You can find the final model I designed on thingiverse: http://www.thingiverse.com/thing:624811

Previous posts in this project:

 

 

Introduction

 

I was approached by jancumps some time ago, as he wanted to give the challenge an extra IoT twist.

 

After some messages going back and forth, the conclusion was that we would symbolise each other's project in our own design and have that component light up when the other design was online.

 

 

Heartbeat

 

Both our designs are making use of MQTT messages on the same broker (iot.eclipse.org).

 

We came up with the idea of having our designs send periodic messages (e.g. every minute) on a specific topic with a specific payload as a heartbeat mechanism.

Once a heartbeat is received, a timer is started and the symbol lit up. When a new heartbeat is received, the timer is reset, ensuring the symbol remains lit up.

However, if the timer expires because no heartbeat is received, the symbol is turned off as we assume the other design is offline.

 

Here's the code used to send my heartbeat (I removed the unrelated bits of code):

 

#include <Adafruit_NeoPixel.h>
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#include <Bridge.h>
#include <YunClient.h>
#include <Wire.h>
#include <Infineon.h>
#include <Console.h>

long isAlive = 0;

YunClient yunClient;
PubSubClient client("iot.eclipse.org", 1883, callback, yunClient);

void setup() {
  Bridge.begin();
  Console.begin();
  Console.println("Connected to console.");
  Wire.begin();

  // connect to MQTT broker and subscribe to topic
  if (client.connect("arduinoYunClient")) {
    client.publish("19e5983adc0f","fvan");
    isAlive = millis();
    delay(50);
  }
}

void loop() {
 client.loop();
  // send heartbeat
  sendHeartbeat();
}

void sendHeartbeat() {
if(millis() - isAlive >= 30000) {
  client.publish("19e5983adc0f","fvan");
  isAlive = millis();
}
}






 

And the code used to process Jan's heartbeat (unrelated bits removed as well):

 

#include <Adafruit_NeoPixel.h>
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#include <Bridge.h>
#include <YunClient.h>
#include <Wire.h>
#include <Infineon.h>
#include <Console.h>

long checkAlive = 0;

Adafruit_NeoPixel widget = Adafruit_NeoPixel(12, 7, NEO_GRB + NEO_KHZ800);
YunClient yunClient;
PubSubClient client("iot.eclipse.org", 1883, callback, yunClient);

void callback(char* topic, byte* payload, unsigned int length) {
  // Check for messages on subscribed topics
  Console.print("Topic: ");
  Console.println(String(topic));

  if(String(topic) == "1cfee8dd0afc") {
    String value = String((char*)payload);

    if(value == "jancumps"){
      checkAlive = millis();

      Console.println("Widget heartbeat received");
    }
  }
}

void setup() {
  Bridge.begin();
  Console.begin();
  Console.println("Connected to console.");
  Wire.begin();

  widget.begin();
  widget.show();

  // connect to MQTT broker and subscribe to topic
  if (client.connect("arduinoYunClient")) {
    client.subscribe("1cfee8dd0afc");
    delay(50);
  }
}

void loop() {
  client.loop();
  // check heartbeat
  receiveHeartbeat();
}

void receiveHeartbeat() {
  if(millis() - checkAlive >= 120000) {
    // turn widget off
    for(uint16_t i=0; i<widget.numPixels(); i++) {
      widget.setPixelColor(i, widget.Color(0, 0, 0));
    }
    widget.show();
  } else {
    //turn widget on
    for(uint16_t i=0; i<widget.numPixels(); i++) {
      if(i%3 == 0) {
        widget.setPixelColor(i, widget.Color(255, 0, 0));
      } else {
        widget.setPixelColor(i, widget.Color(0, 255, 0));
      }
    }
    widget.show();
  }
}










 

 

Symbol

 

Jan's design is a Christmas wreath. To symbolise that in my own design, I chose a NeoPixel ring lighting up in green and red.

photo 1 (1).JPGphoto 2 (1).JPG

 

Testing

 

To test this new feature, I used MQTT Lens and the Console output of the Yun.

 

MQTT Lens allowed me to confirm both Jan's and my heartbeats were "on air", with the expected payload. The console output on the Yun then confirmed I received and processed Jan's heartbeat as expected.

Screen Shot 2015-01-02 at 14.25.28.pngScreen Shot 2015-01-02 at 13.24.48.png

 

Demonstration

 

Here's a video of my widget being activated by Jan's MQTT heartbeat.

 

I shortened the timeout interval for demo purposes to 30 seconds, so the widget would turn off between heartbeats which are sent every minute. The timeout is otherwise configured to 120 seconds.

 

Filter Blog

By date: By tag: