Tag Archives: ESP32 First Steps

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);
Serial.begin(115200);
}

void loop()
{
Serial.println("Hello, world!");
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
}

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.

Facebooktwittergoogle_pluspinterestlinkedin