Monday, December 21, 2015

TreatMaster V-2 - Enhanced Remote Dog Treat Dispenser powered by Raspberry Pi

Introduction

This project was completed earlier in 2015, but I am only now blogging about it...I didn't want to wait till 2016 to get a post up!

I created TreatMaster V-2 during March 2015. It is a Remote Dog Treat Dispenser that you can control from your mobile phone. It is powered by Raspberry Pi. I wrote an iOS App for it as well. Read on if you wanna know more. If you want to see the demo, press play below. 


To watch a better quality video, please click here.


Inspiration

It all started with this post (Judd-Treat-Machine) that I saw online a few years back. It inspired me to start working on Raspberry Pi. What a nice idea to be able to give your dog a treat when he is all alone at home by himself, while you are out having a good time with your friends. A few days later, I bought myself my first Raspberry Pi Model B+ along with a bunch of components so I could start playing with it. 



I built the TreatMaster V-1 prototype (similar to Judd-Treat-Machine) earlier in 2015. The prototype was a bit ugly but it worked. They way it works was: 
  1. You send Mac an email (Yes, Mac has his personal Email) with the subject "Treat".
  2. The treat machine gets the email and will called out for Mac to get him all excited and come towards the machine. 
  3. The machine then dispense the treat, while Mac enjoys his treat, the web camera takes a photo of Mac and replies with a thank you email back to the sender. 
Pretty neat huh! It worked and I was having so much fun making it...Read up more if interested in looking at TreatMaster V-1. The end product looked like this.



After successfully creating that, I just couldn't get myself back to working on it again. 

Early this year, I completed the 2 player bartop Arcade Game Machine, and still with high momentum, I thought it will be a good time to build TreatMaster version 2. This time, I wanted to make it a lot better, where I would be able to see Mac live in action while he is taking the treat, and I want to be able to talk to Mac. So I begin to work. 

How do I start?

I tore down TreatMaster Version-1 to reuse some of the components. I did away with the web camera and got a Raspberry Pi Camera Board. The big chunky plastic container that I got from Walmart had to go. I went to Michael's and got a pretty good size box that I could modify to fit my use. I kept the relay circuit, motor, speaker and auger bit. I am pretty much good to go!

This is the TreatMaster V-2 Architecture:

Software 

Backend Service - RESTful API Server

Date: 11th April 2015, I installed 2015-02-16-raspbian-wheezy.img OS on Raspberry Pi.

Lets keep this high level, I won't go into much boring technical details. 

The first thing I focused on was software. I want to be able to remotely communicate with my raspberry pi that connects with the other hardware parts. What's better than running a RESTful API Server with Flask-RESTful that exposes APIs to control the raspberry pi. I wrote the API Services in Python, example of APIs are:
  • API to establish connection, once connected, security token is exchanged and all subsequent communication is done with the temporary token.
  • API to start/stop the video steaming. 
  • API to upload/play audio.
  • API to take photo.
  • API to dispense treats.



Note: The video streaming is actually recursive photos that kept refreshing on the webserver, it creates an illusion of video when you load it up on your browser. That was how old civilian cameras used to work (if I am not wrong).






Interested into more details? Here are the references to:

  • Install Audio
    • Command to bring up volumn configuration GUI: $ alsamizer
pi@raspberrypi ~ $ sudo apt-get install python-pip
    • After pip is installed, you can use it to install Flask and its dependencies:
pi@raspberrypi ~ $ sudo pip install flask

How does the machine dispense treats?

It uses an Auger Conveyor approach where a rotating helical screw blade moves granular materials, in this case...Mac's treat. This is the same item I used for my TreatMaster V-1. I used GPIO to trigger a relay switch that would rotate the blade for a specific duration to push some treats out of it's container.




Raspberry Pi has 17 GPIO pins (General Purpose Input / Output) that allows you to send Input or Output signal to the board. The pins are 3V3 and not 5V, they directly connected to the Broadcom chip. It has a good chance of frying your Pi if you send >3V down the pin.







This is the Relay Circuit that I used to control my Motor along with the components that I used.








Mobile App Client

Once I had all the API working, I started to design the app. I sketched it on a piece of paper before working on the User Interface. Here's my sketch.



I wrote the code in iOS since I have a MacBook and use an iPhone. Here are the progress and changes:

Initial development

Finally, I am satisfied with this version where it is clean and simple. 


Hardware

I am not a handy man for sure. This is the toughest part for me and took the most time. I tried my best to make it as neat as possible. But still, it could have been better. 



I measured it out and made a cardboard container just to see how it will turn out. It seems to fit well. So the idea is to put the small dog treats into the green container and the Auger bit will rotate and push the treat out. This part needs a bit more work at this moment, it is not working 100% smoothly as I wanted it to. Once I got the cardboard measurement right, I bought some cheap perspex and made a solid container.



The box I got from Michael's is slightly thin. It didn't look like it is able to hold my motor securely. As a result, I glued another piece of wood at the bottom so that it is lifted and thicker for me to screw and secure the motor. After that, more wood filler and sanding... and filler and sanding...


After about 10 times of wood filler and sanding.... I am finally satisfied with the result, so I start painting. I applied about 3 layers of white prime just to be sure (I know it is a bit over kill but I have way too much prime left), then I applied the paint that I have left over from the Arcade Machine. By this time...you would have thought I have master the skill of painting...I still struggle to get the paint spread evenly. I am blaming the paint brush for sure :)



So finally, after a few days of painting. I put all of them together and thought it could be better. With my skill and effort, I am satisfied with that. 



Mac got excited every time TreatMaster make a sound. He got a bit scared and unsure at first, but he is doing a lot better now and got used to this machine.

This is not the last of it. I do have plan to work on Version-3. I didn't really keep track of the cost since I am using the stuff that I already got but my guesstimate would be around $80. I could probably make it a lot cheaper. Who knows, I might be making this and selling it one of these days...

TreatMaster V-1 - Remote Dog Treat Dispenser powered by Raspberry Pi

Introduction

I designed a Treat Machine (TreatMaster V-1) between March to May, 2013. It is a Remote Dog Treat Dispenser that you allows you to trigger it via email. It is powered by Raspberry Pi. Read on if you wanna know more. I also made an upgraded version TreatMaster V-2. It is a lot more polished and allows you to control remotely through an iPhone App. Go here for more about TreatMaster2.

Inspiration

It started from reading online that there is a gadget that runs a full unix operating system. It is basically a complete computer at the size of a deck of playing cards. It is called the Raspberry Pi. It caught my attention with the potential, and being so small and neat. I had to have one to play around with. I bought it from Adafruit along with some electronic start up kits. As soon as I got it, I wasted no time to try it out. It was pretty simple to setup, and I was having fun playing around with it for the next 2 weeks. 

I was trying to think about what I could make, and came across this post (Judd-Treat-Machine). It was pretty straight forward and I thought it would be something that I could make for my dog. So I started work to build a Treat Machine for my tiny 4 legged buddy "Mac".


Software

I used the code from the link above as a starting point. Python was rather new to me but it was not that bad, it just took some time to get used to the syntax and stuff.... but I figured it out after all. I added a few more features and security into the script. So basically:
  1. It polls Mac's Gmail to look for new email. 
  2. If a valid email is intended to give Mac a treat, it will
    • Play a recorded Audio to get Mac's attention.
    • Dispense some treats for Mac.
    • Take a photo of Mac while he is enjoying his treats.
    • Send the photo back to the sender who gave a treat to Mac.
  3. I also added a few other security features, like:
    1. No treat is allowed during night time. It will resume and give Mac a treat in the morning.
    2. Limited treat are allowed during the day. I didn't want Mac to have any health issues :).
    3. Limited treats are allowed by the same user, I didn't wanna get email spam.
This is an email example of response that you get after Mac gets his treat. You get a thank you email from Mac along with a photo of him eating the treat.


Hardware


This part is slightly different from the Judd-Machine. I can't really do what he did. After some research, I decided to go with Auger Conveyor approach. It is a mechanism that uses a rotating helical screw blade that allows you to move granular materials. All I needed was a big enough Auger Bit that fit the size of Mac's treat and a high torque low RPM motor. 



This may have been overkill, but I found a really high torque 6RPM gearhead motor (12V DC) for $18.95 from eBay. It is so strong that I can't stop the rotation with my fingers.



 


Auger bit for $12 from HomeDepot.


At this point, I was glad that I studied 2 years of Electrical Engineering. At the least I know how to look at circuits and play with breadboard and components. I was surprised how much I remembered from my school days, and that I was able to put it to good use again!


I was playing with the GPIO (general purpose input/output) for the past few days and have a pretty good idea how to use them. The motor runs with 12V but the GPIO produces only 5V, so I needed a way to run a motor with a switch. I started to look at the relay switch circuit. I bought all the components from Fry's and hooked it up. It worked just fine. 


Once everything was tested working, It was time to solder it into the board. It could have been done a little more professionally but I was pretty happy with the end result. 


I took a container from a Dollar Store and converted it into my treat dispenser container. 



All of that looked very clunky but it did its job. It was pushing out treats, and I was able to program it to dispense a full meal. Mac was enjoying his treats while I was testing it. It was funny to see Mac as initially he was scared of the motor's sound, but after seeing what he would get, he got so excited. As soon as the motor started, he was right in front of the treat machine hoping that something dropped. The flaw of this machine is that I can't really control the consistent amount of treats to be dispensed. Sometime it has a few dispensed but occasionally it has none. Poor dog.


 


Finally, I found a cheap container rack and stuck everything in to it. and it looked like this:


So I really had a lot of fun making this, and learnt a few things along the way. Unfortunately, I didn't proceed to make the updated version until 2 years later :). Please check out my TreatMaster V-2. It is way smarter than this.