lua arduino-cli

I broke up with Lua and got with arduino-cli for ESP8266 development

TL; DR With the advent of arduino-cli there are no more reasons to use Lua over C/C++ for ESP8266 programming. Please challenge me on that in the comments if you can 😉

I enjoyed a couple of years of writing asynchronous code in Lua. It was fun and intuitive for someone like me, with a solid NodeJS background. I truly love asynchronous environments.

The reason I got into Lua to begin with though was because I’m a Vim user and at the time Arduino IDE with its editor was the only alternative. Programming in Lua allowed me to escape the dreaded UI and stay in my familiar, optimized and efficient text editing environment. Seems like a minor annoyance to be the reason choose the programming language for but I think many of you, especially professional developers, can appreciate just how important it is.

So Lua and I had a fun couple of years together and I would probably still be running it on my ESPs except I started to bump into memory space issues. Adding a print statement would all of a sudden put it over the limit. And the script wasn’t even that big. 100, maybe 200 lines.

I tried things like modularizing bits of code, using require over dofile. Making sure I declare local variables as such, etc.. I even started to look at using Lua Flash Store (LSF) but that quickly became tedious and over complicated just to get my moisture sensors talking to sprinklers with some weather forecasting.

So I decided to check out Arduino command line tools, whether they even existed. And to my surprise I found out that I totally missed the introduction of arduino-cli. It does everything I always wanted when it comes to C/C++ development for Arduino and ESP8266.

It manages your boards and libraries, compiles and uploads your code. All without having to ditch your favourite text editor or leaving the terminal.

And doing my first little project in C reminded me how much a strong typed language can be a pleasure to work with, especially for the kind of small, modular projects most home automation programming ends up being.

The Lua project that was too big for Wemos D1 Mini took up less than 40% of it when I re-did in C. With only something like 16% of it being my code.

Ditch Lua if you haven’t yet unless you just want to get some experience working with something different.


Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *