07:20PM – This one is turning into a MONSTER of a blog entry – lots of new stuff.
This article describes the ESP-01, fitted with LUA firmware that is able to converse with a serial terminal in a high level language, store programs and data, turn things on and off in a package that costs almost nothing. The possibilities for ridiculously cheap remote temperature sensors and more are finally here. The software is new, the hardware is relatively new – and we need people working on software to make remote access easy. No guarantees here as I have only tested (and reported on) some of the features. Am important fix that made this practical to use only came through in the early hours of this morning – there will be bugs but at least it’s a starting point – all you have to lose is a little time.
Cheapest computer is of course a grandiose title, for sure and one one that would have been invalid as far back as, oh, yesterday, but I think its’ fair to say that as of this morning we have a stunning new development. That is not to detract from the many worthwhile firmware developments on-going for the ESP-01 and similar boards, but here I’m going to present you with all you need to get the cheapest computer in the world up and running.
What do I mean by a computer in this context? I mean a device capable of connecting to the outside world via WIFI and doing real things – like flashing a light or reading a sensor – and having a human interface installed…. I’m stretching this a little, but essentially right now as I write this I have in front of me a computer capable of responding to commands in a terminal window – for £2 – does that have your interest?
So now we have probably the world’s cheapest WIFI computer.
The ESP-01 has been around for a little while now- what you are looking at top left is a processor with built-in WIFI radio, a memory chip, a PCB aerial and a few passives. It has a 0.1” spacing (therefore easy to use) connector and that is about it. It comes with some firmware which will have you tearing your hair out if you have any – but that’s no the point – the firmware is easilty replaceable and that has not been lost on the community out there. One of the developments I’ve been following VERY closely over the past few days is that of the LUA firmware for ESP8266. That is, given the starting point of our £2 ESP-01 boards (if they cost a LOT more than that you are being ripped off) and some firmware for it that actually works. We’ve had problems with the indigenous firmware (but those problems are slowly going away, I hope) and there are a couple of alternative firmware sets floating about – and I have NO doubt they will find their place and I will be using them and blogging about them. Compiling the firmware to make your own amendments is a PAIN IN THE BACKSIDE and assumes you love using Linux – which I don’t and the compilation process churns out hundreds of miles of messages (well, quite a few anyway). But the purpose of THIS entry is to sweep away all of that and to detail this one fabulous attempt to make the ESP-01 not only act as it should, as a WIFI board- but to do it STAND-ALONE without understanding compilers or Linux or having to stick another processor on to make it work (though you CAN of course do that and some of us almost definitely will, sometimes).
LUA is a high level language – and I’ll be honest despite knowing DOZENS of computer languages I’d never come across until last week and I am so glad I now DO know a little something about it. So before delving into explanations, lets cut the bull and see what we can expect for £2.
Take one £2 board + FTDI. i.e. a USB to serial interface, cheap – like… a fiver – if you’re into Arduino programming you probably already have one) and very common in the Arduino world – feed that into a PC with a suitable terminal program and VOILA. See the picture on the left. Does THAT get your interest up? You are looking at the BEST free serial terminal software I’ve found this week – having wasted a good day of my life with the absolutely horrible REALTERM – this free package could not be better suited to this application IF IT TRIED.
So what we’re looking at on the right is the output from the little ESP-01 board, loaded up with the LUA firmware (this morning’s version). I’ve installed a couple of routines I put together and I’m talking to the board on my Windows PC, via Coolterm at 9600 baud. In this example I’ve given you the world-famous “Hello world” but there is so much more that you can do already. I envisage testing something like this – then lifting the EPS-01 off onto it’s own motherboard (yet to come into existence, we’re looking at this right now) and controlling something via WIFI.
What you see on the right is the board, connected to a 3v3 supply (should be able to handle maybe 250ma minimum so NOT the very tiniest of regulators) and the FTDI which gives it access to serial commands from my computer using this great Coolterm package.
To follow…. far more information and the high level software to get this far. I figured you’d want to set up a board, get the firmware and grab the terminal software. Refresh this page to see the latest version. I’ll show you examples of coding. If you want more information see my previous blog entries. You will be able to write to the WIFI board directly from the terminal and even “dump” in a while set of instructions or a “file”. In my example, wifi-sta-getap(listap) is a built-in function that is calling a user function which was loaded in by me and stored in the non-volatile storage of the board. In time, examples of functions you can save permanently on the board will appear – all of this with nothing more than a text editor and free terminal program. Hell, you could do all of this from a tablet – on holiday, on the beach (if you know any beaches with WIFI or you have a MIFI unit, for example).
01:53PM – So, the basic LUA interpreter requires a start-up function and that start up function can initialise variables and make the connection to your WIFI router – it’s all interpreted, it all sits in FLASH and hence can be remembered when the power is cycled. Actually creating a product out of this is beyond the scope of this article but the good thing is that armed with the terminal software you can experiment, often the easiest way to learn. You need to get the software which has some instructions and an API guide. Also grab online a beginners guide to LUA – it really is easy if you’re used to C or similar languages and you’ll find yourself as you’re reading the guide thinking “oh THAT’s a good idea”.
You should be looking to learn about LUA 5.1 – not 5.0 and apparently not 5.2 – and beware the implementation of LUA used in the ESP8266 is not right now a full one – it does not (unless I missed something) handle floating point. But what is in there is support for things you’d never imagine in such a low-cost board – the writer has implemented (I’ve not tested these yet) i2C and some analog functions – he’s also implemented PWM on pins (ok so you’ve only got a maximum of 4 pins and only 2 if you want serial comms to play interactively… but think about it – port extender on those two pins!!! To get there in the first place you’ll need one of the means of programming the firmware into the boards – I suggest checking previous blog items here as I’ve already mentioned this. I’m using for this firmware the simple esp8266_flasher.exe on my Windows based PC.
As you will see in the documentation, for this “computer” you will need to define a start-up routine. That is, something that runs when you power up the kit so that it is connected to your broadband. Now, once it’s been set up and has an IP address, actually you don’t need this as it will remember the address of the router and hook up automatically, but that is new and you might want to give that a good test rather than take my word for it.
Now, you may be wondering – can I get LUA for Windows so I can have a play? Well yes but remember this will be more feature-rich than the one we have for the little board. You can get LUA for Windows here. Don’t ask me questions though – I know nothing about it except to say it is a command-line version of the interpreter.
But what if, like me you hate command line stuff and want the usual graphical IDE? Well you’re in luck as the ZeroBrane IDE will let you have a tinker without getting your hands too dirty. If on a Windows PC grab the LUA code and install, grab the ZeroBrane and install and (well in my case) within minutes without any effort other than to learn to press F6 – I had my first test program running – see the window on the right. What fun. I repeat this is for learning only – you won’t get any of the graphical examples running on the little ESP-01 – but at least you get to play with variables and functions etc. and quickly get to know how to use LUA which the new firmware is based on (based on version 5.1).
As I referred to earlier, in order to do anything sensible you need a start-up routine. I cannot get into LUA programming here but I’m going to show you a “file” I’m playing with – which works.
Couple of things you need to know about LUA for this to make sense You can surround strings by single quotes, or double quotes or 2 opening and 2 closing brackets. The advantage of the latter is you can freely mix quotes inside there – neat, huh! There is an operator for concatenating strings – 2 dots, like this. ..
So given that you have the firmware in place and given that the Serial terminal is running at 9600 (and if you want to send several lines pasted into the window I suggest setting a 300ms interval in between each line)… here is my code.
file.writeline([[print(“Pete’s LUA module 0.1”)]])
file.writeline([[tmr.alarm(4000, 0, function() dofile(“thelot.lua”) end )]])
file.writeline([[connecttoap = function (ssid,pw)]])
Functions can be stored in the board by typing them in – but you lose them on power up – another way is to add “files” to the board which do NOT get wiped at power up – and “DOING” the files – it running the contents therein. Best to ERASE (remove) an old file before putting a new one in – just to be safe. So as you’ll see above I am wiping an old file called “init.lua” and replacing it with a new one – that’s the startup routine – I’m then writing another file which contains functions I may want to call. In the start-up routine there is a timer that mean that after the start-up routine has all done, a few seconds later the second file will be run – putting various routines in place, connecting to my router (put your own details in there) and saying OK.
If this does not make sense please don’t shower me with questions – I’m only one step ahead of you. It’s all pretty much explained in the files that come with the LUA firmware – print them out and study. PLEASE NOTE at the time of writing there are still bugs in the interpreter, not the least being the stack runs out almost immediately when for example trying to run a simple web server. The author is aware of this.
Mo Hasan has pointed out an Indiagogo campaign for another board here – though they don’t seem to be getting too far at the time of writing – and you might also be interested in a more expensive board here. One thing is for sure, we’re soon going to have WIFI boards popping out of our ears. That sparks off TWO new conversations… 1) Security and 2) I wonder how many gadgets your average cheap home router will handle before croaking!
There are of course a number of variations on these boards as well as the ESP-01.
The ESP-09 seems interesting in that it has no aerial on-board and the pins are solderable underneath. More’s the point – there are 19 of them – now THAT could be useful – especially with the LUA software which can support other IO pins than GP00 and GP02
Then there is the ESP-02 – this does not have an internal aerial but this one just seems to have the normal number of pins so unless you really need that extra range, not sure of the point.
And here we see the ESP-08 which seems to have neither an internal aerial NOR an external aerial socket. Wierd. That has a few more pins.
In case you are interested (well, you would be or your would not be reading this article) I found this and updated from Chinglish into English – (I hope – you might want to check and not take my word for it)
Different type of ESP8266 Serial boards have their own features:
1. ESP-01: PCB Antenna, 400m Distance (yeah, right), easy to use
2. ESP-02: Surface Mount Device, longer distance, antenna can be attached to the shell by using an IPX header
3. ESP-03: Surface Mount Device, Built-in ceramic antenna , all IO available
4. ESP-04: Surface Mount Device, customisable antenna, flexible design, all IO available
5. ESP-05: Surface Mount Device, compatible with external antenna – sorry even I could not translate the rest
6. ESP-06: Bottom SMT technology, all IO available, with metal shielding case
7. ESP-07: Semi hole SMT technology, all IO available, with metal shielding case,supports external IPX antenna as well as internal ceramic antenna.
8. ESP-08: Semi hole SMT technology, all IO available, with metal shielding case, type of antenna can be defined by customers (what does THAT mean?)
9. ESP-09: Ultra small packaging 10*10mm. 4 layer technology, 1M byte (must be a bigger FLASH – but how would you use THAT?)
10. ESP-10: Patch Interface, narrow body design, 10mm width, suitable for LED Controller.
11. ESP-11:Patch Interface, ceramic antenna, small body design.
More information generally including many links here.
08:31PM – Note: The Telnet example does not work – crashed immediately on use for two of us on two installations – reported.
If you come up with some interesting ideas for code – or thoughts as to how this amazing little device might be used in this context, please DO write in here – we’re all on a learning curve. If you want to know more about me (can’t imagine why) – there’s an about page in here – see menu at the top – links off that.