Tag Archives: Arduino + ESP-01 Magic with Espduino

In a Far Distance Galaxy

A long, long time ago in a far distant…well, world, when I was pretty much using Arduinos for everything, the ESP-01 came along and my friend and colleague Aidan made a little board to handle a relay, an LCD display and.. an ESP-01. At the time we had no use for it, just seemed like a good idea.

Arduino board with ESP-01Today thanks to the likes of Tuan for his work on MQTT and the guys responsible for getting the ESP environment working on Windows via Eclipse (not to mention Espressif themselves) it is very tempting to think that we no longer need Arduinos.

When I say Arduino I mean of course any board based on the Atmel chips. In this case we used a 1284 chip which is an Arduino on steroids but completely compatible. Way more pins, 16K RAM, 128K FLASH – lovely. But as with most Arduinos, getting them to talk to the Internet is disproportionately expensive in terms of available FLASH and real cost.

Well, it was. Thanks to Tuan once again, we now have a way to merge the two. When I was talking to him a LOT about the MQTT software (as I kept finding bugs) he mentioned briefly that he was working on a serial protocol called SLIP so that the ESP boards could communicate efficiently and reliably with the likes of Arduinos.

Well, this evening I decided to revisit this and went off to his Github site here. You may be familiar with his esp_mqtt software which is superb and which I use as the base of my various ESP-12 boards. Well, in that link you’ll find another project of his called espduino. I suggest you take a look.

In essence there are a couple of binary files you blow into an ESP01.  The ESP-01 talks to the Arduino via serial and in the case of lesser Arduinos, that means talking via SERIAL (the only serial port) while doing debugging via a software serial port. Well, the `280 and 2560 based boards have more than one serial port, so I’ve taken his Arduino code and swapped things around… Serial1 for the connection between Arduino and ESP-01 – and Serial for debugging.

So basically once you’ve dumped the binaries into the ESP-01, you connect serial1 from the Arduino (in his example Serial) to the ESP8266 serial – taking into account any level shifting – best to run everything off 3v3 then you don’t have to worry about it.

He shows a wire from the ESP (CH_PD) to D4 on the Arduino but then doesn’t use it so tie CH_PD high as usual.

Run Tuan’s library examples on the Arduino and I can tell you that they just run – they work without issue – I’ve had the board send thousands of messages off to MQTT-Spy. The minimum setup takes in total around 9k, that’s including MQTT -  this is WAY better than anything you could achieve with Arduino Ethernet boards which, as far as I’m concerned are now dead in the water.

In my case we had this little board with the option to add an ESP-01 – took me minutes to get it working – I’ve now imported my command parser from the ESP-12 projects (they’re not that dissimilar if you are using C)  and now I have a board that asks my PI for the time (it’s in the blog somewhere – MQTT request – all my boards know and maintain the time, updated from a Pi on power up and every day otherwise) and can turn a relay off using the same protocols I discussed here.  All I need now is a boatload of libraries and if-then-else blocks to pad the board out into something really useful.

So why add this extra level of complexity?  Well, I use serial LEDs and PWM based lighting and the ESP-12 does NOT do PWM well AT ALL. If you control serial LEDs and say they are slowly fading out – any PWM in use fluctuates slightly. In addition I have serial LEDs working almost perfectly on the ESP8266 but every now and then there’s a timing-related flicker – almost never but you know it is going to do it just as the lights are fading out as you are going to sleep.

The Arduino on the other hand does multi-output PWM flawlessly and there is the great FastLed library for the serial LEDs – not to mention the ability to store data in FLASH easily which means that LCD fonts are easy to implement… and there are many LCD display libraries out there. The combination then is a matter of sense – and let’s face it you can get a bog-standard Nano Arduino from China for under £2 and the ESP-01 for WELL under £2 so using both together is hardly going to break the bank.

So there it is… that’s my Sunday offering – already the board is getting the time and controlling a relay… it won’t be long before I turn it into a kitchen sink.