To Lua or Not to Lua

Serial TerminalLua is one of the two main contenders for firmware for the little ESP8266 WIFI boards which have peaked so much interest recently because of their low price of under £3 (for some reason some people pay more). Alternatively you can brew your own firmware but contrary to popular belief, most of us don’t have time for that and if we did we’d have to take a month to learn Linux commands – so for the majority, the success or failure of these boards will be down to available firmware.

AT Commands – the original AT command set from Espressif is coming along nicely – I would not say it’s perfect but armed with an external processor such as an Arduino, it is possible to interrogate little WIFI boards and for example go and get information from a web server or act as a TCP/IP listener and respond to commands. Right now for anything serious that is my preferred option.

Lua Interpreter. A month ago I’d never heard of Lua and sometimes I still wish I had not, however it is a small, high level interpreted language that can be embedded into the ESP8266 boards and as of last week it will even read the likes of Dallas temperature chips and the A/D on the board. It can read inputs, control outputs and give you many of the facilities that the AT commands can. As you can see in the image above I even developed my own serial terminal specifically to deal with this board and with Lua in particular as I found myself using the same commands over and over again so I developed a non-volatile notepad and filing system to quickly save and retrieve snippets of code as well as easing the process of saving “files” to the board.

Here however is my current list of issues with this otherwise fine piece of work by a gentleman who goes by the name of Zeroday.

1. RAM – the board is chronically short of RAM for variables and the stack – it does not take too much for it to reboot thanks to running out of memory

2. It has only one timer – and that would not be a problem except for the nature of the language – multitasking is arranged cooperatively and unlike the venerable VB6 it does not have the equivalent of doEvents() to let other processes have a go when you are busy. So everything has to be event driven, not ideal for this application. For example one could run the timer at say once per second and increment a load of variables – giving almost unlimited timers but creating a loop in which to poll those timers blocks access to background processes! Ok you could do all of that in the timer callback routine but that limits how much time you can spend on each process severely. Right now for example reading the temperature sensor takes over a second (working on that)

3. Storing variables permanently – lets say the interpreter is running code constantly to listen to an Android of IOS App to control outputs… if the power goes off – how do you restore the outputs to their previous state? There seems to be no equivalent of the Arduino EEPROM facility.  I may be wrong on this one but I spend an hour last night staring at the ceiling trying to figure this one out.

Of course all of this is resolved with the AT command set and a separate processor – but for the fact

that you’ve now gone from a sub £3 device to at least twice that….

Time will tell.

10 thoughts on “To Lua or Not to Lua

  1. Hi Peter

    If you use a ESP8266 board with the required pinouts then you could use external serial memory to store the Lua code.

    The SDK has SPI code in it and there is I2C code on the github. But external memory costs.

    For the time being I will stick to sending AT commands from the 3.3v version of the Arduino Pro Mini. It cost lest than £2, inc postage, from a land far away, and should let me run my sensors on battery power.

  2. Yes I appreciate that I could stick on more memory but that kind of defeats the object. In Lua from the command line you can create a file – and that might be a start up file with definition changes… not entirely sure if you can get into that in code and update any variables therein – oh, well, only one way to find out…. I too am using AT commands in another strand of research with An Arduino but as most of the peripherals I have are 5v… I need to stick with level conversion which after all is only a couple of resistors in this case. Yes the very cheap Pro mini – I have a couple of those… question – as I’m not really familiar with running Arduino at 3v3 – can you still run at 16 meg?

    • You can run a 3.3v Pro Mini at 16Mhz, but that is overclocking it by 20%, not a good idea. The standard 3.3v clock is 8Mhz.

      I have seen a 3.3v 16Mhz multicopter part, but at 3 times the price.

      I have gone for the 3.3v part for battery operation and no need for level shifting.

  3. And that, perhaps is the point – and not as high power generally. Some years ago we developed a reliable circuit with triac, triac driver, 2 resistors and a VDR – it would drive any load.. But compared to a £1 standard 10 or 25 relay? Forget it.

  4. Hi Peter,

    I haven’t spent any time with the Lua interpreter for the ESP8266… my gut feeling remains that the ESP8266 is just too small (memory, processor, peripherals) to get your moneys’ worth of functionality out of this part using an interpreted language. But I’m not an expert in this area.

    I’m more used to writing C for micros (PICs) and I think this will be the ticket, especially if the legions of helpful developers roll out a friendly C library that masks alot of the complexity. However I too have been struggling with the C toolchain. The cygwin environment worked on my Win 8, except the new RTOS version of rhe SDK allegedly won’t work with it. I do have a Linux box I could try…

    It’s still early days with this cool little chip.

  5. You might well be right Ken but it’s fun to try. Having said that until this morning I was dead convinced the AT code was the route to go. I left a little demo board running – which grabs the time – then acts as a TCP/IP client for an Android App. Went to bed last night it was working stunningly well, got up hours later, stone cold dead. By comparison my home control efforts using Ethernet cards have managed 6 months without crashing… so I’m disappointed this morning but will plough on. I write in C (well near enough) for the Atmels…. I think I’ve just realised that the AT code can’t do DNS name lookup – I’m hoping I’m wrong.

  6. Peter, I have read that At the moment the esp8266 firmware has hard coded DNS servers ( Hope this helps

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s