Introduction: The Twittering Office Chair
The Twittering office chair "tweets" (posts a Twitter update) upon the detection of natural gas such as that produced by human flatulence. This is part of my commitment to accurately document and share my life as it happens.
For more in depth theory, please see the next step entitled Theory.
See the results of the toots of your on labor on Twitter.
Step 1: Theory
According to my coworker, Twitter is supposed to happen in that space between Flickr posts and Facebook updates, in the space when life actually happens. Well, in the space of time "when life actually happens," life actually happens. It is neither pretty nor ugly. It is just life. If Twitter is supposed to be a document of life as it happens, then it should really document life, indiscriminately, as it happens without interference. If it fails to do this, then life then becomes the space between "tweets" (Twitter posts).
Therefore, it is of the utmost importance, to be able to update Twitter with life events without actually interfering with the event themselves. The documentation of life, henceforth, needs to be automated.
That said, I decided the first part of life that needed to be documented was my daily flatulence at work. I am not going to lie, I am a gassy individual. Since my flatulence is a part of life, it would be fraudulent of me to document life as it happens without documenting these occurrences.
In keeping with the process of non-interference in daily activity, I have created an office chair to both detect and Twitter my flatulence without having to bother me to update it myself.
Step 2: Go Get Stuff
You will need:
- Office chair
- Squidbee TX/RX pair
- 1/8" piece of acrylic
- 50K trimpot
- Natural gas sensor
- Solid hookup wire
- Soldering setup
- Laser cutter (or saw and drill)
- Razor blade
- Screwdriver set
- Nuts and bolts (or screws)
- A staple gun
- A Twitter account
Step 3: Make a Sensor Mount
Make a sensor mount by downloading the attached Corel file and laser cutting your 1/8 piece of acrylic using your awesome Epilog laser cutter.
Did I mention how awesome Epilog laser cutters are?
Anyhow... If, unlike us at Instructables, you do not have a laser cutter, you can download the file and print it to paper. Cut out the circular outline from the sheet of paper and tape this to your acrylic as a guide. Where necessary, drill holes through the acrylic using a power drill and cut around the outline with a jigsaw (or similar).
Step 4: Attach the Sensor
Attach the sensor to the mounting bracket by follow the wiring in the schematic pictured. If you don't have a trimpot, you can insert a resistor value between 22K and 47K (a trimpot is recommended).
When the components are inserted, solder them in place. You may want to first cut off any extra leads that may confuse you.
See the datasheet here.
Step 5: Plug It In
Open your Squidbee (assuming you didn't make one yourself) and detach all of the useless sensors. Plug in your natural gas detecting sensor such that the power goes to the power socket and the data line goes to pin 2 (as shown).
Step 6: Program the Squidbee
Now is the time to program your Squidbee with the code to read the analog sensor.
First things first, unplug the Xbee shield from the Arduino (the part of the Squidbee the sensor is plugged into). Also, change the power jumper from battery to USB power.
Next, plug the Arduino into your USB port.
Open the Arduino programmer.
Set the Serial port (usually looks like /dev/tty.usbserial-A70048pF). Write down the serial port address for future reference.
Download, open and hit the "play" button to compile the code (download below). Upload the code to your Arduino.
Unplug the Arduino from your computer. Switch the jumper back to battery power and put the Xbee shield back on.
Step 7: Connect to the Computer
When you are ready to start taking sensor readings, plug your 9V battery into the Squidbee transmitter and connect the receiver to the computer.
You can see the incoming stream of data by watching the serial monitor in the Arduino interface on your computer.
Step 8: Python
Before you can go any farther, you need Python.
If you are using a Mac with a recent version of OS X, you should have Python already.
Open the Terminal, type into the command prompt "python" and hit "enter."
This should open up Python.
To see Python do its thing type:
print 'hello world' (and hit Enter)
This will return "Hello World" in the prompt.
To quit Python hit "control-D".
If you don't have Python, you can go download it here and install it by following the instructions listed.
Step 9: Dependencies
There are a number of hoops you have to jump through before you can run the Python code in the next step.
The first thing you need is the setuptools shell script. Open terminal and change your working directory to the directory setuptools is in. You can change directories by typing "cd nameofdirectory" and hitting "enter". and you can look at what directories are in your current location by typing in "ls" and hitting "enter".
Once you are in the correct directory, install the shell script by typing chmod setuptools.egg (or whatever the exact name of the file is. Do not rename the file). This may require entering your administrator password. Do so when prompted and hit "enter".
You should now be able to use Easy Install, which, happens to be one of the greatest pieces of code ever written. Once you have Easy Install you just need to type into the command prompt "easy_install" followed by the name of the package you are trying to download and hit "enter." For example, "easy_install greatcode" (not a real example). Next thing you know, you have downloaded and installed the whole "greatcode" package for use in your own code.
Open your prompt and type each line below and hit enter. This will install the Simple Json, Twitter, Time and advanced Math (numpy) packages.
Download and install Python Twitter by following the directions on the page (you might even just try "easy_install twitter").
Step 10: Code
That said, some helpful things I learned about Python include:
One of Python's greatest features (or possibly the worst?) is its lack of syntax. You rarely need to remember a closing or opening tag. You can just keep typing out lines of code and Python will try its best to process it.
Python processes blocks of code based on their indentation. Improper indentation can result in catastrophe. For instance, the only way the code knows that something is part of a for loop is because it is indented the same as everything else that is also part of that loop. This can start to get tricky with nested loops (loops inside of loops) and lead to confusion and bad code.
Python's function system is confusing on a number of levels (for instance some variables are mutable and some not). I don't fully understand the complexities of functions, but if you are interested, you should definitely look it up.
The code we are going to use includes a number of packages, a collection of functions that can be invoked at will (see last step for more information about installing packages).
We are importing the following packages:
- Python Twitter
The code is as follows:
#!/usr/bin/python #Filename: TwitterChair.pyimport twitterimport serialimport numpyimport timeimport random## Your username and password here#api = twitter.Api(username='yourusername', password='yourpassword')## Change this to match your serial port#ser = serial.Serial('/dev/tty.usbserial-A70063pF', 19200)serialArray = global gassygassy = 0def checkokay(): ser.flushInput() time.sleep(3) line=ser.readline() time.sleep(3) if line == ' ': line=ser.readline() print 'here'def startvalues(i): while i <= 50: #time.sleep(.25) line=ser.readline() serialArray.append(int(line)) ser.flushInput() i=i+1 print serialArraycheckokay()startvalues(0)def main(i, i1): ArrayTransfer = numpy.array(i) ComparatorValue = int(numpy.mean(ArrayTransfer)) print ComparatorValue lastReading = ComparatorValue print lastReading loopy = i1 print loopy y = 0 x = 0 while y < 10: while x < 5: line=ser.readline() currentReading = int(line) if currentReading > lastReading: lastReading = currentReading print lastReading print currentReading time.sleep(6) ser.flushInput() x=x+1 print 'half minute' x=0 y=y+1 if lastReading > (ComparatorValue + 50): i1 = 1 if i1 == 1: sayings = ["He farted again with success and vigor. Woest me.", "Pfffffffffft", "Ugh. That was a gross one", "Someone please disassemble me", "If I could puke my foam stuffing, I would", "I wish I were some other chair", "He farted right on me again", "Didn't hear that coming", "allow me to repeat... ppppfffffffffftttttttttttt", "It wasn't always like this."] pickSaying = random.randint(0,9) print pickSaying status = api.PostUpdate(sayings[pickSaying]) loopy = 0 print 'done' if __name__ == "__main__": main(serialArray, loopy)main(serialArray, gassy)
Step 11: Disassemble the Chair
Mark on the seat of the chair the space between your bottom and the bottom of the backer. This is the space in which you want to install the sensor.
Remove the seat from the chair assembly and undo the upholstery until you can access the foam in the area in which you marked.
Step 12: Undo the Upholstery
The fabric on your chair is probably held on with staple.
Remove the staples from the back side of the seat such that you can pull up a little of the fabric.
Step 13: Modify the Cushion
Rip up the foam so that there is a pocket in which the sensor can be inserted into the chair. I found using a razor blade to get the hole started, made it slightly easier.
Step 14: Insert the Sensor
Insert the sensor into the hole you just made in the cushion of the chair's seat. If possible, angle the sensor slightly towards where your rear will be.
Step 15: Reassemble
Put the chair back together. This means reupholstering it with a staple gun and refastening any nuts and bolts.
Step 16: Bottoms Up
Somehow, fasten the transmitter box to the bottom of the chair's seat in a manner that you can still open and close the case.
I chose to attach mine using hot glue. You can also use things like nuts and bolts.
This may require first emptying the case.
Step 17: Turn It On
Plug the battery into the transmitter attached to the chair and close the case.
Plug the receiver into the computer.
Step 18: Run the Code
Run the code by opening the terminal, navigating to the directory the file is located in and typing in python TwitterChair.py
If you didn't download the python file yet from the "code" step, download it from this step!
Step 19: Tweet
Tweet when you toot. Happily let people know that you are engaging in life as it happens.
We have a be nice policy.
Please be positive and constructive.