Step 2: Using Processing to listen to the web for commands (with full code)
The brain that receives data to activate Twitr_janus' head is a programme (sketch) running in Processing. This runs on a computer attached to the head. The computer is connected to the web.
Processing is simple to learn and has a great open community and easy and accessible documentation. The makers of Processing describe it as...
"an open source programming language and environment for people who want to create images, animations, and interactions. Initially developed to serve as a software sketchbook and to teach fundamentals of computer programming within a visual context, Processing also has evolved into a tool for generating finished professional work. Today, there are tens of thousands of students, artists, designers, researchers, and hobbyists who use Processing for learning, prototyping, and production."
Processing is free to download and use. Visit Processing .org
The key Processing features used to make Twitr_janus' brain include:
- a handy method called loadStrings(); which , which can pull in feed data from an external URL (e.g. RSS feed or API call)
- various handy ways to parse the feed strings received to extract the actual control data
- the ability to set up a serial connection with the USB port to send data to the Arduino
-
a third party text-to-speech library GURU TTS which can turn text into audio speech
See http://www.local-guru.net/blog/pages/ttslib
github.com/downloads/rosemarybeetle/Twitr-Janus/twitr_janus_code15.txt
It includes code to:
-
import the Guru text-to-speech library
>>>
import guru.ttslib.*; // NB this also needs to be loaded (available from http://www.local-guru.net/projects/ttslib/ttslib-0.3.zip)
Serial port;
TTS tts;
<<<
-
referencing Twitter API calls
>>>
String twitterApiString = "https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name="+twitterUsername+"&count=0";
<<<
-
referencing Google Spreadsheet RSS calls
>>>
String gssApiString = "https://spreadsheets.google.com/feeds/list/0AgTXh43j7oFVdFZJdklXTU1lTzY5U25sc3BJNjRLRUE/od6/public/basic?alt=rss";
<<<
-
parsing feed data to extract control data (this is the google spreadsheet data being parsed into an array from the RSS feed)
>>>
String [ ] texty = loadStrings(gssApiString);
String [ ] texty2 = split (texty[0], '¬'); // pulling out data with stop character
String [ ] texty3 = split (texty2[4], '<'); // get rid of trailing text after <
gssText = texty3[0];
gssTextLength= gssText.length();
<<<
-
making a serial port connection >>>
println(Serial.list());// display communication ports (use this in test to establish fee ports)
//if (Serial.list()[2] != null){ // error handling for port death on PC
port = new Serial(this, Serial.list()[2], 115200);
//}
<<<
-
sending data to the Arduino via the serial port
>>>
(this code is writing the eyeball position stripped from the Google data to the port. The Arduino will use it to reference an array of preset positions)
port.write(gssEyeballUpDown);// send up down value to board
This code is sending a code number to the Arduino, which if detected will trigger the blue LED...
port.write(30);
<<<
-
Converting the data into speech by calling the TTS library
>>>
The google text data used as speech...
tts.speak(gssText);
The Twitter tweet used as speech...
tts.speak(tweetText);
<<<
Download the full Processing Sketch
It's not perfect, but the complete Processing sketch is available to download here from GitHub as a text file:github.com/downloads/rosemarybeetle/Twitr-Janus/twitr_janus_code15.txt
For easy viewing, here is an image facsimile of the text
NB - I had inititally intended to get an Arduino script to do this, but couldn't find a way to do it. The arduino would need to have a direct Internet connection and to be able to poll the web repeatedly. This may be possible an Ethernet or wireless shield, but I couldn't find an easy way to do this.
Remove these ads by
Signing Up



























Not Nice














Visit Our Store »
Go Pro Today »



