Killer (ESP8266) Apps for the Weekend

Sometimes, while browsing GitHub for ESP8266-related projects, I come across a user’s page which just happens to “push all the right (ESP8266) buttons” for me.  One which I came across recently was from martin-ger and he has several projects which tickle my fancy.

Those three should keep you amused over the weekend and give you a sample of what Martin is capable of.  Definitely a page worth bookmarking!



Tinkering with the Sonoff TH (by Tinkerman)

Xose Pérez has a great blog ( with lots of hardware projects (as you’d expect from the title).  He’s also heavily into the ESP8266, so it comes as no surprise that he’s already got his hands on the latest offerings from ITead Studio, the Sonoff TH10 and TH16 high power switches.

Annotated board (bottom)Of course, it would be no fun at all if Xose just reviewed the units, but we can trust him to go a lot further than that.  In a recent article, he shows us round the interior of the units (highlighting the differences and the improvements between these new versions and the smaller original) and then demonstrates how to add i2c functionality to the existing sensor socket.  With his small modification, the Sonoff TH goes from being able to interface with either a DS18B20 (One-wire temperature sensor) or AMD2301 (DHT22 style humidity sensor) to being able to handle the whole gamut of i2c enabled input and output devices.

While we’re looking at Xose’s ESP8266 stuff, you might also like to check out his BitBucket repository.  You’ll find an alternative firmware version for the Sonoff series (named “Espurna”), which is probably where the code for the i2c mod will end up, as well as a WiFi manager library (named “JustWifi”), which features automatic AP connection based on signal strength.  There’s a ton of other, interesting stuff in there; some ESP-based and some not.  Definitely a treasure trove.



Headless Server Worth Having

I use Unix™-like systems everywhere (I’m not going to get into a religious argument about this …I’ve been using various sorts of Unix for dang-near 40 years now and I just never quite got the hang of the GUI paradigm, so call me an old fart if you like; the moniker fits quite well 🙂 ).  Recently I’ve replaced a few of the bigger, more power-hungry boxen around the house with ARM boards, which are inexpensive to buy and very cheap to run.  Some of the Linux offerings (Armbian, Debian, Ubuntu-core and the various siblings, family and friends) are doing an amazing job of keeping up with the ever-changing, disparate array of hardware coming out of the Middle Kingdom (and FreeBSD isn’t far behind), so using these tiny boards as headless servers is quite viable nowadays.

Recently I bought a Nano-Pi M1 (plus 3D printed case) from the FriendlyARM on-line shop, with the intention of pressing it into service as a 24×7 web-cam support machine and general anything-else-I-can-get-to-run-on-it server.  As an ESP8266 user, MQTT was one of the leading candidates in the “anything-else” category.  Well, the good news is that it’s really not that difficult to get a distribution to run on one of these $11 boards.  FriendlyARM do a lot better than some of the other manufacturers in making relatively up-to-date releases available from their web site and again, unlike some of the others, the choice of working distributions is actually greater than just one.

While I still haven’t got the web-cam up and running (anyone want to recommend a decent, cheap camera with reasonable resolution for landscape shots?), I have had a lot of fun playing about with this small board and trying out the various flavours of Linux available for it.

Having mentioned the Nano-Pi M1, I have to say that it is not the subject of this post, though.  While browsing my normal favourite collection of sites over breakfast this morning I came upon this little beauty (courtesy of CNX-Software …one of the better sites for cutting-edge info on embedded systems).Nano-Pi Neo board imageThis is the new, NanoPi NEO from FriendlyARM; the latest stable-mate to the NanoPi M1 (and for that reason, I have a quite reasonable expectation that this board will have good support from day-1 …and as my mouse hovers over the “Add to Cart” button, I hope that FriendlyARM won’t prove me wrong).

This tiny board (40mm x 40mm) has 100Mb ethernet, a USB-2 port (with two more ports available on header pins), a micro-USB socket for power and data, a Micro-SD card socket, a 36-pin header for GPIO (which includes I2C, UART, SPI and general I/O pins) all driven by a quad-core Cortex A7 running at 1.2GHz and 256MB of DDR3 RAM (512MB of RAM for an extra $2).

So how much is it?  $7.99 for the 256MB version.

Before I get screamed at, I need to qualify that price and tell you that the last time I bought anything  (the M1) from FriendlyARM, the postage was $10 (via DHL to most of the world,  so reasonably speedy), so you need to add that into your budget.  As far as I can see, there’s no case available yet (Update:- Just heard back from FriendlyARM that the case is in the works and should be available towards the end of this month …July 2016).

Update:-  It looks as though FriendlyARM have changed their shipping options.  When I went to “checkout” this time, the cheapest option was plain old “China Post”, with Fedex just a couple of dollars extra and the DHL/TNT option a few dollars more.

Update:- I mentioned in the original version of this post that it might be worth adding FriendlyARM’s $1 heat-sink to your order.  Better hold off on that for the time being.  The processor on the NEO is on the bottom of the board and we still have no  idea of what the case is going to look like.  Oops!

It’s going to be hard to beat this as an off-the-shelf, ethernet-connected, low power (as in watts used, not computing power) MQTT/DHCP/DNS server for your ESP8266 network.

Last word… for GUI-centric people, please do note that there is no video output connector on this board; it’s serial-console only.

Update (Aug 8th 2016):-  As of today, the printed case for the NEO is now  available for sale on the FriendlyArm site.  There’s also a fairly chunky heat-sink.  Both are priced at $2.99.  The pricing is a little bit of a downer, as together they bump up the total cost of the unit by a fairly hefty margin.  The other downer is the colour …do you really want a neon-pink case sitting anywhere around your house?


NanoPi NEO layout and specs



ITEAD Studio delivery

Well, I can confirm that, for Japan anyway, delivery from ITEAD Studio is much faster than the normal Middle Kingdom standard (wait, wait, wait some more, then wait).  I ordered some bits and pieces from them on Monday (which was the first normal work day for them after their new year’s holiday) and the parcel arrived on my doorstep here in deepest, darkest Nagano at lunchtime on Saturday.  I had to sit down and have another cup of tea.

I was pleasantly surprised by the fast delivery and also fairly happy with the contents of the parcel.  I’d ordered a few of their AC to DC isolated switching supplies based on the iW1700 chip, along with a “Sonoff” ESP8266-based WiFi mains switch module (the non-RF version …it doesn’t have the optional 433Mhz card or a key-fob remote control).  I expected the PSUs to be small and I wasn’t disappointed, but what did surprise me was how tiny the Sonoff unit was.

Small hand, smaller Sonoff
Sonoff is tiny!

I’ve got very small hands, by the way (and probably none to clean either, come to think of it), so just image that it’s about one third smaller than the impression you’re getting from the photo.  The screws in the mains connectors are too small for a general-usage small bladed screwdriver and need a smaller “precision” type.  The box which the Sonoff came in was actually smaller than the boxes for the (tiny) switching PSUs, which had me thinking that they’d mixed up my order quantities, until I opened them.

I haven’t used either the Sonoff or any of the PSUs yet, so this is very much just first impressions.  So first, here are the PSU photos (click on them for larger images):-

From the top you can see the switching transistor nestled between the transformer and the 400v electrolytic capacitors.  The pins closest to the camera are the output side, with the middle connection labelled as 3v3.  However, there is actually no pin in that position and, although there are pads for a regulator on the bottom of the board, it isn’t populated either.  It looks as though it would be fairly easy to add a regulator in there, but as there are no pads for capacitors, it would be just as easy to put the regulator and caps on the target PCB instead.

On the photograph of the bottom side you can clearly see the slot underneath the transformer between the primary and secondary side which also runs across almost the full width of the board, providing galvanic isolation between the mains input and 5v output.  The iW1700 is the six-pin chip you can see underneath the transformer,  but on the primary side of the isolating slot.  It gets current feedback from a sense resistor connected to the emitter of the switching transistor and voltage feedback from a separate primary-side winding on the transformer; there is no feedback path from the secondary.  The two larger resistors at the extreme right of the photo are marked “155” (that’s 15 + five zeros, or 1.5 megohms) and they’re wired in series to give a very high impedance “bootstrap” supply to the iW1700 (this one of the area where the ITEAD design differs from the reference design – the reference uses a smaller limiting resistor and a “normally on” depletion mode MOSFET connected to the “active start-up” pin of the iW1700, so that once the power supply has bootstrapped itself the power flowing through the bootstrap resistor can be turned off).  The big, square, four-pin block next to the input pins is the bridge rectifier.

This isn’t a particularly efficient supply for a switcher (running, according to the design sheet, at roughly 75 to 80%, depending upon the combination of input and output voltages), but it does have a remarkably low quiescent current under no-load conditions, so is pretty good for something like a phone charger where the load will suddenly drop off (at full charge), but where the unit itself may remain connected to the mains supply for long periods.  Similar conditions might be found when providing the supply to  an ESP8266 which operates normally for a while and then drops into sleep mode, so it’s no huge surprise to find that ITEAD use virtually the same circuit in their “Sonoff”, ESP8266-based WiFi mains switch.  Looking at the photos of the (shockingly naked) Sonoff we see some very familiar components (again, click for larger sized images):-

Looking at the bottom side of the board, you can see the square block of the bridge rectifier at the top, left-hand corner and then slightly below and to the left our familiar “155” resistors (labelled R16 and R17) with the 6-pin  iW1700 chip sitting over to the left and slightly higher, labelled as U12.  The right hand side of the board is almost entirely given over to the ESP8266 (note the antenna at the extreme top right) and the tinned bus bars connecting the output screw-down connector to the relay and input side.  The empty row of holes slightly to the right of centre bottom are where the 433Mhz RF module sits (in the more expensive remote control “RF” version).  Over on the photo of the top side of the board the same row of empty holes can be seen slightly right of centre closer to the top edge of the board.  Just below them is an unpopulated pad for a QFP chip, labelled as U5.  That’s for the 8051-based “Busy-Bee-1” chip, which appears to handle the control of the 433Mhz module on the “RF” version.

Further down at the bottom of the photo and further to the left of centre is the (yellow) transformer for the power supply and you can clearly see the switching transistor sitting just to the left of it.  The big black box with the white paper label is the relay which switches the output load.

Backing up just a little bit, you’ll note that I said I was “fairly” (not “ecstatically”) happy about the contents of the parcel and the photo of the bottom of the Sonoff board shows why.  If you compare the photo of the PSU board and the PSU section of the Sonoff board you’ll notice a couple of things.  First, the PSU PCB has an isolating slot between the primary and secondary sides of the transformer, while the Sonoff doesn’t.  Second, the iW1700 chip is under the transformer, but on the primary side of the slot on the PSU PCB and, while it’s in the same approximate place on the Sonoff, it has been rotated 90° so that the tracks from the pins now come out towards the secondary pins.  Mmmm, not so good.

Don’t get me wrong.  This is still an isolated supply (the transformer and the winding on the relay both provide isolation to the ESP8266 circuitry), but I don’t believe that the “Sonoff” would pass regulatory inspection in the U.S. or in Europe (the fact that it has screw-down terminals instead of a molded-in power outlet probably makes the PSU issue a moot point, anyway).

Would I use the Sonoff myself?  Heck yes!  I’ll probably buy some more of them, too.  I’ve built much worse things myself (think full-wave rectified 240-volt mains with thyristors on stripboard and run away, screaming), although admittedly, I didn’t sell them as products.  The Sonoff will enable people with minimal knowledge or experience to put together an IoT set-up relatively safely (without having to resort to the horrible mix of stripboard and mains) and, whatever its faults, it is orders of magnitude better than any of the duct-tape-and-hot-glue IoT instructables out there.  Going back to my initial impression, it’s also small.  There are lots of places where a Sonoff would fit in unobtrusively (behind your TV, in an equipment cabinet) where it would save the trouble of needing to be physically there to simply power-cycle some errant piece of electronics.  It looks like a winner to me and that’s even before you factor in the ability of most ESP-aware folks (that’s you) of being able to reprogram the on-board chip to talk MQTT.

Update – See the newer post “No-Phone Sonoff stuff” for more information on loading an MQTT capable package onto the Sonoff.