visualizing world happiness using the raspberry pi
DESCRIPTION
This project use a Raspberry PI and Twitter data to visualize world happinessTRANSCRIPT
Red - Stockholm; Green - Boston; Yellow - Melbourne Orange - Cairo; Blue - Tokyo; Grey - 547WX3
Tweet #547WX3 to turn on grey lights
Raspberry PILight Strip
Visualize World HappinessVisualize email notification from VIPs
Dag HolmboeKlurig Analytics
Red - Stockholm; Green - Boston; Yellow - Melbourne Orange - Cairo; Blue - Tokyo; Grey - 547WX3
Tweet #547WX3 to turn on grey lights
What does the Lights do?1. Happy Tweets around the World
a. Check Twitter for Happy Tweets “:) :-) :D :P“b. Boston, Stockholm, Melbourne, Cairo, Tokyoc. This is real time: 15 - 20 seconds between searches. Lights show that
a person was happy in a city was happy very recently. d. Try tweeting using #547WX3
2. Gmaila. Every 80 sec, search gmail account for email from different groups of
people; family, business groups, VIPs, clientsb. Light colors based on importance of people
3. Errors
Red - Stockholm; Green - Boston; Yellow - Melbourne Orange - Cairo; Blue - Tokyo; Grey - 547WX3
Tweet #547WX3 to turn on grey lights
Light Cheat Sheet Top light = 31 Green to mark checking email
25 - 30 Email notifications group by email authors
22 - 24 #547WX3 - Grey
18 - 21 Stockholm - Red (time difference +6 hours)
14 - 17 Boston - Green
10 - 13 Melbourne - Yellow (+14 hours)
6 - 9 Cairo - Orange (+7 hours)
2 - 5 Tokyo - Blue (+13 hours)
Bottom light - 1 Blinking green: sleeping. Blinking other color: error
Bottom light = 0 Search happy tweets in cities (color based)
Happy Tweets :) :-) :D :P
Never again check email, just glance at the lights
Red - Stockholm; Green - Boston; Yellow - Melbourne Orange - Cairo; Blue - Tokyo; Grey - 547WX3
Tweet #547WX3 to turn on grey lights
Hardware
The kit URL is in ‘references’ section of this presentation
Red - Stockholm; Green - Boston; Yellow - Melbourne Orange - Cairo; Blue - Tokyo; Grey - 547WX3
Tweet #547WX3 to turn on grey lights
Software stack
OS: Occidentalis v0.2
Python 2.7.3rc2
email - feedparser
twitter - python-twitter
- GPIO
The Digital LED strip requires very fast data signal, so you need SPI (serial peripheral interface) installed.SPI is not included in the default "Wheezy" distribution and requires a firmware update - Occidentalis is the recommended OS
Red - Stockholm; Green - Boston; Yellow - Melbourne Orange - Cairo; Blue - Tokyo; Grey - 547WX3
Tweet #547WX3 to turn on grey lights
Light Strip - Initialize1. # initialize devices2. dev = "/dev/spidev0.0"3. spidev = file(dev, "wb") # writeable bytes4.5. # Create column: R, G, B byte per light6. column[0] = bytearray(number_of_LEDs * 3 + 1)7.8. # Calculate gamma correction table. This includes9. # LPD8806-specific conversion (7-bit color w/high bit set)
10. # for intensity of color11. gamma = bytearray(256)12. for i in range(256):13. gamma[i] = 0x80 | int(pow(float(i) / 255.0, 2.5) * 127.0 + 0.5)
94 95 96
... ... ...
6 7 8
3 4 5
0 1 2
Light #31
Light n
Light #2
Light #1
Light #0
column(bytearray)
Gre
en
Red
Blu
e
Red - Stockholm; Green - Boston; Yellow - Melbourne Orange - Cairo; Blue - Tokyo; Grey - 547WX3
Tweet #547WX3 to turn on grey lights
Light Strip - Make it Light
1. #Light = {0,1,...,31}2. #Color = {0,1,..., 255}3. #OFF = 0,0,0 ; red = 255,0,0 ; green = 0,255,0...4. def light_switch( light, red, green, blue ):5.6. y3 = light * 37.8. column[0][y3 + 0] = gamma[green]9. column[0][y3 + 1] = gamma[red];
10. column[0][y3 + 2] = gamma[blue]11.12. spidev.write(column[0])13. spidev.flush()
94 95 96
... ... ...
6 7 8
3 4 5
0 1 2
Light #31
Light n
Light #2
Light #1
Light #0
column(bytearray)
Gre
en
Red
Blu
e
Red - Stockholm; Green - Boston; Yellow - Melbourne Orange - Cairo; Blue - Tokyo; Grey - 547WX3
Tweet #547WX3 to turn on grey lights
Code Flow1. Setup variables for
a. cities (lat/long, radius, colors)b. email (username/password)c. other (sleep time)
2. Initialize lights with SPI, run a few light sequences3. Authorize with Twitter (consumer and access_token key/secret)4. while True:
a. Email: download email header and check for important authorsi. If received email from important author, then turn on lights based on author
groupsb. Twitter: per City, run an individual Twitter search for Happy Tweets
i. Store latest tweetID (new_tweetID)c. Twitter: per City, compare new_tweetID with prior search’s old_tweetID
i. If( new_tweetID != old_tweetID) turn ON lights for that Cityii. If( new_tweetID == old_tweetID) turn OFF lights for that City
d. Sleep 14 seconds (due to Twitter’s rate limitation, 14 seconds made sense)
Red - Stockholm; Green - Boston; Yellow - Melbourne Orange - Cairo; Blue - Tokyo; Grey - 547WX3
Tweet #547WX3 to turn on grey lights
Thoughts for the future1. Twitter - color based on quantity, sentiment, users, keywords, geo
a. Trends, stock market, weather, earthquakes, politicsb. Sporting events; follow fan mood during games
2. Emaila. Sentiment analysis of emails - combine with author, date/timeb. Predictive analysis - automated recommendation engine, using topic modeling, classification of
emails to understand which emails seems more valuable to open versus others (gmail is already handling most of the spam)
c. Instead of segregate emails per author, can we use social network analysis and centrality measures to rate users automatically to find the most interesting emails based on author influence and show lights accordingly
3. Not only Twitter and email - any online site with an API or easy screen scrapea. Weather forecastb. News, sports, dating, stock marketc. Meetup.com has a great, really simple to use API - color when new meetups are proposedd. API galore: http://www.programmableweb.com/
Red - Stockholm; Green - Boston; Yellow - Melbourne Orange - Cairo; Blue - Tokyo; Grey - 547WX3
Tweet #547WX3 to turn on grey lights
References1. Light: hardware bill-of-materials, software and installation (Phillip Burgess)
a. https://learn.adafruit.com/light-painting-with-raspberry-pi/overviewb. Cost: about $70 - $100 for complete hardware kit, including breadboard
2. Gmail checker (Mikey Sklar)a. https://learn.adafruit.com/raspberry-pi-e-mail-notifier-using-leds
3. Run program at startupa. http://www.stuffaboutcode.com/2012/06/raspberry-pi-run-program-at-start-up.html
4. API lista. http://www.programmableweb.com/
5. Twitter codea. https://code.google.com/p/python-twitter/b. http://python-twitter.googlecode.com/hg/doc/twitter.htmlc. [email protected]
Red - Stockholm; Green - Boston; Yellow - Melbourne Orange - Cairo; Blue - Tokyo; Grey - 547WX3
Tweet #547WX3 to turn on grey lights
Appendix
Red - Stockholm; Green - Boston; Yellow - Melbourne Orange - Cairo; Blue - Tokyo; Grey - 547WX3
Tweet #547WX3 to turn on grey lights
Klurig Analytics
Red - Stockholm; Green - Boston; Yellow - Melbourne Orange - Cairo; Blue - Tokyo; Grey - 547WX3
Tweet #547WX3 to turn on grey lights
Authorization with Twitter1. def auth_with_twitter():2. consumer_key = "***"3. consumer_secret = "***"4. access_token_key = "***"5. access_token_secret = "***"6.7. api = twitter.Api(consumer_key=consumer_key,8. consumer_secret=consumer_secret,9. access_token_key=access_token_key,
10. access_token_secret=access_token_secret)11.12. #print "---------------------- verify credentials"13. #print api.VerifyCredentials()14.15. return api
Red - Stockholm; Green - Boston; Yellow - Melbourne Orange - Cairo; Blue - Tokyo; Grey - 547WX3
Tweet #547WX3 to turn on grey lights
Software Stack
OS: The Digital LED strip requires very fast data signal and you can't just use the GPIO libraries to do it. You must have hardware SPI installed, this is not included in the default "Wheezy" distribution and requires a firmware update, so please use Occidentalis!
The Serial Peripheral Interface (SPI) is a communication bus that is used to interface one or more slave peripheral integrated circuits (ICs) to a single master SPI device; usually a microcontroller or microprocessor of some sort. Many SPI Peripheral ICs exist. They include, analog to digital converters (ADC), digital to analog converters (DAC), general purpose input/output (GPIO) expansion ICs, temperature sensing ICs, accelerometers and many more.