What’s this about?
This is the UK website for Peter and Maureen Scargill. We live in the Northeast of England and also Andalucia in Spain.

Read through the blog entries, menu-accessible pages and archives if you're interested! Welcome to Peter and Maureen's website.

Get in touch via Facebook My Facebook Page
You should follow me on Twitter Follow me on Twitter
Join my LinkedIn network Join my network

Pete's Online CV
Archives

Archive for the ‘ESP-03’ Category

Finding bugs

That was funny… We are currently deep within MIT in Boston preparing a talk and workshop on a microprocessor called the ESP8266 and what should turn up but a bug. No, a REAL one and what a monster.

image

We’re still working on the jokes…

ESP8266 LUA editing tool

This one is definitely only for a very narrow selection of techies – and is also featured in my tech blog – the only reason it is in here as I’ve had lots of help from a Chinese manufacturer and they were interested in the blog – but the great firewall of China seems to have blocked it – so I thought it only reasonable to put it somewhere they could access the entry.

This blog refers to the ESP8266, which is a small, inexpensive board for embedded processing. It offers cheap WIFI to add to an embedded microprocessor project. Indeed with a little work it’s useful on it’s own.  Early days and entering information into the thing is not ideal, especially for Windows programmers – so I wrote a little serial terminal to do the job.

Need a serial terminal to help program the ESP8266 in LUA?

Well, I certainly did as even the rather nice Coolterm was driving me nuts. As of the latest version, we have the basics of an excellent programming tool in the Lua Interpreter for the ESP8266 boards. All you have to do is use a file like FLASH DOWNLOAD TOOL to blow the LUA interpreter onto the board then it’s a matter of sending information via serial to the board and watching the responses.

Except for some peculiarities – the board is chronically short of RAM and sending functions directly eats up more of it… one way to get around this and also to ensure that your functions are set in the board “permanently” – ie stored in FLASH, is to write them as files. But that can get a little messy. It is sometimes better to store functions in “files” – these are then activated by the “dofile” command. For more on that see the LUA documentation.

One particular file you will NEED is the “init.lua” file – because whatever is in there will be run when the board powers up! If you want a little remote light controller you are going to need the board to power up, connect to your router and start some code ALL ON IT’S OWN.

In my case the code is simple..

print “Pete’s LUA module 0.4”
tmr.alarm(4000,0,function() dofile(“thelot.lua”) dofile(“mylistener.lua”) end

WHAT?? What on EARTH was that all about???

Well, on powerup I want the interpreter to say “Pete’s LUA module 0.4” – I then want it to wait for 4 seconds… and call a stored function (one I stored) called “thelot.lua”. That function will check to see if the board connected is actually talking to my router – and if not – will run code to make that happen. It will then call another stored function I wrote called “myslistener.lua” which will go off and listen for commands coming in front the Internet.

AND THAT’S FINE, I’ll not detail those functions here, that’s for another place… BUT you have to get this information and the other functions (which are a lot bigger than this one)  INTO the Lua interpreter via the serial port.  Using Coolterm you could do this by pasting in the code from, say, NOTEPAD.. but there’s a problem – that stuff will run there and then – it won’t wait till powerup!!

SO to delay the inevitable, you make it a FILE by wrapping your code inside file commands.. You firstly ensure the file does not exist by erasing it.

file.remove(“init.lua”)

If it does not already exist, no problem. Then you create the file.

file.open(“init.lua”,”w”)

Easy enough, when you’re done you close it.

file.close()

Also easy.. but the bit in the middle – my code above needs wrapping in “file.writeline([[“ and “]])” and that gets messy. See the final code you need to enter into the LUA interpreter.

file.remove("init.lua")
file.open("init.lua","w")
file.writeline([[print("Pete’s LUA module 0.3")]])
file.writeline([[tmr.alarm(4000, 0, function() dofile("thelot.lua") dofile("mylistener.lua") end )]])  
file.close()

In this example it’s not too bad… but it makes the code harder to read. What would be nice would be if Coolterm could spot that you’re in a file and add that info for you. Also what about comments

–this is a comment

or blank lines.. here’s what you might have

— My startup file – this needs loading into LUA

    file.remove("init.lua")
    file.open("init.lua","w")
    file.writeline([[print("Pete’s LUA module 0.3")]])
    file.writeline([[tmr.alarm(4000, 0, function() dofile("thelot.lua") dofile("mylistener.lua") end )]])  
    file.close()

— All done.

So here we are, after struggling for weeks, we now have a nice interpreter for our little boards and we can start to get ambitious – but the tools for sending this to the board arent’ really up to the job and if you’re a Windows person you don’t want to go messing with command line stuff.

SO I wrote this little serial terminal specially for the job – to make life easier for myself. It started off simple enough but like all things I got ambitious. The terminal will now take your code, strip out leading and trailing spaces, strip out comments, it will add delays between each line to make sure the LUA interpreter doesn’t get overloaded, it will spot that you planned to send stuff as files and will add the relevant code.

So this is what you send.

— My startup file – this needs loading into LUA

    file.remove("init.lua")
    file.open("init.lua","w")
    print("Pete’s LUA module 0.3")
    tmr.alarm(4000, 0, function() dofile("thelot.lua") dofile("mylistener.lua") end
    file.close()

— All done.

That’s a bit neater.. and this is what will actually appear in the window showing feedback from the board.

file.remove("init.lua")
> file.open("init.lua","w")
> file.writeline([[print "Pete’s LUA module 0.4"]])
> file.writeline([[tmr.alarm(4000, 0, function() dofile("thelot.lua") dofile("mylistener.lua") end )]])
> file.close()
>

And that, is that. The installation files are below, no source code, no support and no I’m not spying on you… I wrote this for me and will develop it as the need to do so arises. Works on Windows 7 and 8 is all I can tell you.

Here’s a screenshot

Esp8266 Lua Terminal

And here is a link to the zip file – unzip somewhere – run install . Enjoy. Note this will NOT work on XP as apparently said operating system does not support .NET 4.5 – sorry.

Incidentally you RUN files – i.e. make the Interpreter load up the code with the “dofile” function. For example dofile(“init.lua”) – in the case of this particular file you don’t have to worry as it will automatically be loaded on power up). All of this is detailed with the LUA interpreter.

Of course, you don’t need to be using LUA to enjoy this – you could be using the AT demo… or something else – but I wrote it to help with LUA programming.  Did I miss some really neat, simple feature?

Update – I’ve added tooltips, turned the format on by default, replaced the original simple automcomplete with a new version with most of the AT commands and some Lua commands all in there and put a check in for opening a dead port. Also added Arduino mode (to reset Arduinos as does their internal IDE serial monitor) and more.