This is part 2 of a series describing modifications to an automatic cat feeder used to selectively feed cats. The overview can be found here:
The Smart(er) Cat Feeder Starring TensorFlow and Raspberry Pi
The Raspberry Pi 3
A Raspberry Pi 3 has just enough horsepower to run pre-trained TensorFlow apps, and a bunch of code for getting up and running on the Pi. There’s also a burgeoning IoT and hacking community, which makes is a great hub for controlling internet connected stuff.
A basic Pi setup needs a bit of hardware:
- A SD Card. I recommend 32GB – 64GB to have plenty of room for TensorFlow models, pictures, and video.
- 5V Power. There’s no power cord, so I got a 10ft. micro USB cable and 5V adapter.
- A RPi case. Plenty of these out there. I got a cheap plastic one for a couple bucks on eBay.
And the basic software setup:
- Raspbian & Pixel Desktop. I went with the new desktop GUI rather than headless to try out Pixel, and to do development and testing right on the Pi itself without another computer.
- Add a hidden network to the Wifi list:
sudo iwlist wlan0 scan essid [yourSSID]
- Less cruft. Raspbian comes with too much stuff. Easy to remove, though.
- Node.js 7
- VNC. In case I did want to log in remotely, I had to fiddle with the video settings in
to get a decent sized window. Using hdmi_group=2 and hdmi_mode=27 did the trick.
The Raspberry Pi Camera
I read a few places that the version 1 (5MP) camera module is better with auto focus than the v2 (8MP) module, so I got a v1 from eBay for about $15. I’m not dissappointed. I ended up using 600×600 pictures in the project anyway, so extra megapixels would have been wasted, and all the features (focus, white balance, filters, rotation, etc…) work great.
There are some clones of the camera module from China for a few dollars less, but why risk it? I did, however, order a protective camera covering from China for $1. I’m still waiting on it as of this writing, though.
Remote Control Sockets and RF Transmitter
Here’s where the real fun begins. To turn the feeder (and accompanying lamp) on and off, I used remote controlled outlets, but spoofed the remote control frequencies with the Rapsberry Pi and a radio frequency (RF) transmitter attachment. In order to get the RF codes to activate the outlets, a RF receiver attachment is necessary as well. Luckily, the receiver and transmitter are sold in pairs, and are really cheap.
I followed a couple great guides for inspiration and to set up the proper tooling;
- Wireless Power Outlets – Tim Leland
- How to Control Power Outlets Wirelessly Using the Raspberry Pi – Sam Kear
The guides above go a few extra steps and set up a web server with PHP, but I skipped that in favor of using Node (more on that in the next article). The basic steps for the setup are as follows:
- Install WiringPi and RFSniffer
- Plug in the reciever to the Raspberry Pi.
- Start RFSniffer.
- Push all the buttons on the remote control, and write down all the codes. It will look something like
Received 21811 Received pulse 192 Received 21813 Received pulse 192
- Plug in the transmitter to the Raspberry Pi.
- Test the codes with codesend. Be sure to substitute in your own code and pulse values read from RFSniffer.
./codesend 21811 -l 192 -p 0
Also, the first RF Transmitter I got was busted. I noticed that the circuitboard was slightly different than those pictured in the guides I used. Instead of ‘data’ printed on the transmitter, it said ‘ADAT’. I returned the set, and ordered a receiver/transmitter with ‘DATA’ and everything worked fine.
Good to Go!
With the Raspberry Pi set up with a working camera and the ability to turn electronic devices on and off, the stage was set. The rest was just a simple matter of programming…