Pi stuff and Reassembly
This 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 Control
Wiring 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
Wifi
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.
Log space
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 Script
I 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=1Now 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 |
Final thoughts
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.
Thanks Dan! Based on your question and a few others I updated the Part I post to include an image of where we wired the relay boards. Take a look at Part I again and see if that helps. Let me know if you need a little more. I'm always happy to help. Good luck on your project. If you get it going I encourage you to do a write up or at least share pictures. Thanks!
ReplyDeleteBen
Ben,
ReplyDeleteGreat project, did you post your script for checking email and executing commands on the Pi? I would appreciate the link.
Thanks,
John C
Thanks! I had not posted the scripts. But after your request I have! I setup a github repository for it. You can find that here: https://github.com/locgt/frankenfeeder
DeleteI'm going to go update my post too. Hope this helps. Have fun, and I'd love to know if you are able to get your own frankenfeeder up and running.
First and foremost thanks so much for the inspiration for this! My fiance and I have this 99.9% working minus the code provided. I made a quick python code to confirm my PCB I made works off of your schematic and to my delight the loud motors came to life.
ReplyDeleteIs there anyway you can clarify on how to get the code running? In your code you reference a folder with the SendEmail folder and other things I think that are specific to your Raspberry Pi setup. I am going to post more images/specifics to my setup as we took yours and ran with it combining the PCB into one board, using the battery bay to hold the Raspberry Pi with everything easily removable, making it power from 1 power supply that plugs in for the Pi/Feeder instead of batteries and more. Thanks again!
Fantastic! So great to hear that you've gotten things up and going. I'm especial excited at your optimizations. A single board PCB and running it from one power supply. Those are great improvements. For the best explanation of how to get stuff working, check the comments at the top of the script. The sendemail bit is because the distro version of sendemail didn't understand a current version of TLS google was using for gmail. If you use a different email service or the current version does work, then you don't need this bit. You can just use the system path for sendemail (#> which sendemail).
DeleteMake sure to install the modules listed on line 12 to supply sendemail and other needed modules. And don't overlook line 18 if you are using a webcam. Feel free to post another note here for clarity or ping me @vmfoo and I'll be happy to answer what I can.
I'd love to see picture of your project when you get it going!
Thanks for your quick reply! I have a few more questions:
DeleteWhat version of sendemail are you using thats compatible with gmail? We made a gmail account just for this.
Whats the folder structure youre using, is the feedme.pl in the same folder as the sendemail?
Do you also have your feedme.pl script run on reboot?
Is yours still running today?
Chris,
DeleteI'm not sure which version I am/was using. As it relates to your last question, sadly Frankenfeeder failed about a month ago. It stopped working because the SD card became corrupt. Yous may actually work much longer and better being in a compartment that doesn't have dog food dust vibrating around in it! I believe that infusion of dog food particles didn't lend to the duration of the SD card.
So, my suggestion is to try the sendemail version that installs with the apt package and if it doesn't complain, you are all set. (don't forget to enable imap in your gmail account in the Forwarding and Pop/IMAP section of settings) If the script complains, then make a copy, make the change indicated in the comment header on the feedme.pl script and reference that version in your code.
I was keeping my script in /home/pi/scripts/feedme/ and I copied a version of sendemail there as well.
Finally, feedme.pl is designed to run as a cron job. It runs once and exits. We ran ours once per minute but you can choose how often you want it to run with your crontab settings.
I hope that helps.