Last month Nat Morris built a Twitter-controlled feeder for his dog, Toby. In the first five days of this being online it was being used by a group consisting of friends and family. But after national press coverage he woke up one morning to find that 4,500 people had suddenly tried to feed Toby!
At the heart of Nat's invention lies a small network-enabled microcontroller called Nanode. A derivative of the Arduino, the Nanode remains compatible with its IDE, software libraries and hardware expansion via shields. Targeted at network applications — the hint is in the name! — the Nanode serves as a great example of the power of open source technology, in demonstrating how anyone is free to adapt the Arduino design for specific uses, whilst remaining able to leverage the extensive software support and a vibrant community.
I caught up with Nat and he was kind enough to answer a few questions on the technical implementation of @FeedToby.
How did you interface the Nanode with the motor?
The motor is a Mitsumi stepper motor that I took out of a HP Deskjet 500 printer that has sat in my dad's garage for the last 12 years gathering dust. I used a ULN2003 Darlington array to drive the stepper motor.
What are the LCD display and loudspeaker used for?
The LCD display I pulled out of a broken Dell Laser Printer — I've found printers are great for getting a range of really useful parts. When the feeder is starting up the LCD shows things like the feed trap resetting, the IP address received via DHCP and how many times it has dispensed treats that day.
I put together a simple 555 timer circuit to drive the speaker, and that's Toby's cue that a treat will shortly be dispensed. I thought it'd take him much longer to learn what was going on, but after only 4 or 5 goes he would run down from wherever he was in the house and sit underneath the feeder looking up.
Did you have to write all the software from scratch, or were you able to make use of existing code?
Can you explain how the Twitter integration works.
The Nanode sits on our home network along with two IP cameras, which are pointed below and at the feeder.
A virtual machine that's running on a PC underneath the stairs runs a script that checks twitter every 30 seconds, and uses the Twitter API to find mentions of @FeedToby. Initally for the first week, the script would reply to all the tweets it received so users could send messages like @feedtoby help, @feedtoby about, @feedtoby photo (where it'd grab a picture from the cameras and upload it). This was all well and good with just friends and family, but as soon as the story hit the Metro the script was replying to every tweet and we promptly hit the Twitter API limits and were blocked for an hour.
I had to make some quick changes so that it stopped replying to each message received and only tweeted when he got fed.
The script has some built in restrictions so that he can only be fed between the hours of 9AM and 9PM, plus only once in a 30 minute period. Upon receiving @feedtoby feed it calls the web server running on the Nanode, which sounds the buzzer and starts the feed process. At the same time the script forks a new thread and begins to capture photos from the webcam half a second apart. It then creates a custom graphic with 9 photos in, the time and the twitter avatar of whoever fed him, and it posts this to yfrog using their API.
How are metrics collected and the graphs produced?
All actions and functions increment internal counters in the script, and every minute these are written out to a text file. These metrics are then pulled into Cacti.
Have you made any of the software available?
Nothing is available yet as it's all bit of mess to be honest, but once I tidy it up I'll upload it to GitHub.
How long did it take to assemble the hardware and to write the code?
Assembling the Nanode and building the stepper driver, LCD and buzzer circuits took an evening, plus another one to write the Twitter co-ordination script. The trickiest part of the whole project was getting the treats to regularly fall out of the feeder — my father in law gave me a hand with the dispenser and we spent hours trying to perfect that bit.
Many thanks for taking the time to explain how @FeedToby works, Nat!
Leave a comment