Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LCD Real Time for Twitter #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@

-------------

Consuming Twitter's Streaming API, this little python program will print the RT / Favorites / User mentions for the authenticating user in real time. Connecting Arduino along with a peizo-buzzer as shown below in the schematic diagram, will notify the user in real time with beeps.
Consuming Twitter's Streaming API, this little python program will print the RT / Favorites / User mentions for the authenticating user in real time. Connecting Arduino along with a Liquid Crystal Display (LCD) as shown below in the schematic diagram, will notify and show the tweet to the user in real time.

<img src="buzzer.png" alt="Arduino Sketch Schema" style="width: 500px; height: 400px"/>
<img src="lcd.png" alt="Arduino Sketch Schema" style="width: 500px; height: 400px"/>

### Setup

* Install the required python libraries from requirement.txt file

sudo pip install -r requirements.txt

* Connect your Arduino board over USB and find the name of the port it is connected to (Usually this is **`/dev/ttyUSB0`** if there is only one device connected over USB).
* Open and Arduino IDE; Verify & Upload the sketch **`arduino/buzzer_notification.ino`** to the board.
* Connect your Arduino board over USB and find the name of the port it is connected to (Usually this is **`/dev/ttyUSB0`** if there is only one device connected over USB, For Windows: COMx, where 'x' is the number of the port. ).
* Open and Arduino IDE; Verify & Upload the sketch **`arduino/lcd_notification.ino`** to the board.
* Go to http://apps.twitter.com, login and create an app by filling the form.
* Copy the `access token`, `access secret token`, `consumer key` and `consumer secret` and use those values in the file **`python/twitter_livestreaming.py`**
* Copy the `access token`, `access secret token`, `consumer key` and `consumer secret` and use those values in the file **`python/twitter_livestreaming_lcd.py`**


## Running the program

python python/twitter_livestreaming.py /dev/ttyUSB0
python python/twitter_livestreaming_lcd.py /dev/ttyUSB0

*For Windows: python python/twitter_livestreaming_lcd.py COMx, where 'x' is the number of the port.

You will hear beeps on the board and tweets on the screen if there are any **RT / Favorites / User mentions** on one of your tweets in real time.
You will see the tweet on the LCD if there are any **RT / Favorites / User mentions** on one of your tweets in real time.
35 changes: 0 additions & 35 deletions arduino/buzzer_notification.ino

This file was deleted.

55 changes: 55 additions & 0 deletions arduino/lcd_notification.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Author: Prasanna Venkadesh
Modified by: Jorge Rios (@j29rios)
License: Free Software (GPL V3)

Listens for data over serial connection and
show a tweet on Liquid Crystal Display (LCD)
*/

//Include LCD library
#include <LiquidCrystal.h>

//Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#ifndef SERIAL_RATE
#define SERIAL_RATE 115200
#endif

#ifndef SERIAL_TIMEOUT
#define SERIAL_TIMEOUT 5
#endif

String out = "";
char in;

void setup() {
Serial.begin(SERIAL_RATE);
Serial.setTimeout(SERIAL_TIMEOUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
}


void loop() {
out = "";
while (Serial.available() > 0) {
lcd.clear();
in = Serial.read();
out.concat(in);
}
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
if (out != "") {
/* lcd.setCursor(0, 1); /*0,1 : second line*/
//Print a message to first line of LCD
lcd.print(out);
}
for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
// scroll one position left:
lcd.scrollDisplayLeft();
// wait a bit:
delay(400);
}
}
Binary file removed buzzer.png
Binary file not shown.
Binary file added lcd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 19 additions & 14 deletions python/twitter_livestream.py → python/twitter_livestream_lcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

"""
Author: Prasanna Venkadesh
Modified by: Jorge Rios (@J29Rios)
License: Free Software (GPL V3)

Running this program will listen for the tweets on User's timeline using Twitters Streaming API.
If there are any retweets or favorites on the tweet of the user,
a buzzer beep will be played on the Arduino connected with the
If there are any retweets or favorites on the tweet of the user,
a 16x2 Liquid Crystal Display (LCD) will be show the tweet on the Arduino connected with the
computer.
"""


# import required modules
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
Expand All @@ -26,7 +26,9 @@
try:
serial_port = sys.argv[1]
baud_rate = 115200

arduino_serial_connection = serial.Serial(serial_port, baud_rate)

print "Connection establised on %s" % serial_port
arduino_serial_connection.write('99')
except IndexError:
Expand All @@ -47,11 +49,11 @@

class StdOutListener(StreamListener):

def play_sound(self):
# plays a beep on Arduino to notify the user
arduino_serial_connection.write('1')
sleep(4)
arduino_serial_connection.write('99')
#Data to Arduino
def play_sound(self, text):
# shows the tweet on LCD
arduino_serial_connection.write(text)
sleep(2)

def on_data(self, data):

Expand All @@ -62,16 +64,18 @@ def on_data(self, data):
for user in json_data.get('entities').get('user_mentions'):
if user.get('screen_name') == screen_name:
print "You have a RT / MENTION"
print json_data.get('text')
self.play_sound()
print json_data.get('text') #Unicode
# Unicode to String
u = json_data.get('text')
s = u.encode('utf8')
self.play_sound(s)
elif json_data.get('event'):
if json_data.get('target').get('screen_name') == screen_name:
print "%s (%s) has %sd," % (json_data.get('source').get('name'),
json_data.get('source').get('screen_name'),
json_data.get('event'))
print json_data.get('target_object').get('text')
self.play_sound()

self.play_sound(json_data.get('target_object').get('text'))
except BaseException, be:
print be.message

Expand All @@ -84,8 +88,9 @@ def on_error(self, status):
if __name__ == '__main__':

listener = StdOutListener()

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, listener)

stream.userstream()
stream = Stream(auth, listener)
stream.userstream()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pyserial==2.7
tweepy==2.3.0
tweepy==2.3.0