Category Archives: ESP32

The M5 Stack

M5StackThe M5 Stack looks to be a reasonable use of the ESP32 and for those who need to start from a boxed product with display, it might just have a bright future.

In a nutshell this is a pretty looking ESP32-based box with display and buttons. Do with it what you will. It needs low voltage and the basic unit comes with internal battery supply. instructions, 0.1” pin leads and a USB C lead for charging and serial connection.

The M5 Stack Extensible Micro Control Module WiFi Bluetooth ESP32 Development Kit or Core Module —
Arduino Compatible SCM & DIY Kits —

M5 stackI just HAD to order one and so I thought I’d put a note in here for people into the ESP32 and I’m already seeing responses including a useful note from Bob H and comments from others.  All in all I’m already convinced I need this gadget on my hallway wall even though I’m not yet entirely sure what to do with it. Perhaps people who are ahead of me might write in soon to save me re-inventing the wheel.

Continue reading The M5 Stack


The Script and ESP8266 Code for Beginners

I’m often asked about setting up MQTT, Node-Red etc. on the likes of Raspberry Pi, NanoPi or similar, with a view to controlling ESP8266 devices.

Novice readers start here

Usually it is difficult for me to see this from a beginner perspective, but having spent 2 months in hospital thanks to an untimely stroke from which I’m still recovering, 4 months after the event, I recently found myself doing new installs without the benefit of doing this stuff every day. I am just SO glad I blog everything.

Array of Raspberry PIs

Continue reading The Script and ESP8266 Code for Beginners


Another ESP32

tmp397FIt seems that ESP32 boards are now coming down in price and increasing in number.

In today’s mailbag, this little number entitled WeMos® TTgo ESP32 WiFi + Bluetooth Board 4MB Flash UNO D1 R32.

This isn’t the cheapest ESP32 out there (though it is not expensive either)  – some of the simpler ones with merely 2 lines of connectors and a USB socket are cheaper – but then they’re not size compatible with Arduino boards (if that is important to you).

Continue reading Another ESP32



QD-TechIn case you were wondering – no, I’ve not gone off the boil, I’ve been quietly beavering away on my ESP8266 code since deciding to abandon the old ESP-01 and adding fonts for displays. Right now I’m focussing on the QD-Tech boards – 120×160 but I’ll eventually migrate the use of the various icons to the other displays now that I’m not terrified of running out of space.

Continue reading Icons


ESP32 First Steps

ESP32I said I would not touch the ESP32 until the price came down and true to form, I just received my first ESP32 from AliExpress. Still a little more expensive than I’d like at £5.35 (inc postage came to £6.67) but I felt it was time to make a start. Bear in mind that a similar-looking ESP8266 board is half this price.

The ESP32-S board is as you would expect from a Node-MCU-type board, a simple USB plug in job with 0.1” centre holes along with reset (EN) and programming  buttons.  Unlike the ESP8266, you can see the start-up messages coming up at 115k baud and when in programming mode the board says “waiting to download” – which is very civilised.

What I will quickly gripe about on these boards is lack of LEDS. There is one RED LED which comes up with power and does nothing else. So when you are blowing the chip – there is no visual indication that anything is going on. It isn’t as if LEDs are expensive and there is room on the board!

I’m waiting to hear back from the Mongoose people as I had no success getting this board to work with their Javascript software but in the meanwhile I thought I’d give the Arduino IDE a go.

As far as I can tell there is no board level install for the Arduino IDE and ESP32 yet but I found that the Sparkfun guide worked well on my existing Arduino 1.69 IDE.   I had to install GIT on Windows to make this work – but that took mere seconds, all in all an utterly painless experience.

Despite mentioning the reset and programming buttons, you don’t need to touch any of those with the IDE – just load in your program and press the UPLOAD button on the IDE and you’re all set.

I took the more or less standard Blink example and changed the port to pin 5.

int ledPin = 5;

void setup()
pinMode(ledPin, OUTPUT);

void loop()
Serial.println(“Hello, world!”);
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin, LOW);

You don’t get any simpler than this – I checked which ports were available on the IDE then plugged in the ESP32 board  and tried again – COM6 appeared out of nowhere so I selected that. I also selected the board “Node32s” which appeared in the Arduino IDE once I’d done the Sparkfun install.

And that, ladies and gents, was it. I plugged a LED+resistor to ground and GPIO5 and it flashed reliably while putting out the serial message “Hello, world!”.

Now, the novice might say “so – I can do that with an ESP8266…  but I always like to try something really simple first to prove that the board and software were both working.

ESP32[6]I borrowed this diagram for my board from the excellent free book by Neil Kolban “Kolban-ESP32”. So, why look at the ESP32 when the ESP8266 is such a great board? Well, how about this… 34 GPIO lines, 7A/D convertor inputs, WiFi AND Bluetooth, 520K RAM and 3 UARTs – that good enough for starters? Oh and 3x SPI and 2x I2c.  The ESP32 is also capable of running in deep sleep at 20uA.

Of course all of this sounds good but whether all of that is easy to use is another matter – remember the ESP8266 has I2c but it doesn’t work so you have to use a software version!

In the IDE, ESP32-specific examples were, well, almost non-existent – so I tried one of my ESP8266 examples with WIFI and MQTT. Hey – there’s nothing like going in at the deep end and I absolutely did not expect results!!!

My code is a work in progress and not shown here – but it is a first stab for the ESP8266 at getting my normal WIFI+MQTT+various commands software running in the Arduino environment – a half-hearted project I’ve been working on in the background and includes OTA.  To be honest I was just wasting time trying this out because of the differences between the ESP8266 and the ESP32.  I set the compile going and of course, it did not know about the ESP8266 WIFI or the ESP8266 OTA code. I looked at an example in the Sparkfun page referenced above and they used “#include WiFi.h” – so I changed my include to that – and commented out the OTA stuff.

Well, blow me, it compiled – and better – when I pressed upload in the IDE – the next thing I saw on the serial monitor was it connecting to my WIFI and then to my MQTT broker!!! I had no real commands in the code yet but if I fired a dummy message out to MQTT it is supposed to come back with “Did not understand” which means WIFI and both MQTT publish and subscribe work.

Well, it worked – and sent the message back, with no modifications  – I’m impressed. Within a couple of minutes I had my usual {out5:1} working and from there, well, the sky is the limit.

As far as I can tell (someone tell me if I’m wrong) we’re still stuck with a maximum of 1 MB of FLASH for programs and that little demo used 40% of it – I’m assuming most of that is libraries. RAM on the other hand – well, there’s TONS of that. Unlike the Arduino IDE when using ESP8266 which give you lots of options for FLASH, I could find no options for the ESP32 – which might account for the 1MB limit. I’ll keep looking.

Assuming the price continues to drop I can see a great future for this little device.


VT100 Terminal for HC2018

rear view ESP8266 VT100Well, I had to give it a go, didn’t I – porting the code for the cheap VT100-type serial terminal into the main ESP8266 home control software.

BOY was that difficult but… after 2 days of head-scratching – check out the home control manual in the source code repository for Home Control 2018 – this  uses up four precious port bits (GPIO 13,14,15,16).

I have the terminal code up and running (minus baud rate controls… and the bottom line is now a general status line) and I have to say, fast doesn’t start to explain it.

As you can see in the image above, all we have here is the display with a slim ESP8266 board behind it – a WEMO D1 does the job superbly and you can use double sided tape to fasten the ESP8266 to the flat part of the board.  I just used a board I had handy The FTDI you see attached to the back is merely there to provide 5v power and, erm, stand the unit up!!!

At this point I’ll add what I seemed to have missed out of the original article – the pins!

Connections:  Connect VCC to 5v, ground to ground, light to 3v3.   GPIO16 to D/C, GPIO15 to CS, GPIO14 to SCK and GPIO13 to SDI (MOSI).  Connect RESET to RESET.  Leave the SDO (MISO) on the display unconnected.  The whole thing should light up.. and when you give the {ili_set:1} command and reboot the ESP, the display should clear and put up the header. That’s it.

ESP8266 VT100 front viewI did some tests to see if how fast I could make it –  I’ve already optimised the SPI and character routines – the board will not operate at all under ESP8266 at the fastest SPI speed so that is probably a dead-end, I tried caching the ROM reads (which are 8 bits – meaning you have to read 32 bits at a time and select the right 8 bits.

Caching that info actually very marginally slowed things down – I tried all sorts, writing 16 bits at a time to SPI – and finally after being able to obtain no more speed improvements, I stopped – not sure why I needed any of this as it was already blazingly fast.  Now, writing an X to every location on the screen (that’s 1600 character writes) takes 330ms so that is 200us per character (5*7). I think that is fast enough for now. Clear screen is near enough instant and scrolling is instant.

See this demo video of the ESP8266 version – the 328 version isn’t  quite THIS fast but it is still fast.

So I’ve added some commands in the HC2018 project code

The above will setup the display and make it available to accept data – once set the display will set itself up on power up of the unit.  Setting that command to 0 stops any data and from there on the display will NOT initialise on powerup.
{ili_text:”\e[35;40mHello there \e[32;40mmate\r\n”}
{ili_status:”All working exceedingly well”}
{ili_title:”\e[37;40mESP8266 Status Monitor”}

In addition to the above, {ili_rssi} puts the time and date down in the status area AND puts a nice phone-like RSSI indicator on the bottom right, showing the current WIFI signal strength of the ESP board. {ili_reset} resets the display after clearing it – to show the header and the LED rectangles on the top.

If you want to experiment with lines – and remember this is going via MQTT so don’t plan on making complex objects…  {ili_line:x1,y1,x2,x2,colour} but YOU WILL need to clear the screen first –  you can do that with  {ili_text:”\e[2J”} and when you’re done you can return the display to normal with {ili_reset}

{ili_pixel:x,y,colour} will draw a dot. {ili_rect:x1,y1,x2,y2,colour,background_colour} will draw a filled rectangle.
{ili_string:x1,y1,string} will position a string at an arbitrary location
{ili_fore:colour} will set the foreground colour for future strings
{ili_back:colour} will set the background colour for future strings

All of the above require that you clear the screen – you cannot do the scrolling terminal – and arbitrary text and lines at the same time but this does add a lot of flexibility (which I thought of much later than when I wrote this article originally).

The manual that comes with the bitbucket download is updated with new commands.

Hence by firing serial or MQTT commands at the board, I can get stuff onto the display.  To monitor all MQTT traffic was easy – over to the Pi and MQTT..

In Node-Red – a simple MQTT node picks up all traffic, passes it to a function – which then passes the result to the board which in this case is called “thisone”.

tmpPayload=”  “ + msg.payload;
if (msg.topic!=”thisone/toesp”)
msg.payload=”{ili_text:\”” + tmpTopic + tmpPayload + “\r\n\”}”;
return msg;

DisplayHence the board gets all traffic except for traffic destined for the board (which could end up in an infinite loop).

And now thanks to a conversation with reader Bob Green –  a WIFI signal strength (RSSI) indicator for the board and the time in the bottom left. I deliberately left the seconds out as this would typically not be refreshed that often – maybe every couple of seconds…

Bob suggested that by plugging the board into a battery pack you have a simple range tester and he’s absolutely right of course. Now, how to teach it to make coffee…

On the subject of terminals

No need to talk about VT100-type terminals for PCs – they’re coming out of our ears – but…


I’d put this all together and I thought…an 80 line or 132 line version of this would be nice – I’ll put one on my Android phone. Well, you may well write in and tell me I’m wrong but I cannot find a VT-100 compatible serial modem for Android anywhere (I did find one but it was not clear if scrolling regions worked and it had a limited range of serial settings). Surprising considering that it can be done on a  relatively simple unit like the ESP8266


And that led me to Linux – or rather – I was thinking about the various single board computers I have lying around – a Pi would do but I have a rather nice FriendlyArm NanoPC T2 which was not quite fast enough for Android but runs a nice Debian.  I started looking for fancy graphical terminals – not a lot – nothing to anywhere near TOUCH some of the stuff on Windows – however I had this T3 with a little 7″ LCD touch screen lying around and was determined it would not go to waste.

It turns out that the humble LX terminal does at least some VT 100 – but that pulls up a command line and lets you interact with it  -was there any way to get it to talk to serial instead – preferably one of it’s own rather than a USB serial as it has FOUR serial ports on it.

Well, yes. I discovered this..

cu -l /dev/device -s baud-rate-speed

It looked as if this would let me use the terminal with serial instead of a keyboard- but of course when I tried it using:

cu -l /dev/ttyAMAT3-s 115200

I got zilch. The system didn’t have a clue what CU is (neither did I for that matter).

Anyway, just for a laugh I tried SUDO APT-GET CU

And it worked. I tried again. THIS time all was well – but it could not contact the serial port – as it was “busy” – yeah right.

I added user FA (the user in control of that terminal session) to the relevant group – no difference – so as is often the case I just gave 777 permissions to the serial port and VOILA.

Terminal on Debian running serial

I tested some colour escape sequences from my PC Serial Terminal I wrote some time ago (and just recently updated to let me put ESC in there) and all worked well but for some visible representation of the ESCAPE sequences (which still worked). I continued experimenting and the UX terminal that comes with Debian LDXE does not suffer that particular issue – so it has the job!!!


Sunday Morning Experimenting

I figured after a couple of horrendous days figuring out what was wrong with my ROMS, it was time for a morning’s relaxing.  Some time ago I added I2c to the Home Control software but never actually got around to doing anything with it.  The i2c parallel expansion modules I got from Ebay have their own pull-up resistors on them… could I get away with hooking 2 boards up without having to dismantle surface-mount pull-ups on on?

test ledsSo first things first I wired up some test LEDs comprising a some AQUA LEDs I had lying around and 120r resistors. I looked all over for pre-made leads with female 0.1” connectors on them but as usual ended up making up my own. If anyone knows of a good cheap source of these – do let us know in here.

Next stop I needed a test board and the obvious one to use was one of the samples I got from Bob Elmour.

A few extra ground, 3v3 and 5v lines (0.1” connector strip) along with GPIO4 and GPIO5 brought out and I was in business. Ok, not the prettiest layout but good enough for testing.

And… yes, I’m not sure I’d want to go beyond two without removing resistors – but they work. With one DIP switch set to ON-ON-ON and the other to ON-ON-OFF I found I could easily use i2c to turn on and off LEDS on both boards at addresses 39 and 38 respectively.

ESP8266 board

It is worth noting that the output DRIVE capability of the little red boards is not that good (as the outputs are also used as inputs with pull-ups) and so to get a decent output I fastened the LED + leads to +3v3 and used the expander boards to SINK current (which means the output logic is inverted).

Using the come control software, lighting up those 4 LEDS is simple.



(The zero is a recent addition and simply says there is nothing being returned. See future blogs for more extensive use involving multiple parameters and an optional return value).

So for the loss of 2 wires, you get 16 outputs using I2c and at a cost for boards of around a fiver. Not entirely sure how well that compares to sticking an ATMEGA24560 onto the ESP and doing some custom software to let you control the outputs (I have thought about this)… but it is certainly one easy way to get more inputs and outputs.



After a slight hiccup with the new board (LED track missing) here’s the new board  – link for PCB here – as you can see, Aidan has made several improvements – smaller buttons, connector for DHT22 etc, markings for I2c (right now I only have support for the 8-output expander discussed elsewhere but more will follow as time permits) and general tidy up. Both the original LED and the new RGB LED are included – personally I find coloured lights for status a lot more useful than a flashing light – but of course they can use more power. As well as the LCD project this board has become a general purpose ESP-12 board and I now would not use any other.  We’ve not wasted cost putting USB on it because FTDIs are cheap and that reduces the end cost of the board.   The link above has all the files – please note we’ve NOT had delivery of these, the previous version was almost the same and works but for a track on the WS2812b.. so it is highly likely this board will be just fine – will be a couple of weeks or so before we know (delivery from China) and another week before I get my hands on one (Aidan is in the UK, I’m in Spain). The I2C markings are just to make it easier to remember which pins you use – we didn’t have enough room for yet another 4-way connector. If you are looking in for the first time – see the Nextion WIFI Display blog and the Home Control 2016 blog.

I’ll be trying this out on a brand new Nextion board I just received (faster processor I think – not tested yet – will blog when I do) along with some other stuff from Itead

Enjoy. For my next trick – a new board from SEEED…. review coming up later.




ESP12 and Memory

Anyone writing large projects with the ESP units in C (and probably in other languages without necessarily realising it) will have come across the problems of .TEXT memory. This is the RAM used to store functions.

Functions are stored in their own part of RAM called .TEXT memory and it is WAY too small. Now most of you will have made liberal use of the “ICACHE_FLASH_ATTR “ directive in your functions. This ensures that functions stay in FLASH until actually needed and this saves lots of .TEXT RAM – indeed without it, larger programs would be impossible.

Despite all of that I’ve been slowly running out, sitting at 7CFF  (you can only go up to 8000) recently and when the latest API came out – that was it – over the top – dead.

So for a while I stuck with the previous SDK and eventually got onto Espressif.

They asked me for a .DUMP file – which of course I neither had nor understood and they suggested that in the project directory I type:

xtensa-lx106-elf-objdump -x -s app_0.out > app_0.dump

WELL I was convinced this was another Linux tool that would not work in Windows – but it DID and produced the English-readable file app_0.dump which tells you where all your functions are sitting.

They suggested I add the “ICACHE_FLASH_ATTR”  to my EASYGPIO functions. Well of course as that was an existing library I’d not touched that – and sure enough – I got just enough memory back to be able to use the latest SDK!!   I was now sitting at 7B52 on the latest SDK – not good – but better… and at least I was using the latest SDK. They then suggested I use “os_memcpy, os_memset, os_strcpy” instead of “memcpy, memset, strcpy” so I systematically went through all the code and did this.

On recompiling – I now find the .TEXT RAM sitting at 79C2, the lowest it has been for AGES – another 512 bytes back just by using their functions instead of the standard ones!

I’m making no claims about reliability as I’ve not given this a thorough test – but that is for me a very worthwhile improvement in memory. Of course that means a tiny slow-down as functions have to be pulled out of FLASH to use… What speed would we have gotten out of these devices if they’d just done the RAM differently. Still – given the price of ESP devices I suppose we can’t complain.


ESP 32 Unofficial Development Kit

Michael Grigorev has released a Beta version of Unofficial Development Kit for Espressif ESP32 (Windows)

From Michael:

The kit includes the following components and tools:
* Unofficial GCC compiler for SoC Xtensa L108.
* Official Espressif ESP32 RTOS SDK v1.1.0
* Documentation for SoC ESP32.
* Examples in the firmware source code in C language.
* Additional tools for working with boards based on the ESP32.

Instructions for installing and configuring the Unofficial Development Kit for Espressif ESP32:
1. Download (114Mb) and install my Unofficial Development Kit for Espressif ESP32.
2. Download and install the Java Runtime x86 (jre-7uXX-windows-i586.exe)
3. Download and install Eclipse Mars x86 to develop in C ++ ( Unpack the archive to the root of drive C.
4. Download and install MinGW. Run mingw-get-setup.exe, the installation process to select without GUI, ie uncheck “… also install support for the graphical user interface”.
5. Download the (84Mb) my scripts to automate the installation of additional modules for MinGW.
6. Run from my file install-mingw-package.bat. He will establish the basic modules for MinGW, installation should proceed without error.
7. Start the Eclipse Luna from the directory c:\eclipse\eclipse.exe
8. In Eclipse, select File -> Import -> General -> Existing Project into Workspace, in the line Select root directory, select the directory C:\Espressif\examples\ESP32 and import work projects.
9. Edit the Makefile, correct COM port number in the parameter ESPPORT and SPI_SIZE_MAP.
Further, the right to select the Make Target project, such as esp32_hello_world and run the target ‘all’ the compile project, while in the console window should display the progress of the build. Run the target ‘flash’ for burn firmware.

Official website of the ESP 32 unofficial development project


ESP 32 Update

An update for you. As you may know the ESP-32 is Espressif’s latest venture, a new, hopefully more powerful alternative to the ESP8266 – with Bluetooth 4 and all sorts of other goodies.  I received my ESP-32 module this week along with 0.1” header adaptor board. All very nice you say but what to do with it. I’m still waiting for Espressif to provide a simple diagram for programming – i.e. what pins on the adaptor need pulling up/down and when…  no point in experimenting when you don’t have a backup. (Update: See below).

tmp2D54AND they are all out of beta tester copies – but the GOOD news is for all you budding Windows programmers (like me) – there is a PRELIMINARY copy of the unofficial development kit sitting on my desk waiting for that pin-out info. I got in touch with Michael Grigorev, developer of the fabulous “kit” for Windows which gives us the Eclipse editing and compiling environment without having to dabble in Linux commands… and he is indeed developing an ESP-32 version… sadly because he missed the boat on the beta program it looks like I might have to send mine over to Russia! Well, chicken and egg – can’t program the chips without an environment – got to be hard to make the environment without the chips! Currently the test environment compiles a “hello world” program – ok, not a lot of use but it’s a start.

Finally – our thanks to reader NELSON for bringing this to our attention – just exactly what is needed to start the ball rolling!!!

The pin-out of the adaptor board provided to beta testers is pin mapped to the ESP-31 (which is a kind of engineering sample of the ESP-32 and there are unlikely to be significant differences between this and the final product). The only exception being that pin 19 on the baseboard is grounded – to pin 15 which is out of sync, all other pins follow the ESP31 as you’d expect.


If you know more, do let us know in here.


ESP32 Arrival

And here it is – the ESP32 – or rather the ESP-32 development kit. Mine is in a batch that is running late so my pal has given me his to play with.


I figured I’d take a pic in my hand so you can gauge size. This tiny box is what you get – and inside it – precious little! As you ESP32will see below, you get the ESP32 board itself and an adaptor – complete with pins – so you can do some prototyping – so the first thing you’re going to need here is a fine soldering iron bit and some fine solder as the two boards solder together with some pretty close connectors – you should be able to better see these boards by clicking on the image for a larger version.

And that is what comes in the box – no instructions, nothing – next step is to find out what to actually do with this stuff – can’t wait to get my first flashing light running – I can see another learning curve coming on. A link or something would have been nice…