WindowPlAy

Downtown Los Angeles has a monthly Artwalk on the second Thursday of  each month.  There are a host of galleries, street performers, musical acts that fill the street with art enthusiasts from all over the LA and OC area.

Windows on the high rise housing units are typically HUGE and are the perfect canvases for light installations.  I had always wanted to do some type of autonomous light show from my window.  During the July Artwalk, I was knee deep in development of the SOTU system  and it just so happened to be at a level of maturity that it was ready for some real exercise.  I’m all about knocking two things out with one punch.

The idea I was simple.

  • + Put a giant “#DTLA” in my living room window.
  • + Wire the inside of the window with 60 LEDs
  • + Attach the  SOTU system to the LEDs
  • + Monitor Twitter for tweets containing #DTLA
  • + For every tweet that included #DTLA flash the LEDs a given color, then fade them out, creating a quick flash fade effect

The overall effect was to make a visible canvas from the street below with a lit up #DTLA every time a tweet was published with #DTLA.  I threw a couple of other secret triggers like #red, #blue, #green, and #flash (randomly flash between red, green, and blue 10 times)  which would light the window up those colors or run the flash sequence instead of the default white.

#DTLA

I made this way too complicated at first.  I tried to use the thin plastic that is used to wrap bouquets of flowers, then roughen it up with sand paper so that the light from the LEDs would reflect off of the scratches enough to make the letters visible.  Yeah, it would’ve worked but even the finest grain sandpaper rubbed holes through it easily.  I ended up covering the letters in black construction paper and put enough LEDs in the background so the LED light would be blacked out by the #DTLA characters.  In the following picture the LED strips are connected to the inside of the window sill and you’ll notice the connection wires for the LED strips hanging down to be attached to the Raspberry Pi.

DTLA

SOTU System

I used the SOTU OSC Server Python script I wrote (based on pyOSC) along with the SOTU Raspberry Pi to control the LED activation over my local network.  The OSC/LED interface was activated on the Raspberry Pi and set to listen for OSC messages from the script I wrote to poll twitter.  It would sit patiently, waiting for something to tell it what lights to light up.  Enter twitterPoll.py

 

Polling Twitter

Just about every time I’ve needed some type of Python library, boom.  There it is.  Maybe not the perfect incarnation, but close enough that it wouldn’t take too much editing to get to work the way you need.  Open source amor!!!

Tweepy is a library that allows you to do all sorts of useful stuff with data from Twitter.  The only function of this library I needed was the ability to poll Twitter for any tweet that had #DTLA (or any # I wanted to listen for) in it and be able to do something when that message was received.

Installing Tweepy is simple if you have setuptools installed (if not, don’t worry, it is equally as simple to get it from the Git repository):

(from https://github.com/tweepy/tweepy/blob/master/INSTALL)

easy_install tweepy.  done.

In order to use Tweepy you will need to register your application on the Twitter application management site here: https://apps.twitter.com/, another straightforward well-defined process.

 

Code City

The software components of the system included

OSCServer.py – an OSC server script that ran on Raspbian Wheezy on a Raspberry Pi.  This would listen for OSC messages and convert them to lower-level pi-blaster commands which would ultimately trigger the RGB LED strips.

tPoll.py – This is a modified version of one of the sample scripts in the Tweepy library.   I modified it to monitor Twitter for the # specified on the command line when running the script: tPoll.py <hashtag>.  This script ran in an Ubuntu VM on my laptop

#!/usr/bin/python

#s is a simple example of the Tweepy streaming functionality. It will listen to
#all tweets containing a hashtag and will keep track of the hashtags used in the tweets.

from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import json
import sys
import OSC
import time

tweetDict = dict() 
parsedTweets = 0

#OSC Server IP and Port
oscConnect  = ('x.x.x.x',<port>)

#Create an OSC Client
c = OSC.OSCClient()
c.connect (oscConnect)
onMsg = OSC.OSCMessage()
onMsg.setAddress("/led/tweet")
onMsg.append(1)

#hashtag to monitor on Twitter from command line arg
searchWord = sys.argv[1]

consumer_key=<your_key>
consumer_secret=<your_key>

access_token=<your_token>
access_token_secret=<your_token>

#Handeling tweets, updating dict, and writing a log
def parseTweet(tweet):
	global tweetDict
	global parsedTweets
	#Look for all tags and update our tweetDict
	for tag in tweet.hashtags:
		t = tag["text"]
		print t 

		if(tweetDict.has_key(t)):
			tweetDict[t] += 1
		else:
			tweetDict[t] = 1
	
	print "====================="
	print tweet.screenName
	#Every 10th tweet we will output the most popular tag and log
	'''
	if(parsedTweets > 10):
		parsedTweets = 0
		maxi = 0
		maxTag = str()
		count = 0
		for tag in tweetDict:
			num = tweetDict[tag]
			count += num
			if(num > maxi and tag.lower() != "android"):
				maxi = num
				maxTag = tag
		output = "Most Popular: " + maxTag + " with " + str(maxi) + ". Dict Entries: " + str(len(tweetDict)) + ". Tags parsed: " + str(count)
		f = open("log.txt","a")
		f.write(output + "n")
		print output 
	'''		

#Tweet class with all the information we need for this program (Hashtags and the actual tweet text)
class Tweet:
        text = str()
	hashtags = []

        def __init__(self, json):
		self.text = json["text"] 
		self.hashtags = json["entities"]["hashtags"]
		self.screenName = json["user"]["screen_name"]

#Basic listener which parses the json, creates a tweet, and sends it to parseTweet
class TweetListener(StreamListener):
	def on_data(self, data):
		jsonData = json.loads(data)
		tweet = Tweet(jsonData)
		parseTweet(tweet)
		#send OSC commands to OSCServer on Raspberry Pi
		c.send(onMsg)
		return True

	def on_error(self, status):
		print status


if __name__ == '__main__':
	parsedTweets = 0
	listener = TweetListener()
	auth = OAuthHandler(consumer_key, consumer_secret)
	auth.set_access_token(access_token, access_token_secret)

	stream = Stream(auth, listener)	
	stream.filter(track=[searchWord]) #This will start the stream and make callbacks to the listener for all tweets containing

The software portion of the system worked well. When I would tweet with #DTLA and #red|#green|#blue|#flash, my window would light up like a champ in near real-time. Unfortunately I don’t have any pics or video of it in action, but the one change I would make is to add more lights to make it much brighter and more visible from the sidewalk below. Nonetheless, a fun project converting live tweets to live lights!

On to the next…