Adventures in IoT, the Internet of Things

The History

A few years ago, the Microsoft Technology Center in Detroit built something called a Social Downpour. I never saw it in person, but some friends of mine at Microsoft told me about it and showed me pictures. It’s a kind of internet-connected dunk tank.

At the top, it looks like this:

There is a person on a stool sitting on each side. Depending on twitter traffic, one gets soaked.

Now, having used X10 and Insteon lighting automation products, I know something about lighting control, and I knew that there were electronic control water values out there. I’ve also got experience writing C#. With the release of Windows 10 IoT core, I felt there was a microcontroller platform I could write code for. In short, I felt I could build this!

The original had a few shortcomings. First, it was built on an older microcontroller, and I wanted to build something that would showcase Windows 10 IoT core. Second, the device was large which made it hard to transport and store. For something that we might want to use as an IoT Demo at an exhibitor booth at IT conferences and consumer STEM events, the bulk and outdoor-ness of this contraption was a challenge.

So I came up with some new requirements and began to decompose the problem.

Requirements

The solution must use a Raspberry Pi 2 running Windows 10 IoT Core.

The solution must watch Twitter over a short interval and count the tweets to a particular account (e.g. @SocialDownpour) that use either of two hashtags. The side with the highest hashtag count gets activated and something fun or funny must happen. That could be, but doesn’t have to be, turning on a showerhead and spraying water. In fact, some action that doesn’t involve consumables would be more environmentally friendly.

The following settings are configurable:

The voting interval. This is the period of time during which users can tweet at the specified account. Once this interval is over, the tweets are counted and the action is taken on the corresponding side.

The hashtags for each side. For example, #Red and #Blue.

The Twitter account to monitor.

The authentication info needed in order to query Twitter, if any. In early iterations of development, it would be ok if this was hardcoded.

Problem Decomposition

I asked myself, what are the key challenges in creating a Social Downpour 2.0 (my initial name for this project)?

  1. Obtain a Raspberry Pi 2 and get it running with Windows 10 IoT core.
  2. Write code for the device that queries Twitter and analyses the results
  3. Based on the results, do something.

#1 – Get Pi

Getting the Raspberry Pi 2 wasn’t hard. Although you can buy them directly from RaspberryPi.org, you can save a little on shipping if you buy them on eBay. Also, on eBay you can find vendors packaging them with nice starter kits. For just under $90, I got a Pi plus a bunch of electronics and a case. See http://www.ebay.com/itm/252035066234 .

The case was easy to assemble and because it is clear, people can see the Pi easily. The assembly video is here: https://www.youtube.com/watch?v=KGIWkZYw7Ng. It’s silent but effective. Installing the Visual Studio tools and getting the Windows IoT Core files and transferring them to the SD card was not hard.

I don’t have a dedicated monitor for this project yet, although I am considering a portable 7 inch screen with HDMI input that you can find on eBay. In the meantime, I plug it into the HDMI input on my TV. Plugging power in too, it boots. But it fails to find any Wifi networks, so I don’t think it is recognizing either of two Wifi dongles that I tried with it. Ethernet works however. This lets me discover that I can’t start the WinRM service on my Surface RT, which I assume means I need a “real”, non RT, full OS to be my WinRM client.

#2 – Query Twitter

Writing code to query twitter should be straightforward, because Twitter has a well documented REST API. However, the Advanced Query page does not support time granularity less than 1 day. I’ll have to take that into account at some point. At least a starting point for the query template is https://twitter.com/search?f=tweets&q=%23red%20%40socialdownpour%20since%3A2015-10-17%20until%3A2015-10-17&src=typd . Let’s come back to this later.

#3 – Do Something

Moving onto #3, based on the results, do something. Well, in the original Social Downpour, that was activating a showerhead. That’s fairly complicated, both logistically and electronically. Well, not that complicated, but more complicated than necessary. Logistically, it means you need to locate the Social Downpour device outside and near a garden hose, and someplace where it’s ok to spray a lot of water. Inside a building is not an option. A season other than summer is not an option. Electronically, I’d have to create a circuit that controls another circuit with a separate power supply, because the electronically activated water valve I found online is 12 volts and the voltage output pins on the GPIO connector on the Raspberry Pi 2 only offer choices of 3.3 volts and 5 volts. So let’s simplify. What if we could activate a can of silly string instead of a showerhead? Still too complicated – I’d have to mount an actuator pin to a can of silly string. It’s fun but involved consumables, which isn’t all that environmentally friendly. I saw an electronics kit at LakeShore Learning that had some gadgets that ran off of 3 volts. I could wire one up to the Red side and another to the Blue side. Still, from an incremental design perspective, what was the absolutely simplest hardware setup that would prove we could send one signal if Red won and a different signal if Blue won? The answer is LEDs. My Pi starter kit came with Red, Green, and Blue LEDs and a breadboard. But not a very big breadboard – more about that in a moment. Design decision first: In the first version of this system, I’d have 3 LEDs on a bread board. Red on one side, which would light up if Red won. Green in the middle to show when voting/tweeting was open. Blue on the other side, lit when Blue won. Following the example from the Blinky project, I made a wiring diagram for these three LEDs.

I have a friend who is an electrical engineer by profession, and he kindly reviewed my wiring diagram and approved it. However, when I tried putting this into practice, I encountered some challenges.

First, I was using the ribbon cable from the starter kit and I had that plugged into the breakout board from the starter kit. When I inserted the breakout board into the breadboard, there wasn’t much room to work. So I ordered another breakout board with also came with jumper wires that had one female end and one male end, as opposed to the male-male cables in the starter kit. This gave me options. I could do away with the ribbon cable or use a second breadboard. I chose to use the second bread board.

Now the ribbon cable connects the Pi to the first breakout board, and jumper wires connect the first and second breakout boards. The LEDs and resistors (220 ohm) are on the second breadboard.

I found a box I could put all three sections in, and temporarily put the hardware on a shelf. Next time I have time, I will Velcro the boards and the Pi in place, and cut some holes for ventilation and power and HDMI and Ethernet, and glue on a box for the mini keyboard. I’m ready to write some code to test if I really can control the three LEDs.

To be continued…