How I Feed My Cats with Linux

Give your Linux box the power to control real-world events with an inexpensive microcontroller from Parallax, a Python program and some serial port magic.
Let's Feed the Kittens!

I built the cat feeder with a carousel design, where the treats would be put into cells, divided by a rotating paddle, driven by a servo. When the paddles rotate, a load of treats drops through a cutout in one of the cells to a food bowl. I used a container meant for storing frozen waffles for the carousel, with a custom cut rotating paddle and a Parallax servo to drive it all. The whole assembly, including the BASIC Stamp circuit, is housed in a plastic storage box in my home office. The box is connected to my Web server on /dev/ttyS0 for the feeder and /dev/ttyS1 for the debug port. Figure 1 is a picture of the cat feeder on my shelf. I'm using Fedora Core 1, with Apache 2.0.48.

Figure 1. Cotton Getting a Treat from the Feeder

The initial problem was how do I determine that the paddles have rotated enough to drop the treats and stop them from rotating? The easiest solution was to put a small sensor on the side of the carousel that would detect a paddle passing in front of it. I chose a sensor from Parallax used primarily to find a black line on the ground. I put a flat black piece of posterboard on the edge of each paddle and the sensor on the bottom of the carousel right after the edge of the hole. When the feeder feeds, the sensor detects when the first paddle moves past; when the second paddle passes the sensor, the servo stops.

I wired up the Stamp relatively quickly over a few days of experimenting. The attached breadboard is a great feature of the Homework Board. I was able to rewire and test circuits quickly without having to solder and desolder. Figure 2 shows the completed schematic. Figure 3 is a picture of the wired-up Homework Board.

Figure 2. The Feeder Circuit

Figure 3. The Completed Circuit

Writing the code for the BASIC Stamp mostly was a matter of cutting and pasting code examples from the Parallax Web site. Listing 1 is the final code that I used on the Stamp. PBASIC relies heavily on GOTO statements for flow control, which took some getting used to on my part.

Listing 2 shows the complete Python code we use to drive the feeder. The CGI script uses the built-in shelf module for Python; shelf allows you to store live objects in a DBM database. In addition to shelf, I'm also using the Cheetah Template engine. The line t = Template(open('feeder.tmpl.py').read()) opens an HTML template called feeder.tmpl.py, reads the contents and uses it as the Cheetah template. The template format looks something like <p>The cats have been fed $fed times</p>. When we set the template variable, t.fed, to some number (say 5), the line then becomes <p>The cats have been fed 5 times</p>. My wife, a graphic designer by trade, whipped up some graphics for the page.

The cat feeder is open for business. Occasionally, a treat jams up the works, but 95% of the time, the cats get a stinky little fish. We already have plans for cat feeder v.2.0. We'd love to add a Webcam to see the kittens during the day, as well as move the device to a wireless laptop in the kitchen. The feeder is, as with most of our projects, a work in progress. Feel free to go to the Web site and give Cotton and Tulip a treat.

Resources for this article: /article/7741.

Chris McAvoy is a UNIX Administrator in Chicago, Illinois. He lives with his wife, Camri, and their two cats, Cotton and Tulip. Chris and Camri have a lot of hobbies. Their Web site is www.lonelylion.com.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

very cool cat feeder!

Anonymous's picture

Nice! I bet similar projects could likewise be done with an arduino kit as well...

Would work for goldfish, dogs, etc as well...

I am curious about the two bowl issue.. And what about fresh water via remote? :)

Read from serial port

msdark's picture

(First sorry for my english... i speak spanish xD)

Hi!!! nice work... this post help me a lot to figure out some things...

but.. i need help.. if you can..
I'm working with a basic stamp to read a sensor (a potentiometer).. with python i create a GUI (glade) and add some action buttons.. with one button i send a comand through serial port to "activate" the basic stamp.

The basic stamp read the potentiometer and show (through command line using DEBUG) the result values of the operations.. but i want to send this result through serial port to read it with python to show it in the GUI, but i can't read...

I use SEROUT in the basic stamp code to send the result through port but when i test it with a littel python script i have a error: "OSError: [Errno 11] Resource temporarily unavailable" so i can't read the result...

i use this in basic stamp:

SEROUT 16,84,[DEC3 adcBits ,LF]

and the python test code:

import serial
p = serial.Serial("/dev/bstamp")
p.read(10)

But nothing happend... can you give me some idea?

Thanks in advance
Thanks a lot

PD: I'm using Linux obviusly xD

Another project

CJB's picture

Perhaps this comment comes a few years too late, but I want to do a project that is very similar to yours. I have a problem with a fat cat eating out of another cat's food dish. I want to put a sensor on the smaller cat's collar that opens an auto feeding dish when she gets near it. (I could also try to train her to do something that triggers her dish to open). Coincidentally, I purchased the BASIC stamp controller kit you mentioned and am in the process of learning about it. I'm not a computer programmer. I'm going to have to read your report several times to really understand what you did.
Might you have some tips for me? Do you think I could purchase the motor, sensor, and other equipment I'd need to create my special food bowl from Parrallax? I operate a PC with Windows, and could hook up a computer to the bowl, or just the stamp controller. This sounds like a fun learning challenge for me, but I might be in over my head. Any advice you have would be appreciated!

Nice project!

Sqwishy's picture

Wow thats pretty cool. And i'm jealous of you. I'm really new to this whole microprocessor thingy so can you explain stuff to me :D
The main chipy thing is a basic stamp 2 from parallex right?
Did you write python code and somehow run it on the basic stamp chip or convert it to basic code first or what?
Is there an easy way for me to write python code and somehow send commands or something to a basic stamp 2 chip? like do i hafta get a converter prog?
and do i hafta run linux. i have a gentoo/windows dual boot at home but at school (where i need to work on the chipy stuff) all their compy's use windowz

Nice

Anonymous's picture

I respect you and very much wish you peace Lets talk about... I was send mail off

Flushing

Anonymous's picture

This is exactly the kind of thing that I have just started working on. But instead of a cat feeder, it's just a web-interface to flush a toilet. Sounds silly, I know -- and it is!

It might be a guy thing, it might be a hacker thing, but I find being able to flush a toilet remotely to be funny. Especially if someone is using it or in the shower (and you told them that they've been in there for an hour and it is now your turn).

Anyway, I just need to find a servo with enough strength to lift the lid, after that, it's all good. (I've actually already wired the toilet area up, so now all I have to do is get everything working.)

This is exactly the kind of s

OhMyAchingGut's picture

This is exactly the kind of stuff i live reading in LJ. I never in a million years would have thought of this...and its probably a good project to dip my feet into the world of microcontrollers.

I'm going to go put that renewal check in the mail. Keep up the good work guys :)

Great! Now Where's the WebCam?

Anonymous's picture

Fantastic article ... and definitely a cute web site ... but I'm a skeptic ... Where's the webcam to show the action of the cat feeder and to be able to actually SEE the kitty getting the treat?

*sweet*

RaH's picture

My wife loves cats, we also have two, she also has used a computer the last 10 years and is just now beginning to realize you can use it for more than just word processing. I am going to show her this article to prove that theres more than one way to feed a cat. Excellent job on the feeder. This seems like a good project to do with my daughter to introduce her to programming and electronics. Thank you for taking time to write it up and sharing it.

that's cool... you should def

Anonymous's picture

that's cool... you should definitely show your daughter.
I'll be starting CS grad school in a few months, but when I was a kid, the men in the family never bothered to teach any of the girls how to work with computers. And actually, my degree is in math... that article was still only barely legible to me...

Awesome

NSK's picture

That's an awesome article, please write more like this! Very good job.

Biometrics?

Lachek's picture

Very, very cool project...
Now, what I really want to see (and I'm only half serious :) is biometric support - a simple pawprint reader to dispense and ration food differently depending on which cat is requesting to be fed. It would greatly assist me in keeping my one overweight cat on a diet, while ensuring that my other cat gets the nutrition she needs...

rfid?

Kev's picture

if you had a passive sensor, it could be used to determine who is near the feeder. I though of this after seeing a dog door that was operated by a 'key' on the dogs collor.
Kev

Biometrics?! Or just a scale

Anonymous's picture

Biometrics?! Or just a scale or rf collar.

Junkfood

Anonymous's picture

The last thing these cats need is more treats. From the photo it obvious they're quite overweight (just like the majority of cats in the U.S.) just like the majority of people in the U.S.

Talk to your vet and he will (more democratically) tell you the same thing.

I think you mean diplomatical

Jason's picture

I think you mean diplomatically ...

jealous much?

Anonymous's picture

jealous much?

Of?

Anonymous's picture

Of?

Hmm

Dave's picture

You know technically that the USA is a 4th world country, right?

Nice Project!

Sascha M.'s picture

Hi,
really nice project!
Would be nice to see more of such projects.

>^.^< -(miauu)

Your article is going to hit

Anonymous's picture

Your article is going to hit Slashdot. You may want to get rid of the "feed my cat" link....

Too late! Cotton and Tulip

Anonymous's picture

Too late!

Cotton and Tulip thank the Slashdot community at large
<burp>

Names

Big Daddy's picture

Cotton and Tulip? Next cats you get name them something cool, like Tool and Flames.

Statistics?

BrownEyedGirl's picture

Do you have any statistics on how often Tulip and Cotton get fed? What times of day seem to be popular? Do they sometimes get fed when you're at home? Just curious.

Added to Crazy Hacks.

Uwe Hermann's picture

This is a very very cool project, congratulations. I have taken the freedom to add it to my Crazy Hacks wiki, I hope you don't mind. Feel free to correct the entry, in case I have gotten anything wrong.

Uwe.

Other ways to interface computers to external mechanisms

Michael Shiloh's picture

Another way to interface motors and sensors to your computer is the Teleo System by MakingThings

Disclosure: I work for them

Teleo is popular in the electronic music and kinetic sculpture world, but it seems like a natural for programmers who would like to do things like your cat feeder. It's a series of modules that interface to a wide variety of sensors and actuators, and a simple C API.

I don't want this to look like an advertisement so I'll stop here, but I invite anyone interested to visit our website (www.makingthings.com) or to email me directly.

Sincerely,
Michael Shiloh
MakingThings

Ouch... the prices.

tuco's picture

I was interested until I saw an older model mini ITX mobo + 128MB CF + IDE CF reader selling for $859 bucks! If you purchaced those items seperately anywhere else, it would cost, what, $180. Can I assume the rest of product line is appropriately marked up as well?

Another way to feed a cat

Mark's picture

Thanks Chris for putting the effort into writing this article. I have often wondered about extending the reach of my computer into the world I live in.

While looking around on the subject of microcontrollers I found an excellent device for direct serial to servo control.

If you are always going to drive your cat feeder from your PC this is a very simple solution.

I am going to get a board for myself to play with :)

Check out http://www.seetron.com/ssc.htm
At only $44US a pop too!! (postage is a bummer for OS residents)

regards
Mark Doukidis mdoukidis@gmail.com

Good article

kanzure's picture

Good article, thanks. : )
Makes me want to feed my own cat for a change.

Is there any chance for more future linux toy projects of these likes?

Too much???

Anonymous's picture

Cotton and Tulip have been fed 8164 times. I sincerely hope the machine was taken offline, or they will end up with two dead cats smelling like smelly fish treads.

go away

Anonymous's picture

go away

Go away to where

Anonymous's picture

8-)))))

Shouldn't the author use Parallel Port instead

Ting's picture

Isn't an interface with some electronic via Parallel port a much cheaper solution?

http://www.dehne.nl/pp_powerSwitch/

http://parapin.sourceforge.net/

Why wast money on PLC controller? Take the shortest route!!! :-)

Why not just take an embedded

Ueli's picture

Why not just take an embedded webserver instead of using a whole computer only to feed some cats...

Likely because he already had

OhMyAchingGut's picture

Likely because he already had the PC lying there, because an old PC is cheaper than an embedded board, and can be used to do more than just this one job quite easily.

That said, an embedded board would be a sexier solution. Probably some opportunity there for someone with some initiative and $$$ to put together a slick commercial device.

peace

templar's picture

I is quite evident that this individual has never read the Quran nor studied its history and evolution. When people proclaim peace, peace, it is time to watch for war.
templar

What does one thing have to do with another?

Anonymous's picture

It's a cat feeder ... wft does that have to do with 9/11?

Someone slap that dude with a fish!

obvious really.

REdjohn's picture

In a "post 9-11" world there has never been more need for a cool way to remotely feed our cats using our computers, weblinks, pic controllers and human inspiration. If I cant log in and feed my cats from my cell-phone and some radioshack parts, then the terrorists have won!

Seriously though, great project. I feel the need to build a usb cat feeder. With the pic stuff, usb would give you that 5v+ instead of the serial 12v. Nevermind, must buy cat food.

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix