Monday, March 28, 2016

Over The Air (OTA) esp8266 setup

Why OTA?

  1. it's faster than updating a sketch via USB/ftdi
  2. lets you update code when the module + sensor is wedged where the sun don't shine.
    1. under a dishwasher
    2. behind a fridge
    3. in an attic
    4. in a crawlspace
    5. up a tree
    6. surrounded by man eating racoons bent on world domination 


There's a *bunch* of info out there on getting over the air programming to work with an esp8266.  Much of it describes processes that are more difficult than necessary because...well, it's moved very, very fast.  As of the June 2015 timeframe, it still required quite a bit of handstanding on your head while juggling watermelons to work right.  We are lucky that an awful lot of the difficult bits are solved now.


After a bunch of futzing around, finally got the right combination of libraries, etc.

To wit:


  1. update to the latest arduino IDE (very important) - 1.6.8 as of this post
  2. use Examples=>ArduinoOTA=>BasicOTA as your base sketch
  3. Set the board to "generic esp8266 module" ... even if you're using something like the Adafruit Huzzah ... which I was.
  4. update the sketch with your wifi ssid and pw
  5. upload via normal USB/Serial method


Follow the rest of the steps here:
https://esp8266.github.io/Arduino/versions/2.0.0/doc/ota_updates/ota_updates.html

*POOF* magic happens.

You're welcome.

Saturday, March 26, 2016

Soldering irons and FTDI and bare modules (oh my!)

[question]
In my experience, Apple's default push notifications are fairly good about delivering things promptly and reliably, and email will be even better. I'm not terribly concerned about the reporting thing, I'm fairly comfortable writing dashboards and services for these. I do want to have it centralized so that I can get a notification if/when one of these looses power and stops pinging (or gets suddenly inundated with water or something). I can probably run that off a Pi or EC2 or whatever.

I'm planning to get two or three to start out with. We already have a soldering iron somewhere, so I think the only upfront things I need are the FTDI cable and a bunch of solder. After that, I think I can build these for less than $15/unit. If I'm doing them in bulk and get a little comfortable with soldering, I can shave a few dollars off that by getting https://www.adafruit.com/products/2491 instead of the breakout.



[answer]
Stick with the adafruit or sparkfun ftdi module.  While there are cheap $2 usb-to-serial converters out there, don't be too tempted.  Some use an "unlicensed" ftdi chip (which will give you no end of headaches with drivers...or worse).  Others are based on a different usb-to-serial chipset (CP-2102) that seems to work ok with windows, but is a royal PITA to use with a mac.  (I eventually did some sort of magic to get them to work on my mac ... but the 10.10-10.11 upgrade broke it)  Short answer: stick with the $20 genuine ftdi adapters from adafruit/sparkfun.  I've got experience with *all* the above problems.  And you know what they say ... "Good judgement comes from experience.  Experience comes from bad judgement."

Here's the thing with the bare esp-12E module from adafruit ... you'll still need to create your own method (board of some sort) to do the initial software load, *and* you'll need a minimal VRM to provide a clean 3.3v power source.   I originally intended to do just that with a small custom board, then I ran across these: http://www.electrodragon.com/product/esp8266-smd-adapter-board/  Even sourcing all the parts in bulk, I'm not sure I could build a board cheaper.  You get an easily soldered to/breadboarded breakout board *with* a vrm *and* the esp-12f already attached, all for $3.80!

You'll still need to do the initial flash with an ftdi module (they've got a picture of it hooked up on the page), but if you flash it with OTA (Over The Air) arduino code the first time, you can do subsequently loads via wifi*.   This, of course, also means you can update code easily when the thing is wedged *under* the dishwasher.  Or in the crawlspace.  Or behind the fridge.  :-)  Since you're already ordering from electrodragon for the water sensors, the additional shipping should be negligible.

I just ordered a handful of the above modules to experiment with.  If you're curious, I'll let you know the quality when they get here. (in...admittedly...about 2-3 weeks)

Re: soldering ... the adafruit iron will work fine...I've never seen them sell something they wouldn't use themselves.  A good iron makes soldering 10x easier.  If you can swing it, something like this ($40) http://www.amazon.com/Weller-WLC100-40-Watt-Soldering-Station/dp/B000AS28UC/ is even better and will last you until you're at *least* as old-n-busted as I am, if not longer.  ;-D

I've noodled the "how to know if the sensor has died" issue as well.  With the blynk app, when you add the notify widget there is a switch that says "notify is esp is down".  Which probably only works if the app is running on the individual phone.  It would be easy enough to write a service that runs on your home pc and regularly pings each of the registered sensor nodes.  Anything that doesn't respond over X amount of time triggers an email/sms alert.  Since you're using an a/c adapter, you won't necessarily need this now, but the esp8266 also has a built in incoming voltage monitoring function that makes it easy to keep tabs on battery charge levels.  See here: https://github.com/adafruit/ESP8266-Arduino and scroll down to/search for "ESP.getVCC()"

Ok ~ now get back to work!

*OTA info in a subsequent post ... stay tuned

Friday, March 25, 2016

3.3v (or: how to not fry your esp8266)

[question]
That all sounds great, makes a lot of sense. One more question - http://www.electrodragon.com/product/water-drop-rain-sensor/ says that it uses 5v, but the HUZZAH doesn't have a 5v pin and all the GPIO pins come with dire warnings on https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/pinouts about them not being 5v "compatible". I take this to mean something will melt, explode, or otherwise make me unhappy.

What happens if I just throw 3.3v at the water sensor board? Will give me 3.3v back, or will it not work or explode or something?

[answer]
Ok, took me a bit but I just checked the demo board I made, and I connected the water sensor to the +3v for it's vcc, and it works fine.  Some sensors (eg: the ultrasonic one I demoed) do require a 5v vcc* to work correctly.  Many, however, work fine on 3.3v.  Sometimes the sensor will outright state "5v only" or "3.3v only" or (in some cases) "3.3v and 5v".  Some will state "TTL Logic" <-- this almost always means: "will work with logic levels from 2.7v to 5v for the "on" state"

Yes, 5v isn't good for a microcontroller that uses a 3.3v logic signal to indicate a "high" (ON, or 1) state.  Thinking of voltage as pressure in a hose (a useful, if not entirely accurate, analogy).  A valve that's rated for 3.3v psi might burst/fail/leak if you hit it with 5psi.  Bit of a stretch for the real world, but you get the idea...tiny circuits that are spec'ed to deal with 3.3v may burn up @ 5v.

Using the above ultrasonic sensor, for example, I had to feed the sensor 5v for it to work right, but the signal pin also put 5v out.  That would have very likely damaged the input on the esp8266.  I wound up using a voltage divider to bring the 5v down to 3.3v.   (voltage divider quick tutorial: https://www.modmypi.com/blog/hc-sr04-ultrasonic-range-sensor-on-the-raspberry-pi )

Here's a bit of irony for you...my in-laws came by last night to borrow a pair of fans from us ... to dry out their garage floor ... where the water heater had been leaking.  I described the demo'ed water sensor and they immediately asked where they could buy one ...

OH...and before I forget...for *this* particular application, I'd recommend adding the email widget to your app and a call to Blynk.email in your arduino code.  (http://docs.blynk.cc/#widgets-notifications-email)  So instead of only having it notify an application (that may or may not be running) on your phone, you should wind up with a text message that will be sure to pop up and be noticed.

We do this by sending the email message to your cell carrier's "email to text" gateway. (list: http://www.digitaltrends.com/mobile/how-to-send-e-mail-to-sms-text)

Heck, have the huzzah send the email to *several* people just to be sure!

Cheers!

(*vcc == "this is where the positive supply voltage gets connected")

ESP8266 - powering it via AC

"In the beginning"

Been meaning to do this for a while now.  As in "for the last 10 years or so".  Anyway.   As I shot emails back and forth with a young man getting started in his making/tinkering journey it occured to me that:
1.) someone else might benefit from the knowledge
2.) the above is pretty well a self-serving bit of preening on my part
3.) the real reason is to give myself an easily accessible log for things I've learned and subsequently forgotten

With that bit of confession out of the way...let's go!

We were talking about how to get started with the ESP8266 modules.  A wonderful little doohickey, complete arduino microcontroller WITH wifi on a single (cheap!!) module.  I'd done a presentation at Boise Code Camp on getting started with the things (https://github.com/adbacker/bcc2016 for code and notes) that started the whole thing off ....



RE: getting the things powered by a/c for long term sensoring...

*****************
[question]
I'm looking at getting a bunch of those HUZZAH's from Adafruit. How did you power them? I'm probably an idiot, but I'm not seeing a good way to hook it up to wall (120v) power. All the examples I'm seeing have it powered through the console cable... which is all well and good until you want it to be not hooked up to a computer.

Do you know of any pointers to doing this?


[reply]
To power it via household current, you'll need an ac/dc converter.  (aka ac adapter, ac converter, etc)

I've used ac adapters from old cell phone chargers and other dead electronic devices with good success.  Anything from 5v to 12v will do. (the voltage should be printed on it somewhere).   You know what I'm talking about ~ they look something like this: https://www.ebay.com/ulk/itm/151620955695

If you don't have a 20 year collection to pull from (as I do), thrift stores are great sources for minimal $.

The Huzzah has an onboard VRM (voltage regulator module) that'll step the wall wart's DC to the 3.3v it needs.  But it'll only handle a max of 12v to step down, so keep that in mind.

You could cut/solder the ends of the ac adapter directly to the huzzah(make sure you get pos/neg right!), but I'd recommend soldering something like this, and then plugging your ac adapter into it. https://www.ebay.com/ulk/itm/262198002613

Note that the female connectors above are for a 2.1mm plug ... this size is pretty common to 12v ac/dc adapters, so make sure your adapter plugs match!

According to the huzzah docs, they recommend soldering the battery connector with the positive to +vbatt and negative to ground.  Those would be where you would want to connect your power.

You probably already have, but if not be sure to read through the adafruit learning tutorials ... good stuff in there.

https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/pinouts

Let me know if you hit any more bumps.