Goal of Python Code:
- To scan twitter for various hashtags, send a signal to an Arduino which then signals an assigned audio input once someone tweets with a hashtag
The twitter API utilizes JSON but we chose to write our code in Python, so we needed a “translator” so we could interface with Twitter easily. Tweepy allows this translation, so all you need to do is download, authenticate and import the library.
Problems and Solutions:
- One of the earliest problems we ran into was integrating Tweepy into our code because we needed to renew our authentication and we were using an outdated instruction manual for our version of Tweepy.
The basic_auth.py on the Tweepy github page was different than the one that downloads with the library, so it tooks us a while to realize this and then update our methods.
- Simplifying the code so that it reads all of twitter and only recognizes hashtags, rather than “printing” all of the data associated with each tweet.
When we were first experimenting, our code basically threw up all of the data associated with each hashtag: the user info, tweet itself, and time stamp. If this was something we would distribute to the public, this might be something that needs to be changed, but we decided it wasn’t exactly a “problem”, but more of a design suggestion for the future.
Python Twitter Script Throw Up
- Finding a solution to enable the code to scan for multiple hashtags at once and then send signals to a specific serial port on the Arduino, rather than any hashtag triggering any serial port.
- Example: #yolo needs to trigger serial port 2, while #lybia needs to trigger serial port 4, etc
In order to run several processes at once, Belinda’s original idea was to incorporate “subprocesses”. There were a few options for subprocess libraries that allowed us to “spawn new processes, connect to their input/output/error pipes, and obtain their return codes. Even though this would have been a solution, Andy informed us that creating a list, or array, would be a more elegant solution.
This was our final solution for our python script:
Python Script for ECHO
We finalized our plan and finished our proposal document. Originally started with VH Mutant Subtitles as our name, but after a brainstorming session we changed it to something more reminiscent of our project purpose– E.C.H.O (Emerging Chatter Heuristic Operator). “Emerging” refers to the immediacy of the twitter posts; “Chatter” refers to the unending stream of droning information that spews from the social media outlets; “Heuristics” describes the project’s goal, to translate the unnoticeable droning on the internet into audible sound; and “Operator” refers to the arudino itself, it is the instigator of our little social experiment.
Will and Robert talked shop about the conceptual side of the production and are looking for transistors. The sound system will have 6 channels comprised from 3 cassette players with Left/Right outputs. Aside from the wires, we tried to figure out what the thing will look on the outside – but that’s still pretty vague.
Alex started writing a formal justification for our project by connecting our intentions with past readings and documenting our progress in a more comprehensive manner.
Belinda worked on the code, and tried to get the script to capture hastags instead of a home twitter timeline that we used in our original project. As always, the internet is a wonderful place and we found an already written program to help us with this side of the project. It’s called Tweepy and it’s a Twitter API library that may be invaluable to us in the coming weeks, at least that’s what we hope.
You can find it here: https://github.com/tweepy/tweepy
It supports Python 2.5 and up but not Python 3.
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
We need to know how much current has to pump through the transistors to power our speakers. This might be one of our earliest snags in the design. There were a lot of sites that detailed HOW to use the transistors in this way, but not really WHERE to get them or the specific models. After a bit more searching, we learned we need to use a FET (field effect transistor) and change our code to accommodate this. The way we did it before (on a BJT), the channel closes when you add a current, but a FET closes when you take current away. We need to switch it so the script turns it ON instead of OFF.
In our last project, the code was one of the hardest parts but now it seems this project will have a much heavier on hands component that may prove challenging.
Our group’s first ventures into the world of hacking with arduinos was concerned primarily with the concept of disruption. Utilizing twitter, we incorporated an interactive element that allowed participants to trigger a motor, which in turn would spin wheels on a motorized car that was mounted on an autoharp. In theory, this setup would create a live noise experience with completely different sound results at every trigger.
Ideally, the audience would use certain hashtags that would immediately trigger this loud cacophonious noise. As this was a big learning experience for all of us, the final product was triggered by the signal of any tweet on our project’s own twitter account’s timeline: @arduinochopped. The account followed all group participants, so any tweet each of us made that showed up on the @arduinochopped home timeline triggered the motor to turn on for 1 second. The mounting on the car was also another hurdle, as the car tended to “roll off” the autoharp. We had to attach a shield to keep it in tact.
Unfortunately, the car itself ended up making more noise than the wheels spinning on the strings. A plucking motion would have been more ideal. This code was written in python by Belinda, Laura and Robert with the help of Andrew Famiglietti and lots of googling. It uses relatively simple concepts, but it was the first time our group had ever worked with Python or an API. Essentially, the code checks the @arduinochopped home timeline for new tweets every 15 seconds. If there has been any action, the code sends a message to the arduino to turn “on” for 1 second.
- Python Code for Arduino Harped
The arduino was connected to the car by hooking up with the integrated circuit chip on the motherboard of the motorized car. This was essentially the arduino code that spoke to the car: