Blog

Side projects

Push4food : a Connected Button to Order Pizza

Here is a post relating my first journey into DIY (Do It Yourself) connected objects: the making of a connected button to order the ultimate developer food : pizza!

Connected Button

Motivation

Three months ago, I got a second hand Raspberry Pi and I wanted to do something original and fun with it. I did not have any idea of what to do to yet, but I was pretty interested in building a basic connected object.

Yes, I love connected objects! Especially ones with basic controls, and no screen at all. To me, they are a proof that connecting objects to the Internet does not mean putting a touch screen on all of them.

I also knew, that I will end up doing hardware like soldering wires. Something I haven’t done in years (probably since high school): the challenge motivated me even more !


Connected Button

Never heard of the Raspberry Pi?

The Raspberry Pi is a credit card size and inexpensive computer designed to teach computing to kids at school. It is also very popular in DIY electronics thanks to its GPIO pins (General Purpose Input/Output) which is a read and write interface to the outside world.

 

 

 


Inspiration

Wanting to do something is good, but then you need to find out what… I had a lot of ideas, but not much time (2 to 3 evenings a week) : I had to find something original but not expensive, and that I could finish in a couple of months.

So I started thinking of what simple connected object impressed me the most… The first thing that came to my mind was the Darty button.

The Darty button

Darty is a company specialized in eletrical retailing: they sell toasters, fridges, tablets, vaccum cleaners, and much more… Last year, they came with a simple, but very interesting, idea of a button that you can push at anytime to call for help.

If you need support for one of the electric devices you bought at Darty, just push the button, at anytime, on any day, and an advisor will call you back in just a few minutes.

The piece of hardware is quite interesting as well: no cable required (works on battery and connects to your Wifi network) and has magnet at the back, so you can put it on your fridge or washing machine.

I had my idea: building a connected button!

But a button to do what?

A button can do a lot of things, but I really knew what I wanted my button to do on May, when Domino’s Pizza announced their Tweet to order feature.

Domino’s Pizza Tweet to order feature is a way to order pizzas using Twitter: you just have to tweet a pizza emoji to order a pizza.

Of course, you need to setup your account first, and it is available in the US only, but I had my idea: an automatic pizza ordering system! 

Imagine: you push a button and it orders an delivers a pizza for you.

No phone call, no endless web forms to fill… Your pizza is just a push away!

The piepal

A button to order pizzas: that was my idea. But I was not the first to think about it…

In 2013, some guys made the piepal: a pretty button to do exactly want I wanted to do.

The piepal is 3D printed, and works with… A Raspberry Pi (of course). You can turn the button to select the quantity and push the button to order.

The button is plugged on the Domino’s Pizza API (which is available in the US only). Very good project!

But remember: my goal was to have fun, so I decided to do it anyway.

Design

When first thinking of my button design, I was very inspired by the piepal and wanted to have 2 controls: one to select the quantity, and another one to send the order.

Keep it simple and stupid

However, when my 6 years old son came with this sketch:

Connected Button

I changed my mind: a single control is better than 2. It’s simpler to use, and more challenging to design!

Yes, challenging, because it was important to me to keep the ability to control the quantity: pizza is a social dish after all. You eat a pizza with friends, family or co-workers. Never alone!

How to control the quantity with a single button?

After some googling around I found arcade style buttons with builtin led.

So I figured out a kind of state machine where the button action changes, depending on the led state.

Here is the idea I ended up with:

Connected Button

On the first push, a single pizza is being order, but the order is not sent immediately: the button led starts blinking and waits a bit, so you can push the button again to increase quantity.

When the button stops blinking: order is sent.

If order succeeds, the button led stays on until the pizza is delivered (actually: until the estimated delivery time is elapsed). If the button starts blinking very quickly: an error occurred.

Easy as pizza !

Making of

Of course, the button is composed of the software and a hardware part.

foodcommander

Software was the bigger part… Wanting to order pizza with an API (Application Program Interface) is nice. But I did not find any franchise with an order API.

Domino’s Pizza has one in the US, but nothing in France… Shame! So before working on the button itself, I spent nights building my own API on top of the Domino’s Pizza website.

I did that using Node.js, which is a pretty good development tool (especially if your are not a Python fan) for the Raspberry Pi.

I made my own standard library that can support multiple franchises (even though only Domino’s FR is implemented): foodcommander. It comes as an API and a CLI (Command Line Interface). For more information on installation and usage, please visit the Github site.

With foodcommander, you can:

Look for a store near you:

$ foodcom store -p 34090

Have a look at the menu of a given store:

$ foodcom menu -s 31972

And of course: order

$ foodcom order -d PORI[size=large]*2,P4FR
--firstname Homer --lastname Simpson --email homer.simpson@somewhere.com
--street "evergreen terrace" --streetnumber 74 --phone 0999555555 -p 34090 -c montpellier -s 31972

Let’s solder!

Once I had my order API, it was time to have a lookat the hardware.

I already had a Rapberry B+ model. I just had to find the button…

During the design phase I found nice arcade buttons with builtin led, but it was nothing compared to the Massive Arcade Button that I found on Adafruit: I needed it!

It’s a huge button working with a micro-switch, that has a builtin led with a resistor (up to 12V).

Once I found it, I just had to solder wires with jumpers on the micro-switch and led connectors and plug everything on the Raspberry Pi GPIO (one port for the switch, and one for the led).

Pullup/down you said ?

Then, it was time to test the button and the led with a basic script: led was ok, but I was not able to read the button state… No matter what I was trying: button state was always 0.

And suddenly, I found out!

A micro-switch is pretty basic: it is either opened (no signal) or closed (signal) and by default GPIO ports are set to 0. So if it is 0 when closed, it stays on 0 when opened…

To change that 0 value as initial state, I had to set the micro-switch port as pullup. I used the wiringPi utility for that:

$ gpio -g mode 23 up

Here port 23 is set as pullup : read value is now 1 by default, and will move to 0 when micro-switch is opened!

A decent case

Once button, led and API where okay, I had to find a case for the button.

At first, I was thinking of a 3D printing (still the piepal influence), but the case had to be large enough to embed the button (which is pretty deep) and the Raspberry: most printers available in fablabs where not able to print a case big enough. I had to find something else.

I thought of ordering a 3D printing online, but it was way to expensive… So I decided to fallback to a common case.

I finally found a this ABS case on gotronic. Not the case of my dreams, but after I added stickers on it, that did the trick.

The bill

Here is all the hardware I bought for the project:

With shipping costs, the total expense is $88 (80€).

The final bit of code

As foodcommander, the button software is written with Node.js.

It is waiting for a button push to trigger the state machine sequence.

The only tricky part in this program was to add a debounce interval to the button: a slight delay to avoid getting a value change triggered twice within a single button push.

The full source code for the button is available here.

And the result…

That was my first dive into DIY connected objects, and I really enjoyed it!

Mixing software and hardware gives you a lot of possibilities that you can try at home with affordable components.

If you read this post carefully, and have a look at the Github repositories and tools I mentioned, you should be able to build your own connected button.