Category Archives: ESP-01

ESP8266 Lessons Learned

ESP-01The Trip: As regular readers may know, early in 2016 I worked in Spain on a contract with some great guys to analyse information from ESP8266 chips. Without going into any commercial detail, this is what I brought back from that trip as well as other lessons learned since then.

The scenario: The tests were done on a series of ESP-01 WIFI micro-controllers  in a rural environment, initially with a bank of 40 ESP-01 boards. These were powered by a single 20 amps 3v3 power supply. Yes, a switched supply. The boards were mounted on Vero-board and power applied. No linear regulator to smooth out the crap ( I would normally run 5v switched and a linear 3v3 regulator on-board for each device), lossy tracks on Veroboard, signals interfering with each other..  except it DOES get worse - read on.

The Place: The location we conducted our tests was off-grid, relying on solar power and a generator - and the weather most of the time was cloudy - that meant at regular intervals the remote generator kicked in and when it did a couple or so mains cycles were lost as the set-up there uses a combined inverter/charger. The result of that was that at regular intervals, the router reset.

boardsAside from actual power cuts you don't get much worse than this.  At first when we switched on the boards - which are running a modified version of my home control software which is in turn based on TUANPMs MQTT code with a boatload of stuff added and a lot of tweaking over time, only some of the boards would report back. A quick check of the router revealed that by default it only allocated enough room for 32 connections on DHCP. That was quickly doubled and lo and behold, all the boards logged in by MQTT to the PC (running Node-Red and MQTT and firing off data to a database).

Useful outcomes: Well, any thoughts I may have had concerning reliability completely vaporised this last 2 weeks as day after day our little bunch of 40 boards (not even all from the same supplier as some were blue, some were not) just sat there constantly delivering information. This was soon increased to  a wopping 120 boards without issues.

So if you're just starting up with ESP chips - bear the above in mind before jumping to conclusions about board reliability. The boards used in the test, running as I speak, were the early 512K versions, today I always use ESP-12 boards in my own projects as they have eight times the amount of FLASH which means OTA, big programs (up to 1MB of C code (that's a lot)) and in the case of the "F" version arguably better antennae.

I sometimes hear of people complaining that once programmed, some ESP boards go into a loop at power up - and I've recently had this happen to me TWICE. In each case I had extra bits and pieces attached and was running the board off the FTDI - again in each case, putting proper 5v onto the boards immediately resolved the "problem". FTDIs vary a lot in their output and voltage.  While it is tempting to use them to power the ESP (or indeed the micro-usb connector in some cases, straight off your PCs USB - the time will come when this causes trouble and now you know the answer.


32Mb ESP01 and Sonoff

Some time ago I passed comment in here about converting an ESP-01 to 32Mb  (or 4MB).  And here it is in the flesh – a 32Mb ESP-01 – and also – at last - Sonoff Upgrades.

Now, why would you want to do all of that? I would suggest only if you happen to have lots of ESP-01 units lying around – and I’ll bet quiet a lot of you do. As for the Sonoffs – well, put it this way, I just ordered another 10 chips!

CompareI stopped using the ESP-01 a while ago because the standard 4Mb (512K) of FLASH was simply no longer good enough. Richard of RBOOT fame set me using using his RBOOT program so I could easily flash my home control code (see Home Control 2016 and Blowing the Home Control 2016 Code). Partly because I keep adding new stuff and partly because of the size of the Espressif SDK, Although my code will still run in an ESP-01, it certainly won’t OTA (remote over the air programming).  And so my little ESP-01 boards have been sitting gathering cobwebs. The Sonoff mains controllers on the other hand are VERY useful but it annoys the hell out of my that my software is now too big for the limited FLASH in these units – at least, for doing OTA remote updating anyway. All of that, for me, is now history.

A few weeks ago I noticed the Flash chips available for very little money and thought “go on then, why not” despite never having thought of updating Sonoffs – well, today, weeks later, they arrived, all five of them. I mean, at £1.86 for 5, or 37p each – you have to give it a go.

I got my fine soldering iron out (who’s bit is so fine it looks like it will last all of a week) and opened up the package.

Compare[5]The first thing I noticed is that these chips are slightly wider than the one in my little ESP-01 – chips shown side by side in the photo above. To remove the originals, I took my tweezers, put the side of the bit along the side of the chip – and when the solder melted, just lifted the chip a little – then did the other side. Came off a treat.

ESP-01 on motherboardWhat to do about this width problem…,   I decided to hold the new chip and flatten the leads on either side (vertically) by merely pushing against my desk.  You’ll see in the photo on the right – which shows an un-adulterated chip (the upper, larger one), the lower right photo showing in the middle, the one who’s leads I flattened – and the original chip from the ESP-01, lying on it’s back.

Doing that added very little to the height but positioned the leads smack in the middle of the surface mount tracks. With a fine soldering bit and fine solder it really was a doddle to re-solder the new chip back onto the board. I’d say total time to remove the original and put the new chip on – something like a minute.

And here it is – the ESP-01 is shown here mounted on one of a little adaptor board to allow 5v operation and standard FTDI connector etc. As you can see in the picture, the FLASH chip is a tad higher than before – but only by 1mm, it works a TREAT, flashed first time and my test function shows it as a 32Mbit chip.

flashsize=Manuf ID= 239, Type ID= 64, Size=4194304

And on power cycle, works a treat. Ok, yes, only worth it if you fancy a soldering challenge and you happen to have a load of otherwise useless ESP-01 boards – but hey, that’s what hobbies are all about.

ESP Starting...
GPIO4 and 5 are outputs.
Current web programming pin: 2
GPIO13 is an indicator.
Software version 1.4.2

Use the {debug} command for more information.
Web page control enabled
Waiting for Access Point wififorus
Connected as 192:168:1:34
MQTT connecting
MQTT Broker connected
Device ID is modified
Item published
Time is 10:48:01 06/07/2016

sonoff upgraded to 32MbitJust to prove to myself this was not a fluke, I modified a second board -  worked a treat (well, programmed a treat but would not work then I noted I’d shorted pins 3 and 4 together – fixed that – immediately worked a treat). Yes, I’d say total conversion time around a minute or so. Of course now I don’t know what to call them – ESP-01+ maybe!!

Just earlier after I wrote the blog – and LOTS of people took an interest, I received a comment to ask if it was possible to upgrade the Sonoff.

Well, there’s only one way to find these things out – so back to the soldering iron and yes, not QUITE so easy to get the iron in there – but yes, I now have a working 32Mbit Sonoff – this changes a lot and THAT is why I’ve just ordered another 10 chips.

The Sonoff chip is the EXACT size of the new chips I bought so no bending of leads. Just a VERY careful soldering job – you HAVE to have a pointed fine tip to do this – your dad’s Antex bit will not do it – but – I would say maybe 5 minutes this time being careful not to melt the stand-up LED?  I will update my other Sonoff boards now but I’ll have to wait for more chips to arrive – whoever thought it would be this easy. See my original blog on the subject for programming.


Home Control 2017

Introduction (Latest update July 19, 2017)

HomeSick of reading about other people’s home control? Want to make your own? Got some electronics and software experience? You’re going to LOVE THIS! Rock-solid home control – low cost, DIY.

If you’ve read my early blogs you’ll know that Aidan Ruff and I have been working in home control since the late 20th century. Together, we ran an electronics R&D company for many years and one of our products was a home control system called APPCON.

Home Control 2017

Continue reading Home Control 2017


A little aside

40 ESP-01 Boards

Some testing of 40 ESP-01 processors – all sending MQTT data data back to a database, powered by a 20 amp power supply.

Just two more of the same to go.

Of interest to those struggling with ESP-01 – I normally have a 3v3 supply on board but this time they are just on their own – so I was using the 3v3 output of an FTDI to power them and I had to have the odd retry at programming – something that normally NEVER happens. All my leads are short and properly formed so I’m hazarding a guess while the USB is able to supply enough current (at 5v) the chip on the FTDI is SLIGHTLY under-powered when delivering 3v3 to the ESPs.   Next batch I’ll put a large cap across the power. Having said that out of 40 flashing attempts I think I only had to retry 4 of them.

All working a treat and looking distinctly spiffy as the 40 blue comms lights flash – sometimes in sequence, sometimes out of sequence.



EMW3265Erm, no, though you might think so by this headline..

Read the comments – the $5 ESP8266 – where?  $2 ESP8266 more like it – less, even -

There’s even a claim that this new single-source board (Seeed Studio) has MORE memory – well at least one variation of ESP12 has 4Mbytes – and the EMW… according to the ad, 512K.

And what about the all important Windows and Linux support libraries? Erm, no.

Another comment – Chinese documentation? Well I don’t know about you guys but I have  raft of English documentation that until recently came with the Espressif SDK and which is now maintained online.

And the last – Chinese – guess where SEEED are!

Cheap, reliable, effective, more compatible variations of ESP and more suppliers than you can shake a stick at – and we want to move for what reason?

But – if you like spending money – there’s this – even more expensive -


Automatic Router Selection for ESP8266

I wonder if anyone who has done this can help.  As most of you know, I program my ESP8266 devices in C.  I've been having some issues with weak signal recently and it would be really nice to have a list of acceptable access points and their passwords - and have the ESP, if it loses the signal, check the list (including identical SSIDs) and reconnect.

Has anyone done this already and if so would they care to share code?


ESP8266 Remote Access

Notice I titled that remote access as against remote programming – but that’s part of it.

Years ago, having gotten sick and tired of dismantling my home control Arduinos just to upgrade the code, I purchased a couple of small units from China which I’ve just thrown in the bin.   One had a USB plug on it and plugged into the PC, the other had an FTDI output on it. Both had those black 2.4Ghz antenna.

So the purpose of these units was to wirelessly replace an FTDI – or serial programmer, the idea being that instead of bringing the Arduino project back to wherever one programs the devices, you plugged the unit into the project and over the air programmed it.

At the time I was using Arduinos and those CHEAP £1.50 radio modules – the NRF24L01s, the worst radio boards in the world who’s range could be so bad you’d be lucky to get through one wall. I had high hopes for them with a great mesh network called RADIOHEAD, but ultimately their range and lack of ability to read signal strength doomed them.   However, as you can imagine they were dotted all over the house and I thought this little radio pair would solve the issue of programming them without ripping everything up.

It turns out the “radio FTDI” had the same problem – it was based on the NRF24L01.

Fast forward to September 2015. Here I am in Spain with a new setup of ESP-12 modules controlling lights, watering system and a lot more.  I’ve made some improvements to our “home control 2015” software in the ESPs and once again I find myself having to dismantle kit.

Now, I know that is it possible to program over the air – a few guys have tackled this successfully and indeed much of the code is built into the Espressif SDK. Right now my friend Aidan is working on adding this to our code but there are two issues, he’s not had luck up to now and secondly as our code comes to something like 300k you’re never going to be able to add this to the ESP-01 modules (we use ESP-01 sometimes, ESP-12 other times…)  as you need as much spare storage as you have code for OTA programming!

It was with that in mind that last night I dragged out the old FTDI boards to see if I could save myself the effort of dismantling the Pergola lighting system to update it.  Suffice it to say that I managed to get a few bytes programmed before that all came to an end despite several attempts. With around 25 WIFI units of one description or another dotted around the place, the old wireless FDTI (same frequency range) simply could not handle more than a few feet.


I figured it would not hurt to look around and see if someone has alternative wireless solutions – lots of time has passed since I bought that kit.

And so it was that I stumbled upon this. – as it happens it is quite new – essentially what we are looking at is a single unit (yes, that had me going for a while) which will hook into the WIFI system and act like an FTDI – given that you can fire the serial out of your PC over TCP to a port – port 23.   I grabbed the code (the stable 1.04 version) and very excitedly blew it into an ESP-01 unit I had lying around.

Really, nicely done web interface (with remnants of Martin Hanzarov’s code in there) and a really good write-up – indeed there may be enough info in there to help us implement our own FOTO (over the air) updates to our code.

But this has far wider implications – a virtual serial link would also let you monitor the serial line of a remote unit for debugging info – and our units do indeed put out lots of serial debugging info. It would also let you remote program and monitor un-wirelessly enabled Arduino projects.

So the first problem was – I had this unit sitting as on my network and I needed to blast info into port 23 to have it come out as 115K serial.  I have ECLIPSE sitting on the PC running my projects and there’s a line in the MAKE file that says “COM6”.  I have absolutely NO idea how to turn that into a TCP statement if indeed it can be done (FEEL FREE TO START TYPING IF YOU KNOW HOW).

So I turned to a 30 day trial of a PC program that promised to provide a “virtual com port” – and that it did. Serial/IP Redirector let me create a link to port 23 and ship raw data back and forth to COM22 (which doesn’t exist on my PC)- LO AND BEHOLD I set it running, put PUTTY on the PC talking to COM22 and with a real FTDI attached to the little ESP-01 board on real COM6 I set that running on a terminal –at 115K. Utterly flawless raw serial communications – rock solid.

I was getting excited by now. I took my ESP-01 board and cross-connected the serial to an ESP-12 test board. I held GPIO0 to ground and turned the power on, putting the ESP12 into programming mode.

I punched COM22 into the ECLIPSE project and hit the FLASH button on the project. Lights flashed on both units. With a scope attached  to the serial in on the ESP-12 I could see clean 115k data going into my project and… nowt, zilch, nothing.

I was up until the early hours ensuring the baud rate was ok and that my level conversion wasn’t getting in the way – you see all my projects use a resistive divider on the serial input of ESP boards so the whole lot will work just fine with 5v logic on the FTDI and elsewhere.  I wondered if hooking two of these units together with serial cross connected might prove too much but the scope says no – it says I’ve a perfectly reasonable serial signal going into the ESP-12 – but it’s not having it – no responding output whatsoever. Eclipse tries sending out data over and over and eventually gives up just as if there’s nothing connected.

So near and yet so far.

I got up this morning and the unit was still rock-solidly connected to the WIFI and typing a few characters provided perfect results at the other end – but I cannot program ESP units – yet.

Very exciting, yet very frustrating.

Perhaps coffee and a new start to the day will help. BUT I had to bring this to you as the article is really good, the software seems to WORK and there’s a super-bumper version with it’s own OTA updating in the works for larger targets like an ESP-12 (more FLASH) than the ESP-01.

I’m sure this is going to be a winner – just need to get it to work. After all, the ability to add remote programming to any FTDI-enabled project for what, a couple of quid.. well, you just can’t ignore it.

Meanwhile if anyone reading this firstly knows how to set COMX on Eclipse (on Windows) to TCP – do let me know – and if you really think you know what I’m doing wrong here and want to jump in before I figure it out – by all means – you have the keyboard…



I recently put out a question about the RAM in the ESP8266. In a typical compile, for me I might see…

Idx Name Size VMA LMA File off Algn
0 .data 00000894 3ffe8000 3ffe8000 000000e0 2**4
1 .rodata 0000275c 3ffe88a0 3ffe88a0 00000980 2**4
3 .bss 00009a80 3ffeb008 3ffeb008 000030e8 2**4
4 .text 00007786 40100000 40100000 000030e8 2**2
5 .irom0.text 0003ce04 40202010 40202010 0000a870 2**4

All very confusing.  So .irom0.text is FLASH – why they can’t just call it FLASH I’ll never understand. The rest are various kinds of RAM.

.data is used for “initialised” data, i.e. that which needs copying from FLASH on powerup. I’ve used 0x894 in the above example.

.rodata is used read only data – this is in ram (again I don’t understand, if it is read only why it’s not in flash – most likely for speed). I’ve used 0x275c.

.bss is used for variables which are not initiased. I’ve used 0x9a80.

.text is used for CODE that is not in FLASH – i.e. it is in FLASH on powerup – but gets copied to RAM for speed.  Sadly due to lack of RAM we usually end up using a directive to put code into FLASH to save space – but REALLY time critical code should be left in RAM. Of course it does get copied into RAM (cacheing) but that could mean execution times which are different first time around – not good for RGB LED lighting etc.

A fellow by the name of Don Kinzer replied and here’s what he had to say.. very useful.

“There are no individual limits for the sizes of .data, .rodata and .bss (but see caveat below). The ESP8266 has 80K of User Ram which is occupied by .data, .rodata, .bss, the stack and the heap. Basically, the space represented by (80K - sizeof(.data) - sizeof(.rodata) - sizeof(.bss)) is used by the heap growing from one end and the stack growing from the other end. If the heap and stack collide bad things will happen (probably an exception, eventually, and a reboot).

The caveat that I mentioned is that the .data and .rodata sections, along with the .text section (itself limited to 32K) must fit in the first 64K of Flash. The sizes of each of these sections is rounded up to an integral multiple of 4 bytes and an additional 8 bytes of overhead are added for each section plus an additional 8 bytes of overhead. Finally, space for the checksum is added (between 1 and 16 bytes) so that the overall size is an integral multiple of 16 bytes. The total of all that must be 64K or less. The image containing all of this data is often called app.v6.flash.bin but the name itself is not important.

As for the limit on the size of .irom0.text, that depends on 1) the size of your Flash chip (commonly 512K but can be 16MB or more), and 2) where you load it into Flash and 3) if you want OTA upgrade or not. For non-OTA upgrade, it is common to load the .irom0.text at 0x40000 but it can be loaded as low as 0x10000. Since the system parameter area exists at 16K from the end of the Flash chip, the size of .irom0.text is limited to sizeof(Flash) - 16K - loadAddress.

If you want to load the (non-OTA) .irom0.text at an address other than 0x40000 you'll need to modify the linker script accordingly.”


BASIC for ESP8266

Don’t get me wrong, we don’t yet have a fully working interpreter, but a link appeared on my ESP8266WIFI Facebook page thanks to Michael Molinari this morning and I thought I’d give it a whirl.

I grabbed the Windows loader (Windows 10 put up a SEVERE warning about this which I totally ignored), plugged an ESP-01 into my FTDI and blew in the interpreter, all of which took a couple of minutes and zero effort.

At first I didn’t know what to expect, I looked at the serial port – nothing.. then realised it outputs at 9600 baud, not my usual 115K…. I then started typing stuff into the serial – nothing – at which point I noted it already knew about my router – I can only assume that is because the WIFI passwords were already in the board, normally you’d have to use the board as an access point just to put in your WIFI details… anyway, I managed to bypass that.

I checked the examples on the page – hello world and a graphics example – which worked right out of the box!! Imagine that – simple BASIC commands putting out graphics on a web browser from a twopenny WIFI board all on it’s own!!

At this point, things went down a little. I tried editing the code (in the web browser!!) and it wasn’t having a SAVE – I noted on the serial that it had crashed… but then if you look at the dates this is all very new.

Seriously this has to be worth a few minutes of your time – assuming the project continues and these niggles go away, you just don’t get a quicker, simpler and cheaper way to get a web page with buttons into an embedded device – even if just to do some simple stuff. This is now ENTIRELY down to how much effort the author puts into this.

Go take a look! These images should enlarge on click/touch. Well impressed IF development comes quickly enough….

Basic Interpreter for ESP8266   Graphics on the ESP8266


RGB versus HSV

Image author SharkDIn implementing my own home control solution which you’ll find in this blog “home control 2015” the software has been and remains a work in progress – mainly because I keep finding bugs and adding new features.  I’m fairly confident that most of the bugs that have plagued me over the months are gone. For example NONE of my boards has failed in the last week – running constantly, turning things on and off, monitoring temperature and humidity, powering RGB LEDS…

And that brings me onto tonight’s subject.  You may have  noticed elsewhere that I’m getting fanatical about the Nextion displays because now at last I have the potential of a nice touch display for the wall to control things. You’ll also notice I’m realising their code is VERY early – but that’s another subject.

The first addition I made today to the home control system was to allow any of the ESP boards to send an MQTT message to any other board. Of course that is built into the MQTT library in the first place and there would not be a lot of use in having the Raspberry Pi brains send a message to one board to send a message to another.. but it occurred to me that an essential feature of a serial wall mounted display would be to control more than just the ESP8266 board that it is actually attached to!

So – in went a new command to send out an MQTT command from the serial input on the board so that the ESP board could pass the message on. That’s a little tougher than it sounds as I only had one string argument available in my line parser so I had to delve into that – however, it is now all done.

And that led me to thinking about how my wife Maureen would control the coloured lighting around the house, from the wall.

RGBObvious really, RGB sliders – you can make any colour or hue from RGB can’t you – any techy will tell you that for free.  Sadly the rest of the world does NOT know how to manipulate RGB. Any paper artist will tell you that the primary colours are red, yellow and blue! Not in my world they are not.

And so we have a problem – how to better enable any old user to play with colours – and hence I started reading and it is pretty clear that a better model is HSV, or hue, saturation and value - brilliance in other words – I looked up HSV on Google but the best I could find was Herpes Simples Virus. I’m going to continue to refer to brilliance as the word “value” means nothing to me in this context.  The problem with RGB is – let’s say you get a really nice pink. That’s fine at full brilliance but how would you keep that shade of pink as you turn down the brilliance… even for a techy that is not easy faced with 3 sliders.   With HSV it’s a snap.

And so I’ve been looking at code – I found some great Javascript code and in fact I now have that running on my little WEBSOCKETS project – but what about C to put into the home control project… I found this after much searching.  Excellent code and simple to implement – do I put that into the ESP C compiler? NOPE – it needed a couple of includes that screwed everything else up because of the FLOOR function… so then I found this…

int inline fasterfloor( const float x ) { return x < 0 ? (int) x == x ? (int) x : (int) x -1 : (int) x; }

That solved the floor function and I was up and running.   H values 0-359, saturation 0-255 and brilliance 0-255.

Thinking about a display, a simple colour wheel with touch points along the way, then 2 sliders… that’s it - full intuitive colour touch control.

Well, it was enlightening for me – I hope you found this useful.