This project began as a remodeling job to repaint and re-floor a water closet, but ended as a entertaining display of home automation, adventurous user interfaces, and artificial intelligence--all using Python. Although the project is two years old, development has been accelerated since we switched to Python three months ago.
An inexpensive IBM 486 computer called toilet has been "installed" in the water closet alongside the real toilet. Toilet runs Slackware Linux and contains a sound card with joystick port, an ethernet card, standard parallel and serial ports, and a CD-ROM drive. The case is on the floor with a special cover (this is an especially adverse environment), and a mini keyboard is mounted on the wall.
Most data is acquired through the joystick port of the sound card, which gives 4 analog values (the axes) and 4 digital on/off values (the buttons). A few input bits of the parallel port are also used to read digital on/off values. See figure 1 for a complete list of inputs and outputs.
We chose Python for its incredible prototyping speed and ease of extensibility. For example, the interfaces to the parallel port, joystick port, and CD-ROM are custom C modules. Older versions of the toilet software spawned separate programs from a script and parsed their output. Under Python's module system, our scripts are shorter, clearer, and faster.
Toilet also makes use of various modules written by others. In order to get news headlines from the web, it has httplib fetch selected web pages and the re module parse the headlines out of them. Once it has these headlines, it scrolls them across the LCD screen using the termios module. The sound output system uses the linuxaudiodev and wave modules to play sounds. Also, toilet uses a DB-API module to store history into a database, socket to listen for requests from other processes, and the thread module to allow input polling to continue while other sequences of events are executed.
When a motion sensor detects a visitor in the hallway outside, toilet picks from a list of sounds to play to encourage a visitor to enter. If toilet has a visitor, it plays appropriate sounds based on state from the seat positions, the laser beam across the seat being broken, the light switch being off, etc. It scrolls news headlines across the LCD panel. When the toilet is flushed, the lights flash and the music fades. If the seat is left up when the door is opened, a reminder sound plays. Toilet also serves web pages to the outside that allow us to view history from the database, request specific CD tracks, control the volume, and send messages to the LCD screen.