This is a project to hook up an Arduino borad to Twitter using Python. It takes data information from an Aruino in the classroom and tweet to the Twitter account @SheridanS421.
The project is based on pySerial, Python Arduino Prototyping API v2 and Tweepy.
- Go to Twitter Apps to create an app and generate your API tokens if you haven't already
- Hook up the Arduino board with the sensors and output devices. This is a example hooking up with a button, a 16 * 2 LCD and a ADXL345 accelerometer:
- Clone this repository or Download ZIP
- Paste your Twitter API tokens to
tweet.py
- Use the Arduino IDE to open the
ArduinoAPI.ino
under the directory ArduinoAPI - Start from a new
.py
file under the same directory, and here is a basic template:
from arduino import *
from tweet import *
arduino = Arduino('COM6') // Use the Arduino port
arduino.output([])
Here is a basic example that tweets when someone presses the button:
from tweet import *
from arduino import *
arduino = Arduino('COM6')
arduino.output([])
buttonPin = 8
print "INITIATE"
today = 0
total = 0
while True:
button = arduino.getState(buttonPin)
time.sleep(0.1)
if button:
today += 1
total += 1
tmp = arduino.getTemp()
arduino.LCD(today, total, int(round(tmp)))
name = str(raw_input("Who pressed me?! "))
print tweet(name + " pressed the big red button!")
time.sleep(1)
It gets the name from user input in the Python console when somebody presses the button and send a tweet with the name.