Hey guys i'm pretty new to arduino but have been working endlessly on this tutorial: http://www.instructables.com/id/Twitter-Mention-Mood-Light/step4/Python/
So i am not ready to give up.
I think I may have installed all of the packages for python successfuly but I am not too sure (is there anyway to text)
I've worked my way out of most of the problems im facing in creating this.
These is the final problems I am experiencing them and i'm all out of ideas now.
Please help ![]()
This is my error codes (processing):
Stable Library
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
[0] "COM5"
[1] "COM7"
[2] "COM8"
gnu.io.PortInUseException: Unknown Application
at gnu.io.CommPortIdentifier.open(CommPortIdentifier.java:354)
at processing.serial.Serial.(Unknown Source)
at processing.serial.Serial.(Unknown Source)
at simpleTweet_00_p.setup(simpleTweet_00_p.java:91)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
Exception in thread "Animation Thread" java.lang.RuntimeException: Error inside Serial.()
at processing.serial.Serial.errorMessage(Unknown Source)
at processing.serial.Serial.(Unknown Source)
at processing.serial.Serial.(Unknown Source)
at simpleTweet_00_p.setup(simpleTweet_00_p.java:91)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
This is my current processing code:
import processing.serial.*;
import twitter4j.conf.;
import twitter4j.internal.async.;
import twitter4j.internal.org.json.;
import twitter4j.internal.logging.;
import twitter4j.http.;
import twitter4j.api.;
import twitter4j.util.;
import twitter4j.internal.http.;
import twitter4j.*;
static String OAuthConsumerKey = "ykaw70kvBc6jVV21eLlWA";
static String OAuthConsumerSecret = "PllQqnwaZV7aYuH33vniloGW2U5fbkfYxef2LQVAK0";
static String AccessToken = "20026567-9juOyYchv9k7PXsu7kyrvhpHKkOY3Fg6xTn9vatuA";
static String AccessTokenSecret = "AcIhlVX95nvpFYMyk9oh41PWHe3TXYqhMbSy6hLgQ";
Serial arduino;
Twitter twitter = new TwitterFactory().getInstance();
void setup() {
size(125, 125);
frameRate(10);
background(0);
println(Serial.list());
String arduinoPort = Serial.list()[0];
arduino = new Serial(this, arduinoPort, 9600); ERROR BEGINS ON THIS LINE
loginTwitter();
}
void loginTwitter() {
twitter.setOAuthConsumer(OAuthConsumerKey, OAuthConsumerSecret);
AccessToken accessToken = loadAccessToken();
twitter.setOAuthAccessToken(accessToken);
}
private static AccessToken loadAccessToken() {
return new AccessToken(AccessToken, AccessTokenSecret);
}
void draw() {
background(0);
text("simpleTweet_00", 18, 45);
text("@msg_box", 30, 70);
listenToArduino();
}
void listenToArduino() {
String msgOut = "";
int arduinoMsg = 0;
if (arduino.available() >= 1) {
arduinoMsg = arduino.read();
if (arduinoMsg == 1) {
msgOut = "Opened door at "+hour()+":"+minute()+":"+second();
}
if (arduinoMsg == 2) {
msgOut = "Closed door at "+hour()+":"+minute()+":"+second();
}
compareMsg(msgOut); // this step is optional
// postMsg(msgOut);
}
}
void postMsg(String s) {
try {
Status status = twitter.updateStatus(s);
println("new tweet --:{ " + status.getText() + " }:--");
}
catch(TwitterException e) {
println("Status Error: " + e + "; statusCode: " + e.getStatusCode());
}
}
void compareMsg(String s) {
// compare new msg against latest tweet to avoid reTweets
java.util.List statuses = null;
String prevMsg = "";
String newMsg = s;
try {
statuses = twitter.getUserTimeline();
}
catch(TwitterException e) {
println("Timeline Error: " + e + "; statusCode: " + e.getStatusCode());
}
Status status = (Status)statuses.get(0);
prevMsg = status.getText();
String[] p = splitTokens(prevMsg);
String[] n = splitTokens(newMsg);
//println("("+p[0]+") -> "+n[0]); // debug
if (p[0].equals(n[0]) == false) {
postMsg(newMsg);
}
//println(s); // debug
}
And these are the errors on python:
running... simpleTweet_01_python
arduino msg: #peacefulGlow
Traceback (most recent call last):
File "C:/Users/Ciaran/Desktop/python final", line 47, in
listenToArduino()
File "C:/Users/Ciaran/Desktop/python final", line 24, in listenToArduino
compareMsg(msg.strip())
File "C:/Users/Ciaran/Desktop/python final", line 31, in compareMsg
pM = ""+prevMsg[0]+""
IndexError: list index out of range
This is my current python code:
print 'running... simpleTweet_01_python'
import libraries
import twitter
import serial
import time
connect to arduino via serial port
arduino = serial.Serial('COM5', 9600, timeout=1)
establish OAuth id with twitter
api = twitter.Api(consumer_key='ykaw70kvBc6jVV21eLlWA',
consumer_secret='PllQqnwaZV7aYuH33vniloGW2U5fbkfYxef2LQVAK0',
access_token_key='20026567-9juOyYchv9k7PXsu7kyrvhpHKkOY3Fg6xTn9vatuA',
access_token_secret='AcIhlVX95nvpFYMyk9oh41PWHe3TXYqhMbSy6hLgQ')
listen to arduino
def listenToArduino():
msg=arduino.readline()
if msg > '':
print 'arduino msg: '+msg.strip()
compareMsg(msg.strip())
avoid duplicate posts
def compareMsg(newMsg):
compare the first word from new and old
status = api.GetUserTimeline('yourUsername')
prevMsg = [s.text for s in status]
pM = ""+prevMsg[0]+""
pM = pM.split()
nM = newMsg.split()
print "prevMsg: "+pM[0]
print "newMsg: "+nM[0]
if pM[0] != nM[0]:
print "bam"
postMsg(newMsg)
post new message to twitter
def postMsg(newMsg):
localtime = time.asctime(time.localtime(time.time()))
tweet = api.PostUpdate(hello)
print "tweeted: "+tweet.text
while 1:
listenToArduino()
I know atleast one of the buttons are working as it sends the signal of arduino msg: #peacefulGlow
to pyhon when running module but as soon as the button is pressed then error messages appear.
My LED is not lighting up at all ![]()
I can send pictures of the circuitboard if needed.
Please will someone help me with this.
Either contact me here or and email to broadleyutb@googlemail.com would be great
Thanks