TweeToy by Raspberry Pi Using Python

Introduction: TweeToy by Raspberry Pi Using Python

About: Japanese, in Tokyo. Server Engineer.

I created a Toy which Talks somebody's tweets using Raspberry Pi.
This Toy catches object by distance sensor and then make sound (Tweet).

The architecture is very simple. For getting Tweets, just using twitter api for python. And playing sound with "AquesTalk Pi" (free) which is created by Japanese software company. Unfortunately AquesTalk Pi only supports Japanese words so cant handle English and alphabet. Maybe "eSpeak" works for English, I haven't tested it.

- raspberry pi type B
- usb wifi adapter
- MCP3008(Analog-to-Digital Converter)
- sharp distance sensor (GP2Y0A02YK)
- small speaker
- Redbull

Program source and wiring on breadboard is based on "Analog Inputs for Raspberry Pi Using the MCP3008".
Thanks Mikey Sklar.

Step 1: Enable Sound

$ sudo nano /boot/config.txt

add "hdml_drive = 1" line and save (cntrl + O[enter]).

this enables sound out put to 3.5 mm jack. In case of connecting HDMI, HDMI is set as Sound output device so it's need to chenge.


Gain volume by up key. Default is a bit small.

Step 2: Install Twitter API and Related Modules

install httplib module
$ wget
$ unzip
$ cd httplib2-0.8
$ sudo python install

install simplejson module
$ git clone
$ cd simplejson
$ sudo python install

install oauth2 module
$ git clone
$ cd python-oauth2
$ sudo python install

install twitter module
$ git clone
$ cd python-twitter-master
$ sudo python build
$ sudo python install

Step 3: Assembling a Breadboard

Step 4: Register App on Https://

To use Twitter API, you need to register app on Twitter developers.
After registration, take a note some security codes like Consumer key / Consumer secret / Access token / Access token secret.
sorry I don't write the procedure here. You can find it  in the internet.

Step 5: Test Run Program

$ git clone
$ cd TweeToy
$ sudo nano

modfiy 2  parts bellow. If you want to speak some tweet (not only one), add "for" sentence "after if trim_pot < 600:".
This video of top page is set loop.

# dev account ....(1)
api = twitter.Api(consumer_key='user consumer_key',
consumer_secret='user consumer_secret',
        access_token_key='user access_token_key',
        access_token_secret='user access_token_secret')

# specify the account you want to get tweet from ....(2)
account = '@dave_spector'

$ sudo python

Close something to the senser.  You might get sound of Tweet.

And then schedule "" in crontab( crontab -e) for periodically execution like 5sec or 10sec.

That's ALL!!!

Raspberry Pi Contest

Participated in the
Raspberry Pi Contest

Be the First to Share


    • Puzzles Speed Challenge

      Puzzles Speed Challenge
    • "Can't Touch This" Family Contest

      "Can't Touch This" Family Contest
    • CNC Contest 2020

      CNC Contest 2020