ESP8266 Options

Firstly let me say this is not intended to be authoritative, so please don’t come back to say I have it all wrong… these are just my views for now – they may change as things develop.

tmp962BYou may have noticed I’ve been taking an active interest (there’s an understatement) in the development of firmware for the ESP8266-type WIFI boards. Why? Well I see this little board as a saviour on two fronts:

1. As a low-cost stand-alone unit – using either C or a higher level language to make the ultimate in low cost controllers.

2. As a means to accessing the Internet for Arduino and other microcontroller systems at low cost.

Up until now, the lowest-cost means of scattering devices around an area included the likes of the NRF24L01 radio modules, at around £1 each you don’t get much cheaper, but they have very limited range. This can be mitigated somewhat by networking software and in my own homes and elsewhere I am using a network of Arduino-type devices to control and monitor heating and lighting. It works – but the hoops you have to go through to get range make it not a lot of fun. Low cost alternatives include RS485. Again at around £1 from China you can get RS485 interface boards and these are fine – but you have to wire everything together.

In my case the whole thing is held together by a master board using hardwired Ethernet to talk to the outside world. All well and good but for all the wires and intermediate wireless points to boost the range.

And then along comes the possibility to use WIFI. I have simply dismissed the alternatives available at £10+ as the cost per point starts to become excessive – especially for anyone doing this as a hobby.

A few weeks ago, the ESP-01 and similar boards appeared out of the woodwork, a dirt cheap Chinese WIFI board around the size of the NRF24L01. At first I started to think of them as a  simple cost-saving replacement for my own main Ethernet card and so I was very interested in the AT version released by Espressif. To explain: The little board uses serial control to talk to a host microcontroller such as an Arduino. I have spent every spare minute on this as we’ve gone from a board being released with almost useless firmware, to the point where today we have maybe 3 viable options for taking this forward and I’ll go into that in a moment.

tmp2ED3The hardware: The ESP-01 is probably the most popular design and sadly it is not ideal. The tiny board has an 89-pin header and it’s sole saving grace is that it is CHEAP – just over £2 at best. It has a PCB antenna which works but doesn’t give the best range but it’s save to say that if you have routers offering a strong signal throughout the building, this board will work for you.  As a unit designed to work with, say an Arduino, it is perfect.  As a stand-alone board it is useless as you only have simple access to one pin! The problem there is that with 2 pins you can implement, say, I2c which opens a whole world of peripherals. With 1 pin –  well, you can flash a light or read a temperature sensor.

There are others, the ESP-03 design brings out the pins to the edge of the board. In both cases these boards use 3v3 – which is fine unless you consider that many controllers and many peripherals run on 5v and those microcontroller boards which offer 3v3 do so with insufficient current to safely power these boards which can use up to 250ma (tiny 3v3 regulators often supply only 100ma).

In my experience, while powering the boards with 3v3 you can feed the output directly to, say a 5v Arduino but you need at a minimum a resistive divider to the inputs – that is the serial input – and the reset (and you really do need to be able to access the reset).  There is even a board out there which I won’t discuss which has access to power and serial only – that is dead in the water for me.

What I would LIKE to see is a 5v compatible board with internal aerial, the pins available on 0.1” centres and an optional aerial socket for external aerial. Do I want this? YES, do I want to pay over £3 for it? NO. Therein lies the issue. Only the Chinese can make that happen at the price.

What absolutely is needed is a minor change to ESP-01 to bring out at least one more port wire. The magic phrase… “I2C”.

The software: This has been an absolute minefield and I would say it is only in the last 2 days that I’ve come to the conclusion that we have a real winner of a board here. There are to my mind 4 routes to potential success available to us, depending on our requirements…

1. The original Espressif software. To call this awful up to now would be generous.. Using the existing software is a nightmare as it has bugs – several trivial and one major. The “busy…s” problem is firmly embedded in my brain as a timeout which won’t go away and as for some of the error messages, “no is fun” comes to mind.  However as of yesterday, an as-yet unavailable version seems to have tamed but not eliminated the first problem.

I have an Android App for my mobile phone which controls 4 outputs on an Arduino which is using the ESP-01 board. Until yesterday I could not keep it running for more than a few minutes without the dreaded lockup. The busy issue still appears but is now an inconvenience. My App has not fallen over in 20 hours (to keep this in perspective, my Ethernet-based home controllers have stayed up for well over 1100 hours without a hitch). I am relatively confident that if Espressif continue to develop this we will have source code access to working software within days or weeks.

2. Frankenstein. There is one complete re-write of the software, no longer using AT commands which, until the designer got the flu last week was starting to look promising. Badly documented to date this is a potential alternative to the Espressif software.

3. There is, floating around, an implementation of a standalone web server designed to initially turn a LED (or whatever) on and off from the ESP-01 etc. using the board itself with no external support. This can act as a router for setup and via a web page can be set to use your router. Another fellow has developed this to read temperature and you can see the possibilities here… but right now, it is NOT a practical solution as there is a bug in the setup software which means the part where it runs stand alone and gives you a list of available routers… doesn’t actually work. You end up having to FLASH the original Espressif software to setup the router – then re-flash this software …. erm, no thanks.

I do have promises this will be fixed and if and when that happens, I think this has a niche all of it’s own – not in it’s original form but with custom software to make better use of I/O.

4. Finally, one great hope is a development that puts a LUA-based interpreter inside the ESP-01 etc. and allows for a stand-alone unit needing no other hardware. See my notes however about I2C and the need for another pin. So – WHAT ON EARTH is LUA? I’d never heard of it until last week when the first implementation came out – which didn’t work properly. I am about to test the update completed only hours ago and a colleague of mine is already onto it and getting excited. Essentially LUA is a high level language interpreter. You can send commands, functions and even complete  programs and data to the ESP-01 serially and have them run on the board with nothing else but power attached.

There is even a start up function you can send which will ensure the board acts sensibly on power up. If you are familiar with C and Java etc you’ll find LUA reasonably straight forward but you might want to get something printed out. The ZIP file for this software contains a lot of info and if you look up LUA on Google you’ll find a complete reference website – concentrate on the features of version 5.1, not 5.0 or 5.2 (as far as I can tell). 

Today I intend to give this last option a good hammering – one of the features CLAIMED to work with e LUA version is I2C. Now, how you do that with 1 wire I don’t know, I suspect on the ESP-01 it’s going to involve micro-surgery but we’re still trying to work this out. But think about it – even if it’s slow (as interpreters tend to be) if it will act as a web client and web server that’s half the battle (reading time servers etc., remote access) and the ability to handle I2C means the little board on it’s own, with no compiling from your perspective, can talk to a myriad of devices including port extenders, clocks, LED drivers – there are thousands of devices out there that talk I2C ( for the uninitiated, a 2-wire bus where devices have addresses and can talk both directions). Remember that this is not an Arduino – it’s a powerful little Microprocessor with a reasonable amount of room – the possibilities are huge.

We have cheap WIFI devices, we have at least one company working on a prototyping board for them, we have many suppliers ensuring we should have reliable access to the devices…what we need is for at least one of the above options to mature to the point where we can rely on them to do whatever it is we want them to do. I could see, best case, these things being a fantastic, low-cost alternative to radio networks for so many applications around the home and office. Sadly the current devices use a lot of power which makes solar operation “challenging” – but that’s just for now – you never know what might happen tomorrow. What would really be nice would be a cheap supply of the actual chips so those of us with PCB abilities could make our own versions.

Everything I describe above, has links in my previous blog items in here. I am so lucky as a man who spends his life going from meeting to meeting around Britain and Europe that at this very time I’ve a short lull in said meetings which means I can spend a little time indulging in this challenging but exciting development. I don’t normally get the time to do this so please, take advantage, do look in over the next couple of days to see what’s new – it’s changing by the hour.

ESP8266 Current State of Affairs

As the weekend begins, here’s where we are as far as I can tell with the ESP8266 WIFI board. The LUA-based software I refer to elsewhere is showing promise. I could not get the web client to work (first thing I tried) but I’ll try again this weekend. I have questions.. Why only 9600 baud, how much space is available for programs in there, how much space for variables?  I’d be happy to put a board together to expose the remaining pins on a 0.1” header if I thought this was viable.  Then there is the “Frankenstein” firmware also referred to in another blog item here. I get all manner of strange control characters appearing when I use that (as well as valid data) and I can’t get it to connect to my routers. I’ve commented twice but the author either isn’t getting my comments or figures I’m too thick to respond to. And then there is the original v9.2.2 software from the designers. That is the ONLY software to date that to my knowledge actually works, BARRING the “busy…s” problem, which may or may not be less prevalent at really high speeds but really does need fixing – and of course, “Chinglish” messages like “no is fun” etc.

So with the original software I can make a simple on-off light app but I would not want to rely on it – using a simple TCP socket. With the other two sets of firmware I’m not yet able to make a decent application. It’s so frustrating as the little boards have so much potential (not to mention any boards we may make ourselves). I have a Windows-based compile setup but the last part of it will not work – I finally figured out that you have to set the path THEN open a DOSBOX… and so now my computer knows about the ESPTOOL but..

Before I twigged..


And now..


I’m hoping the weekend brings more improvements and will report back if I spot any. Meanwhile if anyone has any idea what’s wrong with the above image… do let me know.

Digistump Cricket Generator

A little toy for Digistump fans – a cricket generator.

What is a Digistump? It’s just a little Arduino – i.e. An Atmel-based board. Any similar board will do – maybe changing the pins – a UNO for example…  the Digistump uses the little 8 pin ’85 chip. On a larger board such as a UNO you could use D13 and D12 outputs for example – the pins are defined at the top of the software.

Recently for a bit of fun we sat down and made a cricket generator.  A couple of things are important – this needs to sound like an insect and not as most do, sound like an electronic buzzer. We did find one excellent generator on YouTube – but I think it was a con as the guy’s code simply bore no resemblance to the output – so we made our own.

The second thing that is important is power as presumably one would like this to run off solar or maybe charge off solar.The Narcoleptic library lets you have delays in which the processor is off – down to a few micro-amps. So we used that – BUT the settings in the library would not allow the use of the Digistump – threw up an error – so in the Narcoleptic.cpp file – simply change WDTSCR to WDTCR – 3 occurrences  OR make the change in a more sophisticated way as here

Here’s the library:

The Narcoleptic stuff above is ONLY to save power… you could just use DELAY if you wanted and forget the library.

So in this case – you need a piezo element (not a speaker – can’t handle the high frequency) across outputs P0 and P1 and I suggest once you’re happy  – snipping off the two surface mount LEDS as they use juice!

The cricket generator has variations as you’ll see in the first lot of code below – feel free to experiment – this will work on an Arduino without the mods mentioned above…. on other digital outputs of course… but the nice thing about the Digistump is that it’s cheap. Another way is just to program the ATTINY85 on it’s own – internal Xtal and fasten straight to a solar cell/battery arrangement capable of 3-5v output – an extension might be – read the voltage when set to internal reference by a VERY high value pair of resistors, measure the voltage of the solar cell (occasionally while sleeping the rest of the time) – if the cell is dead (ie nighttime) start chirping!.


The above was our first attempt….. then out of interest, I actually sat down and listened to a real recorded sample from one of the insects… firstly the main frequencies are around 5Khz, so that’s 200us. Usually around 125 of those followed by a 25ms break.. in groups of 5….  then there are maybe 3-4 of those bursts with something like 200ms between them- then a gap – anything from 2 seconds upwards.

I noted also that in each single burst of the high frequency, the level increases then drops off achieving soft edges to the waveform– I achieved that with PWM.  The actual frequency over each burst also increases slightly – I used the loop variable to add a decrementing delay while forming each sound block.

The gaps being a real creature are not AT ALL consistent – hence the random numbering to emulate what the real thing might do..

The result – will depend on the piezo you use but on mine – compared to a live recording – it’s not bad – not bad AT ALL… here’s the code – feel free to experiment. Half a dozen of these in the garden…..

If you REALLY want to go to town  – a movement sensor to make the thing shut up for a while when it senses movement nearby?

latest cricket

For articles on home control, some views and much more – take a look at my main blog.


How do you control 3 LEDS with only 3 wires?

Impossible, right? Wrong.

Charlieplexing is a mechanism to do just that. It was developed by Charles Allen at Maxim.

Because LEDS are diodes they only work in one direction – and they only work above a certain voltage. These characteristics can be used to help control them in a multiplexing fashion.  Imagine for example you had TWO wires – surely you can only drive one LED with that. Well no. Imagine you put 2 LEDS and their associated resistors across the two wires – but in the opposite direction. Take wire A high and B low… and one of the LEDS will light up – takes wire A low and B high and the OTHER LED will light up. 2 wires, 2 LEDS.

So how many LEDS can you multiplex onto 3 pins… 3, 4, 5… no – SIX


And here’s a library suitable for Arduino-like chips I spotted out in the wild!

Arduino Timer– To Overflow or not to Overflow

Part of the learning curve in mastering the use of the Arduino – is how to use delays. The simplest sketches (programs to most people) show turning a light on, waiting a second, turning it off, waiting a second… in a permanent loop.

Still don’t know what an Arduino is? Well, perhaps you should because Google want to put these things in our schools – it’s like a PIC chip but different – a cheap and cheerful way for kids to learn about computers… or put another way, a damned powerful and CHEAP microprocessor to let you do control experiments – timers, lighting systems, heating control, robots….. you name it.

That’s easy – but almost NO programs are so simple that all they do is flash lights (though the chip does a cracking job of emulating a police car set of lights given red and blue LEDS)! The problem with delays is that you can’t DO anything while waiting for the delay to finish.

Perhaps you might want to get clever and make use of interrupts to ensure that certain things happen at the right time – the problem with that is one of volatility – i.e. using variables in the interrupt routine (which can happen at any time) which may be affected by stuff going on in the main program – and vice-versa. Yes interrupts are do-able but anyone who tells beginners that interrupts are easy is delusional. If there’s another way, simple avoid the subject.

I figured instead I’d make use of a standard Arduino routine called millis() – quite safe, it tells you how many milliseconds have elapsed since the chip was last reset. Well, that’s easy – except that it isn’t. There is a whole lot of mumbo-jumbo about how long it takes before millis() overflows… and what does that mean?

It is quite simple really, the millis() routine stores it’s value in an "unsigned long" which you can’t easily access – no black magic, this is a 32-bit number which can count from 0 to just over 4 billion – and that doesn’t take too long really at a count of 1000 a second. Depending what you are building that might not be a problem but any program with any kind of long term timer might end up in trouble.

So as an alternative to sitting in a loop you can look to see how long it was since the last time you read millis() and run code accordingly. The problems with that are two-fold… eventually millis() will reset and you could end up with a duff comparison – OR you could be busy doing something else, call millis() a little late… and now the WHOLE thing is put back a little. Accumulatively you end up building up inaccuracies over time that could be significant.

I decided I needed a delay that was accurate and if I was a little late calling it – well, it would time a little earlier next time to make up for lost time – then I realised people might not want this – even if they were way too late they might not want another call before the minimum specified… so I looked around for routines to do the timing and offer the option of catching up or not. Look for METRO library – sounds great but in order to retain accuracy you have to call that at least every millisecond – WHAT? The simplest DALLAS temperature chip calls sometimes go away for a SECOND… I’ve fixed that incidentally – but you know what I mean.

So, I needed a routine that would handle overflow, that would not mind my calling it a bit late and would give me options to compensate next time for the delay – or NOT.

I’ve wrapped this in a class just really to make sure I understood classes.. and put it on GITHUB again just as a training exercise.

Enjoy.. but TEST – don’t take my word that this works…. if you want to test the overflow- remember the limit for a 32 bit number in HEX is FFFFFFFF (ie 6 Fs). Consider a last timing just under that- add the interval – you get a lower value as it overflows – but actually do the math and you’ll find the difference is still a positive number because both millis() and the comparison are 32 bits and so it still works.

So now you can write a program with routines that might take some time – and you can then check for intervals… an example might be to update the screen every 1 second – if you’re not fussed about accuracy use TRUE for the last parameter – on the other hand you might want a rock-steady beep every second – use FALSE or 0 as the last parameter.

As always a thanks to my pal Aidan – in this case the answer was mine but simply the ability to have someone to bounce the questions off and get intelligent answers makes all the difference.

Incidentally this is NOT super-accurate – you may check the routine at any time – not just dead on the millisecond so WORSE CASE you might find a stagger of somewhat less than a millisecond – ok 1 in a 1000 isn’t that bad – but it’s not perfect. It might mean in a real time clock the difference between catching a show and missing the first second or so Smile

So simple – but it does work. Proof…. call every 1000ms and print out the value of millis() on an LCD and it will display having added 1000 every time i.e. it remains accurate.

class Timing
 unsigned long counter;
 boolean catchup;
    void begin(boolean cat)
    boolean isOver(unsigned long interval)
        unsigned long newmillis=millis();  // temp vars so easier comparison
        if ((newmillis-counter)>=interval)
            if (catchup) counter=newmillis; else counter+=interval;
            return true;
        return false;

// you can hide that class in an include file... so here's how to use it.
Timing myTimer;

void setup()
 // 0 means catch up, 1 means delay will always 
 // be at least the value stated

void loop()
   if (myTimer.isOver(1000))
        // do something here

This code may be improved on – and I’m most likely to store improvements over at GITHUB. Here’s the link for the latest version. Enjoy.

Peter Scargill

Arduino as a Keyboard–working example April 2012

One of the things I wanted to do right at the beginning of learning about the ATMEL microcontrollers (Arduino etc) was to make USB devices – that is, devices that appear to a PC as a USB gadget, for example a keyboard. There are many uses for such devices if they are simple and cheap enough – a little box to insert your username and password for example or to time an operation regardless of what package the PC is using – sky’s the limit, if you can do it.

Sadly when scouring the web for the necessary library I first found stuff that was frankly "academic" by which I mean so incredibly complex you were losing the will to live trying to do something really basic like "hello world".  Some people really haven’t grasped the idea of creating “re-usable components”.

Then I hit on what looked like pay-dirt. A general USB library – including a keyboard library that needed just a few lines of code to make a “hello world” keyboard emulator for example. Well, of course, it didn’t work that way, the library was written in 2008 and NO WAY would the code compile in the current 2012 Arduino IDE… I ended up abandoning the effort, disappointed.

Then this evening, I’d given up for the night and was reading "Practical Arduino by Jon Oxer" (I know, sad but hey, this is how I learn and how I get to sleep, using my spare moments to read up on the technology) and I noticed the same library again… sure enough, I followed the link, grabbed the library and sure enough, it failed to compile.

And then I looked at the bottom of the web page, a little note from 2010, some minor changes. I keyed them in and VOILÀ  – code compiled… so much for the early night. I got out of bed, grabbed a USB lead, ripped it to bits and added the extra components and, taking my life into my hands, plugged the lead into my USB hub. After a few second’s silence (which seemed like ages waiting for smoke to appear) the PC announced a new keyboard had been plugged in. Wheeeeeeeeeeeeeeeee.

tmp7E03The software listing indicated I should short an input to ground on the board… and sure enough "Hello world" appeared in Notepad on my PC – problem solved.

So, what to do – if you’re reading this far, chances are you were looking for a solution. You’ve found it… This is April 2012 and the software works in the current Arduino IDE.

So – first things first – grab the library here.  The layout is weird so don’t just dump it into Arduino as-is. Take the keyboard directory and put it in your Arduino library directory. Grab the keyboard demo file – and if you try to compile it will fail. Make the trivial modifications as detailed at the BOTTOM of this page…and you’re up and running.  Note that you have to use pins D4, D5 and D2 – you can’t go changing pins… and on that same page are instructions – I basically took a standard USB to mini-usb lead, chopped off the mini end – which left me shielding and 4 cores.

tmpCF8BThe shielding I ignored and there are black (ground), red (5v), white (D-) and green (D+) leads..  you must add in the trivial components (I did it on a bit of Veroboard which include a couple of 68r resistors, a 2k2 resistor and a pair of 3v6 zener diodes – they MUST be small – ie 1.2 or 1.4w – as the larger ones have more capacitance and may hinder the USB.

I used 3v9 zeners as I had them handy but DON’T COPY ME – just because my hub has not blown up yet doesn’t mean to say it won’t.  Use 3v6. We’re talking pennies for these components unless you go to Maplin.

So to test the USB keyboard software I used a fully formed Arduino (well, my own UberBareBoard as detailed elsewhere).. but really all you need for this is the chip, an Xtal or ceramic resonator, a decoupling 0.1u cap and… erm, that’s it, oh and a 10k pull-up for the reset.. you really could make a TINY board to do this. Oh, I guess you really need a pretty LED light as well, just to prove it’s on.

That’s it, it really was THAT simple – from getting off my backside and turning the soldering iron on to having “hello world” on the screen took no more than 15 minutes.

Now the fun starts – coming up with applications for this.

DIY Arduino

While waiting for the first Raspberry Pi to arrive, I’m continuing to work with Arduino clones. I use the name repeatedly just as it’s familiar to those in the field, but essentially we’re simply talking about a minimal ATMEL-based processor board with reset and power components. Having discovered that the Chinese do prototype boards quite cheaply and quickly I figured I’d have a go at doing my own. The Eagle PCB package is free for anyone wanting to have a go up to a certain size board. I’ve used this package over the years but not for a decade so it’s nice to see they’re still in operation and obviously they are very popular with the hobby community.

Anyway, here’s the board so far. This is a “jack of all trades” board as I put stuff in that “might come in handy”.

As you can see, it has it’s own proper 5v regulator (fastened down with some heatsink area) and power connector, standard Arduino-type general connectors and the usual microchip, xtal and a crude 3.6v supply via a couple of diodes. The connectors include the normal programming connector, ICSP and one (lower left) specifically for the cheap Chinese RF modules. ~I’ve also put in a 24c65 socket there as the Atmel chip has only 1k of EEPROM for storing logs etc. and the socket I’ve added lets you add a 24c65 or 24c256 chip for up to 64KB of logging or other storage (can’t use for programs).

The next step is to find out the realities of actually getting prototypes made in China. I looked all over the UK and I might be missing something but there’s no-one here to even remotely compete on prototypes – these work out at around a fiver each for 10-off which means if I’ve made a mistake it’s not going to break the bank – but it’ll be weeks before they turn up – so more information at the time… I’ve jokingly called the board “UberBareBoard”… I’ll find out how super it is (or not) when they arrive.


MyDuino !


On the subject of iPads -  has anyone noticed the utter lack of anything new and exciting recently – same with iPhone – it’s as it people are running out of ideas. A good old fashioned (but not old) adventure would be nice, not one of those silly “guess the hidden objects” but a proper adventure…

Testing lights

This is kind of neat… British as well – simply a little board with half a dozen LEDS on it…and resistors – and pins off the bottom. Next time you’re testing that single-chip micro project and you need a bunch of test lights-  this sure beats soldering a bunch of them up on Veroboard…


You get 8 of them on a board the size if a chip – 0.11” spacings… for around £4 or so – check out



I wouldn’t care, but it turned up just after I’d soldered a bunch of LEDs to a board to do some tests!!!


Peter Scargill.

Copper the Catalyst and Nail Varnish Remover

This may well not be new to you – or you might not be the experimenting type – in which case look no further.

Copper is a catalyst, that is something that speeds up a reaction but does not suffer in the process… so examples like platinum catalysts in cars come to mind.

This one is new to me – and is a great, fun and relatively safe way to demonstrate the use of a catalyst.

IF YOU BLOW YOURSELF UP IT’S NOT MY FAULT. ACETONE (Nail Varnish Remover) is flammable and the fumes set fire relatively easily (hence the requirement to use a tiny amount)).

Copper glowing hot above AcetoneGet a piece of copper wire, let’s say earth wire out of one of those 2-core+earth mains cables… and wrap one end around a nail so as to make a coil, maybe half an inch (12mm) long… with slight air gap between the turns..

Get a short glass – like a half-pint glass or less and arrange something non-flammable (like the rest of the wire – or a drill, or fork so that you can put the item across the top of the glass and use it to suspend your coil just off the bottom of the inside of the glass.. maybe 1/2 inch or less.

Put the tiniest amount of nail varnish remover (has to be the type that uses acetone as that’s the bit we’re interested in.

So, you have your coil on the end of your wire, dangling…… just above the acetone…  take the arrangement away from the glass and with a cigarette lighter, heat it until red hot… replace the arrangement in the glass…. and watch.

Without flame, the copper will continue to glow red hot… experiment with layout, size of coil etc. but always near but not touching the surface, the idea being to get air and acetone fumes on the copper.

There are plenty of places on the web to explain this – I can’t help thinking there has to be a way (while venting waste fumes) of making a neat heater with this. With thicker cable I managed to keep the thing hot at just below red glow level… The example you see here was thick earth wire, one coil within another – to keep the surface area up… but a MUCH simpler arrangement works just fine , even a thin copper WIRE with no coil works fine but tends to turn off quite easily.