The Super Kickass Temperature Logger Thingamabob

It all started with an email. (Don't they always?)

In this case, the email was from the Dallas Coding Workshops and Hackathons group at meetup.com. Now, I've been a member of meetup.com for a long time, and I've signed up for many more meetup groups than I probably should have, and for the most part, I've found that emails from meetup.com are for events that I'm either not interested in, or that I'm not available to attend. In this case, however, the planets aligned: this was an event that both interested me, and for which I had the time to attend! The email came on August 10 and announced a Hackaton the weekend of August 19-20. I checked my calendar and found that I don't have the kids that week (yes, that's foreshadowing; stay tuned), and there was nothing pressing on my calendar.

For the first time in a long time, I clicked "YES" on the "Are you going?" link that meetup.com provided me.

Friday Afternoon

On Friday I was able to get off work early and for the first time really considered the question: what am I going to do at the Hackathon? What am I going to bring? I went to Wal-Mart and bought a $5 tackle box from the crafting section, went home, and crammed it full of various dev boards, Arduinos, R-Pi's, USB cables, a soldering iron, jumper wires... basically, anything that looked like it might be useful or fun to work with. I quickly ran out of room in the tackle box and filled a small cardboard box with overflow items, all of which went into my car. I hadn't read the details of the event, so I threw a sleeping bag, a pillow, and a toothbrush into the trunk, and headed out into a rare summer downpour in Dallas.

2016-08-22 21.59.49 2016-08-22 22.01.37

Friday Night

I arrived at the front door at about 6:15, which meant that I was fashionably late for the 6PM start of the event. I trailed another guy into the building who was hauling a wheeled tote full of doodads with him. I suddenly felt a lot less self-conscious about carrying a plastic toolbox full of dev boards.

When I got upstairs, I was a little surprised to find few people there. There were maybe two dozen folks milling about noshing on the food that AT&T, the event sponsor, provided us. (Clearly, this was going to be a great event. We hadn't even started yet and were being fed!) I'm guessing the weather-fueled traffic was responsible for the meager early turnout, because an hour later the presentation room was full of folks finishing up dinners on disposable plates when our emcee kicked things off.

Things kicked off when our emcee, Ed, took the floor and welcomed us and explained the rules. I didn't take copious notes, but in general, the rules were, "form teams, build something cool, demo it tomorrow at 6PM." There were no requirements on technologies that had to be used. The only real requirement was that we had to demo something that worked the next night (although even that rule wasn't strictly adhered to.)

Ed allowed volunteers to stand up and pitch either an idea, or pitch ourselves to help form teams. I stood up and showed my toolbox stuffed with electronics goodies and said I was looking for a team that would give me an opportunity to use one of the doodads I hadn't used before. After about a dozen or so pitches, it became a free-for-all for us to meet each other, discuss ideas, and form teams. I ended up in a group of about 8-12 people where we talked about ideas we had.

My personal idea for a hack was a temperature logger. I've found that the air conditioning system in my house heats and cools the house unevenly, but I've never gathered the data to measure, and therefore be able to fix, the problem. I wanted to use an ESP8266 board with a DS18B20 temperature sensor to build a battery-powered node to gather data on temperature vs. time. I wanted to make these nodes cheap enough that I could build a passel of them and put them all around the house, where they'd log data to The Cloud and I'd later be able to use a web browser to dig into the data. Another person suggested taking the idea a step further: once I measure the temperature imbalances in the house, I could use similar ESP8266-based modules to drive servos that would adjust the louvers in the air conditioning vents to restrict or open up airflow, and thus automatically fix the problem.

And that, my friends, was a great idea!

After the pitches and discussions, I ended up forming a team with Ean and Leandro. Friday night we discussed my idea and one or two others. By the time I left for the night (the venue was closed between midnight and 9AM), I was committed to my temperature logger idea. Ean and I decided that we'd meet up at Tanner Electronics when they opened the doors Saturday morning to buy parts, then we'd head in to the hackathon to build our product.

I went home and soldered some pigtails onto some ESP-03 modules that I had, I installed the Arduino software and the ESP8266 board package on my laptop, and went to bed around midnight. (Sadly, my 44 year old body is no longer able to pull all-nighters.)

Saturday Morning

I managed to get myself out of bed and showered in time to meet Ean at Tanner by 9. Heck, I even managed to grab a Whatabreakfast on the way. I was in the parking lot when Jim opened the doors at 9AM.

For those of you who don't know what I'm talking about, Jim Tanner runs a surplus electronics shop just north of Loop 635 in Dallas. It's a hardware hacker's toy store. All kinds of surplus discrete components, oddities, tools, cables, parts... the list goes on. In addition to the surplus inventory, Jim stocks a wide variety of maker components: Arduinos, R-Pi's, ESP8266 boards, FTDI cables, LCD and LED displays, microcontrollers, sensors, kits.. wow. His prices on the maker inventory are a little high and certainly not competitive with AliExpress, but on the other hand you don't have to wait 4-6 weeks for your order or deal with Chinglish (Engrish?) speaking sellers.

My goal was to pick up a few DS18B20 temperature sensors. I bought Jim out of his only DS18B20 and took his last ESP-03 board while I was there. Oh yeah, I also picked up some supercool breadboard power supplies. These puppies plug directly into the power distribution rails on your breadboard, and each side can be jumpered to 3.3V or 5V. Naturally, I picked up some breadboards and some power bricks to feed the boards with juice.

Going to Tanner always has a damaging effect on my wallet.

Ean was running a little late and pulled up just as I was getting ready to drive back downtown. He did his shopping and we drove back to the event and I set up my work area...

2016-08-20 11.00.07

...and got to work.

2016-08-20 11.12.55

Other teams were already plugging away.

2016-08-20 15.29.13

I'd never used an ESP8266 module before, so the first thing I did was build the obligatory blink-a-LED project. (I actually had to borrow an LED for this; I had neglected to put any in my kit when I raided my workshop before heading out.) The power supply, breadboard, ESP8266, FTDI programming cable, and LED were wired after a few trips to Google for pinout information.

2016-08-20 11.42.24

After a quick refresher on the Arduino environment (which I really, really hate, but have to begrudgingly admit does allow for very rapid prototyping), I had an LED blinking!

2016-08-20 11.52.27

Okay, so the blinky effect doesn't translate well to the .jpg format. Just open and close your eyes once a second and you'll get the idea. It really did blink. I promise.

One thing that I did notice, and that did cause me problems, was that uploading code to the ESP-03 was extremely unreliable. I'd say that I got one successful upload every 5-10 attempts. I was using a genuine Adafruit FTDI cable but had problems nevertheless, as did Ean with his ESP-03 at the other end of the table. The dots on the Arduino UI would draw in fits and starts, and the blue LED on the ESP-03 would blink irregularly, and the progress indicator wouldn't get to 100%. Sometimes I'd get an error message in the Arduino UI, other times I'd get a success message despite and incomplete flash programming cycle. If I had to guess, I'd guess that numerous blocks were having to do retries and it was just hit-or-miss on whether or not the operation would finish. Thankfully, simply retrying enough times did the trick.

Now that I had an LED blinking, it was time to connect to the Wi-Fi network. Again, the Arduino libraries made it stupidly simple to do. I wrote quick code to simply connect to the network and display the board's IP address in the serial monitor. I was connected to Wi-Fi on my first attempt.

Next I had to add the ability to read the temperature from the DS18B20, and to send that to the web. I found Arduino libraries and sample code to read the DS18B20 rather easily, but sending the data to the web was more challenging. I didn't know where I wanted to write the data to.

Early in the project, I was hoping that I'd team up with someone who was good at web development, and I'd have him or her work on writing a web back-end to store the data on an R-Pi, and then write a front end to display the time series data in a browser. However, by this time I was on a team of three people, and the other 2 people were leaning toward working on a different project idea. Since I was pretty much by myself at this point, I decided to use an existing service rather than build my own. I had been to a demonstration of the AT&T M2X platform a few months earlier and managed to remember my username and password to the site, so I decided to pursue that route.

Wouldn't you know it, there's already an Arduino library to upload data to M2X. It was a fairly simple matter to set up a new M2X stream for my data, package my code, and get things up and running. For as much as I really hate the many layers of abstraction present in the Arduino ecosphere, it's hard to argue with the ease of use and success that I had this weekend. I flashed the code, rebooted the ESP-03, and within a few seconds a data point appeared on the graph in the browser on my laptop.

I think we all remember the way we felt the first time we managed to blink an LED with a microcontroller. For me, it was on a PIC chip 25+ years ago. For many makers today it happened with an Arduino. But no matter what platform you used or what toolchain compiled your code, blinking that first LED is always a major accomplishment. Folks, I have to tell ya: sending data to the web from an ESP8266 project feels the same way. It's just... it's magic that this $2 board, with free software and easy-to-use libraries, just works on my first attempt. The technology behind the whole thing... a single line of my code that connects to the network and obtains a DHCP lease,  a second line of code that does a DNS lookup and executes an HTTP request, reading a sensor, sending the data on an invisible carrier in the room to a Wireless Access Point, after which the data goes God-knows-where to a server on which I have an account, so that I can look at my laptop and see a red circle appear on a temperature graph, is simply amazing. It was successful, it was easy to do, and man was it exciting to experience. Every ten seconds I had another dot appear on the graph as my code made temperature measurements and uploaded the data. And yes, I spent several minutes just watching new dots appear. (And holding the temperature sensor in the exhaust air flow from my laptop to see the temperature change.)

So by about 2PM, I had the first part of my project prototyped and demonstratable. Here it is in my workshop after unpacking from the event:

2016-08-22 21.11.33

Flush with this success, I moved on to the next step: configuring a second ESP8266 to move a servo, which would simulate opening or closing the louvers on an air conditioning vent. On Friday night I had taken a few of my ESP-03 boards and had soldered some wires to them so that I could use them in a breadboard. I pulled one out and plugged it in and tried to flash it.

Nothing happened.

After a good amount of double- and triple-checking the wiring, swapping RX and TX pins, unplugging and replugging everything, my solder joints started to fail. So I tossed that one back into the box and took out the second ESP-03 I had prepared.

Same thing.

Rats. I had an idea, and a good plan for implementation but no hardware. I had bought the last ESP-03 from Jim, so a quick run to Tanner Electronics wasn't going to fix my problem. I had to resort to desperate measures: I begged.

I walked the floor of the hackathon, intruding into any number of teams that were heads-down working on their Super Cool Projects, to ask, "Does anyone have an ESP8266 board that I can borrow or buy?" I came across a nice fellow whose name I have already forgotten who took out a parts box and sifted through dozens of boards before picking one up and saying, "Here! You can have this one, this should work nicely for you." Despite my best efforts, he refused any payment.

Hackathons are really cool places where you can meet some really cool people. This total stranger just gave me some kit to work with. Granted, it's only $4 worth of kit, but still... the whole ethos of the event was just amazing.

The board he handed me was this one (full size SD card for scale):

2016-08-22 21.32.39_resized

From the top, it looks like any other ESP8266 variant. But it gets really interesting when you flip it over and see:

2016-08-22 21.30.37_resized

The thing has a micro USB port built in. That chip is a USB-to-serial converter. And there's a reset button on it. As it turns out, this is the WeMos D1 Mini. I hadn't heard of this gem before, and I still don't know a whole lot, but the inclusion of the USB/serial converter and circuitry that will automatically pull GPIO0 to ground and reset the board to put it into programming mode when the Arduino UI starts to upload is pretty darn cool. (I haven't yet tested the automatic upload wizardry. I didn't know about it at the time and manually jumpered GPIO0 to ground, but after returning from the hackathon I reviewed the schematic and the circuitry is there.) And these can be had on Aliexpress for no more than the cost of any other ESP variant. Even better, using a plain old USB cable to the D1 Mini, I was able to flash code faster and more reliably than using the FTDI cable on the ESP-03.

I grabbed a servo from my tackle box and a servo library in the Arduino 'verse, and wrote a simple demo program that swept the servo back and forth between its stops. My puny power supply was, not surprisingly, incapable of driving the servo. Ean lent me a 6V 2A power brick which I used to power the servo. I fed the signal line of the servo with 3.3V from the ESP8266, and by jumpering the grounds of the two power supplies together, had movement on the servo. My first attempt produced very inconsistent, sporadic movement. By limiting the range of the servo's travel I was able to get things settled down.

And this is where the wheels came off.

I'm not sure what happened, but I think I cooked the WeMos. It stopped driving the servo and stopped responding to the USB commands from the Arduino IDE. I can only guess that I crossed the streams and fed 6V from the power brick into the 3.3 volt input on the microcontroller. I didn't see any magic smoke escape, but the effect was identical.

And the Winner Is...

...going to be discussed in a later post. This post is already longer than I wanted it to be and it's past my bedtime. I'll continue my writeup tomorrow.