Saturday, February 27, 2016

First IoT Gizmo: Enhanced

I know what you're probably thinking after reading this post title: "How could it possibly get any better?"

I agree.  It's a thing of beauty already, but some parts showed up recently including a 128x64 .96" OLED.  I thought it would be a better value add to visually display the current temperature (and some other data) on the OLED display.

Getting this thing to work with the ESP8266 proved to be a bit of a challenge.

First off, the device's documentation is mostly nonexistent.  Before you can get anywhere with an I2C slave device, you need to know its address.  After using the addresses on the back of the PCB with no success (and some beating my head on the wall), I did some outside the box thinking and found this little gem.  It scans the I2C bus and looks for slaves on every possible address.

After determining that the correct address was 0x3c, I started hunting for a library that let me use this thing without implementing low level code.  Several Arduino libraries for 128x64 OLEDs were available, but they only sort-of worked.  The Adafruit library ran for a little while but it would always crash and cause the ESP8266 to reboot.  Eventually I found this library, which is specifically written for the ESP8266.  The only minor issue was that the code didn't compile, but it was minor so I fixed it, submitted a patch on github, and moved on.

The code I've got so far is worthy of calling a "proof of concept".  It works, but it usually crashes.  I'm 99.9% confident that it's the excessive use of delay(...) calls, causing starvation to things like the WiFi stack.  Before I deploy this thing in practice, I'll probably try running it using a cyclic executive.  This is a perfect use case for timers, but I've not found readily available documentation on the ESP8266 timers.  This is part of the down side of using the Arduino framework on this thing - you have no idea what's actually running under the hood.  More research may be in order here...

Here are some photos of the "proof of concept":





Also, I wanted to get this thing off of my ESP8266 programming board + breadboard, so I whipped up a protoboard version.  Side note: I'm feeling much more confident in my soldering and board layout having made just a small number of these things.  If you haven't moved past breadboards, I would strongly recommend soldering up some permanent boards.  Visuals:




If anyone is interested, here's a schematic of the board.  Note that RST and CH_PD pins on the ESP8266 need to be pulled high in order for it to run.


Saturday, February 20, 2016

First IoT Gizmo

I made my first internet-connected sensor.  I suppose this makes me an Internet of Things expert, right?

While I'm no expert, I did learn a lot along the way.  One of the biggest learnings was how stupid-easy it was to set up a place to dump my data.  I used data.sparkfun.com to publish data "stream".  This freely available platform is based on phant, which appears to be developed by Sparkfun.  Sign up was fast, easy, and didn't even require me to give away all my personal information!

Here's what their UI looks like:

A handy button labeled "Export to Analog.io" produces an ultra-schnazzy chart:


There is a phant library accessible in the Arduino IDE library manager.  I looked into this briefly but determined it to be of little use in the case of ESP8266.  The library looks to be focused on constructing the message payload that you could just send out over TCP port 80, which makes sense if you're running on an Arduino and may have different TCP/IP stack implementations depending on what adaptation gizmo (e.g., ethernet shield, WiFi shield, etc...) you're using to connect it to a network.

Since the ESP8266 features a full TCP/IP stack out of the box and the libraries include a HTTP client, it was easier just to use that.  I was in a rush to see it working, so created data with a GET request.  As a professional software engineer who works in RESTful services, this made me die a little bit on the inside.  I have to keep reminding myself that this is a hobby, and that it's OK to lower my coding standards back down to the undergrad-level of "get it to work."

The gizmo itself consists of an ESP8266 and a 18B20 one-wire temperature sensor.  The 18B20 is much more expensive than the pile of LM35 sensors I had laying around.  Since the ESP8266 has no onboard ADC (well, no ADC that you can use on a GPIO pin), one is forced to use a digital sensor.

This was my first attempt at one-wire interface.  One-wire is a bit of a misnomer because you also need a ground (which in my case was a wire), thereby increasing your wire count to two.  Since the circuitry for parasitic power wasn't work it for me, my wire count was again incremented putting us at three.  Long story short, it worked out just fine.

Here's the gizmo:



Thursday, February 18, 2016

ESP8266 Programming

The ESP8266 is an amazing little unit.  I've had some ESP8266-01 boards on hand for some time now, but haven't had an opportunity to start fiddling with them until recently.  My interest in this board was originally for use as a WiFi enabler for another microcontroller (an AVR), but this article caused me to rethink things.  With a little effort, the ESP8266 can be reflashed to both act as a WiFi device as well as run your logic.

I started out using the hackaday article to build a programmer.  It was a vile, ugly thing.  I didn't go to school for electrical engineering, and it probably shows through in this thing:


It probably goes without saying that this rat's nest of wires didn't work well, so I built a different rat's nest:


The truth of the matter is that the first one didn't work well because I was powering the ESP8266 through my USB-TTL-Serial device.  This device had a convenient 3.3V pin, but it put out nowhere near the current required by the module when it starts talking WiFi.  So, I added a 3.3V power regulator, capable of 800mA, along with a 330uF capacitor to the circuit.  This yielded repeatable results -- much more satisfying than intermittent results.

My third programmer revision was inspired from an article I found when searching for ESP8266 stuff.  This board works reliably and I had the forethought to include headers to supply easy access to GND, GPIO0, and GPIO2.




It wasn't long before I realized that my brilliant forethought to add headers for GND, GPIO0, and GPIO2 forgot to include a pin for VCC.  Thus, it was no longer brilliant and needed an amendment.  Since I was making changes, I added some other improvements to include fancy button label stickers and a stress relief for the wires going to the barrel jack.  Eventually I'll get a female barrel jack that I can solder to the protoboard directly, but this will work for now.  Revised:




For programming the device, I opted to go for the Arduino software with the ESP8266 plugin.  The lack of intellisense and some other professional IDE software features are a bit of a turn off, but it is a free and easy to use option for the time being.  Well, easy to use from a toolchain and device flashing perspective -- not so much coding.


Friday, February 12, 2016

Temperature and Humidity Logger

I was past due for a project.  I had a technical itch that needed to be scratched.

Note the past tense. :-)

Enter the amazing Temperature and Humidity Logger 5000!  The genesis of this project idea stems from my fiance's lasik eye surgery last summer.  With the dry humidity conditions over the winter, she was experiencing painfully itchy eyes.  I got her a humidifier for the bedroom, and I'm curious how effectively it's working.

The project is to log data over time and analyze the humidity and temperature readings.  Who doesn't love some data to analyze?

The parts include:

The general logic is:
  1. read temperature, humidity, heat index
  2. read date and time
  3. append results from #1 and #2 to a file on the SD card
  4. repeat about once a minute
I prototyped everything up using a breadboard and an Arduino Uno clone.  It looked like this:



Once I got this up and running with some [quite frankly hacked together] code [that I'm not the proudest of but this needn't be perfect], I moved forward with making it a little more permanent on a protoboard.  I also downsized to an Arduino Nano clone.  These documents helped to plot out the pin mappings between the Uno and the Nano.

I learned that soldering and physical prototyping are "development areas" for me.  Nonetheless, it came together and it worked.  Here's how it looks:






After a short stint in the upstairs bathroom, I couldn't resist pulling the card and plotting the data.  For those of us who love charts, here's a little eye candy: