Pi stuff and ReassemblyThis is Part III, Part II is here.
The Pi and what you can do with it is a deeeeep subject. I'll just stick to the highlights. Turning on/off GPIO pins, high level Wifi and sundry, and the script.
GPIO ControlWiring Pi by Gordon @drogon, is an excellent project for low level Pi IO control. Actually his whole site is just pure awesomeness if you have the time to read. Anyway, I followed the instructions on downloading and installing Wiring Pi on my Pi. I've heard rumors this is included in the base distro now, but you might want to check your version of the distro to be sure.
With the wiring pi package there is a binary, the gpio util, that allows you to issue command line commands to see the state of the pins and turn them high/low.
We're using Pins number 17 and number 22 for our project. The commands to set these into output mode are:
Then to turn them high:/usr/local/bin/gpio -g mode 17 out /usr/local/bin/gpio -g mode 22 out
And low:/usr/local/bin/gpio -g write 17 1 /usr/local/bin/gpio -g write 22 1
So with that setup, on to .../usr/local/bin/gpio -g write 17 0 /usr/local/bin/gpio -g write 22 0
The hardware part of this is pretty simple. Just pop this little baby in one of the available USB slots and poof. Wifi.
Now, you will need to mess around with the network settings. I won't bore you with details but there are LOTS of articles on configuring wifi with debian for headless, roaming, whatever suits your needs and security. I'm not going to try to replicate them here. But I will say that we chose to go with a static IP address and leave SSH server turned on so we could push code updates and troubleshoot as needed.
Another note about configuring the Pi. I had an SD card go bad on me because of all the logging going on from my script. My fault, and cheap SD card. So I chose to put /var/log on tmpfs. Here's a little info on doing that if you want to. It means that you lose your logs if the thing reboots, but it means you are not writing a hole into your SD card. Logs write into RAM instead of the SD card.
Webcam and ScriptI had a very cheap USB webcam laying about that I threw at this project (Kodak S101). The Pi recognized it by default. But in order to use "streamer" with it to grab pictures from the camera at the command line, I had to fix this kernel parameter in the /etc/sysctl.conf vm.overcommit_memory=1
Now I can grab pictures from the camera with: streamer -o filename.jpg
So all the parts are here, GPIO, Wifi, Webcam, oh, and of course perl. The next step was to create a perl script that used all these bits. In the script, we are checking a gmail account to look for a message and trigger the feeder. The details of the script are a whole other subject, but suffice it to say that if folks are interested I'll go through the effort to post my script on github and link it. Update: The script can be found here on github: https://github.com/locgt/frankenfeeder
Below are some pictures as we reassembled the dog feeder with notes:
|Two of the relay boards glued back to back|
|The relay boards in the feeder shell. Lots of hot glue.|
The Pi itself we originally hot glued to a foam backing and then to the inner side opposite the feeder PCB. You can see it in the picture above and below. Later when we had to do some fixing up and needed to get access to a video out etc, we removed the glue and foam and replaced it with double-sided Velcro.
|Here it is. All wired up.|
|All buttoned up.|
Because there are two schnauzers to be fed a system to divide up the food was devised. My Dad's a better mechanical engineer than I. This is his handiwork
|It works! Dog tested and approved. The webcam to the right in the picture sends the picture back.|
Finally, the proof is in the pudding. Here's a picture from the feeder after a successful feeding.
|Nom nom nom nom|
The lessons we learned during this we too numerous to write up here which was the point in doing it. We had a blast and learned a lot. The dogs liked our mistakes a lot as well. NOM NOM. We had some false starts, blunders, and in the end a great lesson in hardware hacking with the Raspberry Pi.