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.

Cats love toys. Our cats, Cotton and Tulip, slowly have taken over our house with their little plastic doo-dads—ping-pong balls, furry mice, bells, springs and things to scratch. The cats are rarely bored. On the weekends, my wife and I oblige the kittens by tossing their toys around the house, flinging strings and jingling bells. We scratch their backs and feed them treats. They're both in love with these little stinky fish treats; all we need to do is shake the can, and they stop whatever they're doing and dash to the kitchen. Their English lexicon now includes their names and the words good and treats.

Monday through Friday, nine to five, however, the cats are responsible for their own entertainment. While we're away, we're sure the cats have a good time with their toys. Our rugs almost always are moved around, ping-pong balls end up in water dishes and fur covers our chairs. The only real difference between the weekday and the weekend is our presence and the lack of treats.

We have to work, but that doesn't mean our cats should have to go without stinky little fish, right? Why should our economic necessities have a negative effect on their treat times? Isn't it our responsibility to build them an Internet-enabled, Linux-based, cat-feeding device?

Where do we start? Three ingredients are key to our Linux-based Internet cat feeder: logic on the system, a way to talk to a device and a device to talk to. I chose Python for the logic piece, talking over a serial port to a microcontrolled cat feeder of my own design. Let's start at the bottom, the device, and work our way up to the top, the logic.

The BASIC Stamp Microcontroller

I first heard about the BASIC Stamp microcontroller from an article on Slashdot in which three guys were using a BASIC Stamp to control a bolt gun. They had taken some great pictures of bolts destroying fruit. Microcontrollers, I soon learned, are everywhere. They're the bits of logic in our microwaves and our remote controls. They are tiny and often difficult to use.

Parallax, Inc., specializes in making microcontrollers for non-engineers, specifically for students and hobbyists. Parallax products are well documented, easy to use and relatively inexpensive. I bought the Homework Board, the most inexpensive starter kit, from Radio Shack for around $75 US. It came with a book, a bag of electronic components for the experiments in the book and the board and chip.

The Stamp itself actually is a PIC microcontroller with some memory. Typically, you need to program microcontrollers with a low-level language, such as Assembly. What sets the BASIC Stamp apart from a typical microcontroller is the programming language you use to make it do stuff. Parallax developed a superset of BASIC, called PBASIC, that makes it easy to build expressive, useful programs quickly. In addition, the Homework Board has an integrated solderless breadboard, which makes for quick rewiring of projects.

The BASIC Stamp has 16 I/O pins. Each pin is set to high, +5V, or low, 0V, based on programs you create. Say you want to make an LED blink. You attach one end to an I/O pin and the other to a ground pin. You write a program that says, every second, turn the I/O pin to high (on), wait for a second, then turn it to low (off). Now replace the LED with a servo, and we've got the start of the cat feeder.

The I/O pins also listen for +5V or 0V. PBASIC even has a built-in function that allows an I/O pin to read serial data, the basis of which are high/low charges that make up binary words. Don't worry too much about serial connections yet; we cover them more in the next section. For now, understand that the BASIC Stamp can receive a command easily from a Linux system over a serial cable and turn on a servo that drives our cat feeder.

Linux and the STAMP

Parallax has done a great job of creating a fun community of hobbyists. Two mailing lists are devoted to its products, and dozens of sites have ideas for projects. Although the best integrated development environment for the BASIC Stamp is available only for Microsoft Windows, a tool called bstamp has been created, with Parallax's help, to program a BASIC Stamp with Linux. An example of tokenizing a program and running it, follows:

# bstamp_tokenize catcode.bs2 catcode.tok
PBASIC Tokenizer Library version 1.16

# bstamp_run catcode.tok
Model: Basic Stamp 2
Firmware version BCD = 16
Ack = 0
Ack = 0
Ack = 0
Ack = 0
Ack = 0
Ack = 0
Ack = 0
Ack = 0
Ack = 0
Ack = 0
Ack = 0
Ack = 0
DEBUG OUTPUT:  (Press [Control]-[C] to complete sequence)
_________________________________________________________
Waiting for Command
Received Command: B
Feed the kitty!
Waiting for Command
Received Command: B
Feed the kitty!
Waiting for Command

__________________________________________________________
Received [Control]-[C]!
Shutting down communication!

______________________

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.

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState