Building a Bear that Tweets (post by Justin Hoenke and James McNutt)

One of the best things about working at the Chattanooga Public Library is the freedom we have to try new things.  Nate Hill once said that he sees The 4th Floor at the Chattanooga Public Library as a beta space where things are tested, kinks are ironed out, and then are sent out into the rest of the library.  I’ve embraced that idea with all of the projects, programs, and things we’re trying out with ages 0-18 on The 2nd Floor of the Downtown Chattanooga Public Library.

Nowhere is that freedom and spirit to give everything a shot more visible than with THE AWESOME BEAR.

Awesome Bear Page

The Awesome Bear started its life as a plastic bear that I found in a closet during one of my first weeks in Chattanooga.  It had no use just sitting in a closet, so I set it out for the public.  Its job was simple: collect bits of paper which people would use to write awesome things on.  It could be a wish, something neat that they saw, or a recommendation.  The Awesome Bear would collect these things and put good vibes out into the world.

After collecting scraps of paper for a few months, it was clear that the Awesome Bear was super fun for those who visited the 2nd Floor but the idea needed to grow.  Along came Meg Backus, doer of great things at the Chattanooga Public Library with this comment:

The AWESOME BEAR    Comment

After a 15 minute chat with Meg, it was clear that only a few things were needed to make the Awesome Bear tweet: a keyboard, an internet connection, a twitter account, and a Raspberry Pi.  Megan Emery and I set up the Twitter account and trascribed the written notes inside the Awesome Bear into its first ever tweets.

James McNutt (Education Director at Engage 3D, 4th Floor Awesome Person) came into the project as we set up the twitter account.  He remarked that it would be super simple to write a few lines of code in Python to collect what people were writing.

For details on how the Awesome Bear got some technology and tweets, I’ll turn it over to James McNutt, Education Director at Engage 3D and all around amazing person.

Materials:
Raspberry Pi B
SD card (4+ GB)
Ethernet cable
Power supply
Keyboard
Monitor (HDMI or RCA video cable)

PREPARING THE SD CARD
For ease, I went with wheezy/raspian. You can get the latest images at http://www.raspberrypi.org/downloads

Once you have the .zip file extract it

My preferred method to write images is the dd comand

When you plug the SD card in, it will be mounted.

This is Mac specific:

In the terminal we are going to look at our mounted disks with: diskUtil list

  • Write down the path of the device we are going to write to (for example /dev/disk2)
  • Now we unmount that device with diskUtil unmountDisk /dev/diskN (where N is the number in your specific case)

Now we are going to write the image to that disk

Caution: we are running this command with root privileges and if you specify the incorrect disk you can end up writing to your primary drive instead

with:

sudo dd if=2013-09-25-wheezy-raspbian.img of=/dev/diskN

(this will prompt you for you username and then password, when typing your password nothing will appear on the screen)

(again where N is the number in your specific case)

 This will take some time

Once it is finished you SD card is ready!

BOOTING FOR THE FIRST TIME!
Insert your SD card, connect your ethernet cable, keyboard, a monitor, and lastly your power supply. Your device should boot upon connecting the power supply

The first time you boot you’ll need to do some configuration, like setting your keyboard defaults to US rather than UK!!!

Likely your pi will reboot and you’ll login with your username and password (“pi” and “raspberry” if you didn’t change anything).

First thing we’ll do is install apache2

sudo apt-get update
sudo apt-get install apache2

After installing the apache server will start and anything in your /var/www directory will be served up.

For our purposes we only concerned with being able to see this on the LAN so we’re good

Let’s get rid of the filler index.html

sudo rm /var/www/index.html

Now since we only want a text file let’s make that

sudo nano /var/www/index.txt

Write whatever inspirational message you like to be the first thing on the record.

  • Type ^x to exit and save

Now we’ll give this file to the user pi or whatever you made your user

sudo chown pi /var/www/index.txt

Now we’ll change the privileges

chmod 644 /var/www/index.txt

WRITING A PYTHON SCRIPT
(Justin here: Here’s the Python script that James wrote to collect the tweets on the Raspberry Pi)

filename = "/var/www/index.html"
while(True):
    submission = raw_input()
    f = open(filename,'a')
    f.write(submission+'\n')
    f.close()

 


In regard to the python script it might be worth instructing to save the file as something.py and running it with python something.py

  •  Type ^x to exit and save
  • Write down your IP address
  • ifconfig
  • Find your address under the eth0
  • Now run the program
  • Type something and hit return
  • On another deviceopen up a web browser and type the IP address in the URL followed by index.txt
  • You should see messages! (please note:  this doesn’t tweet using the twitter-python api but just serves a local file.  Basically it will save everything everyone types into a text file.  It will be your job to copy/paste those into twitter)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s