Here at Yelp, we enjoy a good brew. We also love our jobs as engineers! So for our recent Hackathon, it made perfect sense to build something that made drinking beer more…interactive. We call it KegMate.

</embed>

Being that you’ve found yourself on our Engineering blog, I bet you’re interested in how it works, eh?

Theory of Operation (An Overview)

Sensors attached to the keg feed data into an Arduino microcontroller, which in turn communicates directly with the iPad via a serial connection. The iPad processes that data and displays it in a snazzy manner along with a description of the current brew. An RFID reader attached to the system allows users to ‘swipe in’ to KegMate and keep track of how much beer they’ve had, as well as assign a star rating for the beer currently in the keg (this is Yelp, after all).

</embed>

Sensors! Data!

Let’s start from the bottom, closest to the beer. At the lowest level, we have a LM335A analog temperature sensor, ID-12 RFID reader, and a SwissFlow SF800 flow sensor attached to an Arduino microcontroller. The temperature sensor is an analog sensor, though we’ll probably go with a digital one-wire sensor in the future (hey, we only had a couple days to build this thing!). We mounted the temperature sensor on the side of the keg towards the bottom; ideally we would know the temperature of the beer in the keg, but since it’s not practical to get a temperature sensor inside the keg, this was the next best thing. The flow sensor sends the Arduino an electrical pulse every time ~.164mL passes through it. By counting the pulses we can calculate the volume and flow rate of the beer passing through the tube. The RFID reader sends distinct codes to the Arduino every time a card comes within range. While many kegbots attach the RFID reader directly to the host computer, we had to attach the RFID reader to the Arduino since we only had a single serial connection going to the iPad (more on that later). We used Mikal Hart’s NewSoftSerial library to instantiate an interrupt-driven serial port using another GPIO pin that receives data from the RFID reader. The Arduino is running a modified version of KegBot.org’s Kegboard firmware that handles the packetization of all the sensor data. We had to add support for the ID-12 RFID reader as well as the analog temperature sensor, but other than that, the Kegboard code is unmodified.

Establishing Communication with the iPad

To use the iPad’s dock connector for serial communication one must either be a part of Apple’s MFI (Made for iPhone/iPod/iPad) program or jailbreak the iPad. We opted to jailbreak the iPad. Note that while jailbreaking the iPad can usually be reversed by restoring the device from iTunes, Apple’s official stance is that it “can violate the warranty and can cause the [device] to become unstable and not work reliably”. So proceed at your own risk. After the iPad is jailbroken, the serial port in the iPad’s 30 pin dock connector can be opened just like any POSIX serial port:

int fileDescriptor = open(/dev/tty.iap, O_RDWR | O_NOCTTY | O_NONBLOCK);

There is one caveat here: any program that will access the serial port must be in /Applications on the iPad’s file system. It took us a while to figure this one out. This means you cannot install your application from XCode and expect them to immediately work. You must first move it to /Applications using ssh. We opted to send new builds directly to the iPad using scp. This turned out to be a great setup, because we could program the iPad without disconnecting it from the Arduino.

``

scp -r KegPad/build/Debug-iphoneos/KegPad.app root@[IP ADDRESS OF IPAD]:/Applications

Be especially careful when making connections to the iPad; make sure to check the pinout of the connector that you are using several times. We used a PodBreakout v1.4 board which had a different pinout than other versions of the same PodBreakout board.

iPad Software

The iPad software is the center of KegMate. Under the hood, we built a parser that interprets the input from the Arduino, processes that stream, and gives the important data to the view controllers handling the UI. Currently we use CoreData to store information about the beer and users, though in the future we’d like to move this data to an independent backend so we can support multiple KegBots in different locations.

That’s it!

When assembled, you get a neat project that makes drinking beer even more fun! (Did you know that was possible?)

This is definitely a work in progress; we’ve started working on an independent backend with an API to store all the beer and user data. This will allow us to install KegMates on all our kegerators and have them share data in real time. We’re also awaiting delivery of our shiny new RFID reader that will allow us to use our work security badges to swipe into KegMate. Don’t worry… we plan on keeping the github project up to date with these new improvements.

Also, a quick disclaimer: mixing beer and electronics with your iPad could easily go very poorly if you’re not careful. Build your own KegMate only if you have a good idea of what you’re doing. Proceed at your own risk!

Have fun! Let us know how your KegMate turns out.

Resources

Back to blog