Moving on from Arduino to ESP32 – Part 1

Arduinos are great little things. With the analog and digital inputs and outputs, plenty of power and memory for your programming sketches, a solid IDE (integrated development environment), small price, and a wealth of examples to teach yourself the variant of C language, what’s not to like, really?

But at some point you will want to move on from local to global systems and connect to the Internet with your devices. You can do that with Arduino, no problem – just get an Ethernet shield for it, or a WiFi dongle. Or if you need a SIM card connection, it’s possible too, just add a shield. Bluetooth is available as a little connection board, you don’t even need a shield – just use some jumper wires. But sometimes space is at a premium and you just need something smaller to get you connected.

“ESP32-WROOM-32 is a powerful, generic Wi-Fi+BT+BLE MCU module that targets a wide variety of applications,
ranging from low-power sensor networks to the most demanding tasks, such as voice encoding, music streaming
and MP3 decoding. At the core of this module is the ESP32-D0WDQ6 chip*. The chip embedded is designed to be scalable and
adaptive. There are two CPU cores that can be individually controlled, and the CPU clock frequency is adjustable
from 80 MHz to 240 MHz. The user may also power off the CPU and make use of the low-power co-processor to
constantly monitor the peripherals for changes or crossing of thresholds.” -Espressif website

ESP32, Bluetooth adapter, and Arduino Uno

As soon as you start thinking of expanding your realm from you desk to the Internet, you will come to see that ESP32 may be the way to go. Or some other similar product, such as Pycom’s SoCs which are also very popular and have a wide range of available models. I just happened to get the ESP32 WROOM kits because they were the first on eBay when I searched for ESP32 based systems. I also had set my eyes on Zerynth, which offers an ecosystem and a very nice IDE for using Python, but more on that later.

What language to use on your ESP32?

You have in your hands a system-on-a-chip that you can go straight over to from Arduino. You can add ESP32 support to your Arduino integrated development environment by following this excellent Random Nerd Tutorial’s blog post and keep on doing stuff with C. This is the nice way, since the C libraries and other material needed to use ESP32 in your WLAN are all there. But you’re not limited to just that. You can go forward and bring in the power of Python, which is one of the most popular languages today.

This is where the path diverges.

C is a compiled language. Whatever you code in it, the Arduino IDE will compile into an executable program, which it then flashes onto the chip you are using. Python, then, is an interpreted language. Its code is executed at runtime, one line at a time. This means that you have to have something sitting on the chip that will interpret your code and cause the magic to happen.

The usual solution is to install MicroPython on your SoC. This is a somewhat lengthy procedure, better handled by people who have experience of GitHub (the open source software repository) and Linux or Unix, but it is entirely doable. I managed it, so it’s very likely that a more clever person will manage it too. I am not saying it was easy, and for the most part, you have to follow the instructions to a T. I will write up a part 2 to this post showing you how to work with MicroPython.

ESP32 and Arduino SIM card shield

Zerynth and MicroPython

Zerynth, which I mentioned above, is a little different. They have opted to develop their own virtual machine, which sits on top of the ESP32 and is able to use Python.

The core of Zerynth is the Zerynth Virtual Machine, a multithreaded Real-Time OS that provides real hardware independence, allowing code reuse on a wide range of 32-bit microcontrollers, in just 60-80kB of Flash and 3-5kB of RAM.

Zerynth VM has been developed from scratch with the goal of bringing Python to the embedded world with support for multi-thread and cross board compatibility. It supports most high-level features of Python like modules, classes, multi-threading, callback, timers and exceptions. In addition to these, it allows to use custom hardware-related features like interrupts, PWM and digital I/O. -Zerynth website

This sounds great and is great too. Zerynth saves you space in the memory of your ESP32 as compared to MicroPython. However, for people like me who aren’t fully able to comprehend the finesses of C and Python, there is a snag. In developing the virtual machine, Zerynth has written its own modules a little differently from the basic MicroPython flavor usually seen on SOCs. Again, this is no problem if you’re good, but for a two bit hacker like me, it’s problematic, since many of the examples needed to learn how to add sensors, displays and the like aren’t available yet in the Zerynth world.

A case in point is my recent work in bringing the Morse Moai statue into the Internet. For that, I needed WLAN connectivity, and a method for reading content off the Web so I can change the message shown by the Moai. When I got my ESPs, I went the Zerynth way, and got my system not only connected to the WLAN, but to read the message from there and do the Morse code song and dance. But when I started to work on doing a LCD display, or the ultrasound distance sensor installation, I ran into a wall.

The examples I found were all written for MicroPython, not the flavor of Zerynth. Despite some assistance from the Zerynth team and their forums, I didn’t manage to take MicroPython modules and convert them to Zerynth. This has now come to the point that I have installed MicroPython, and am now in the process of converting my Zerynth Python code to suit my MicroPython system. I have by now managed to do the LCD and ultrasound integration and will soon port the rest of my Morse Moai from Zerynth.

What do you need to decide?

The decision tree is like this:

Arduino or ESP? If you don’t envision connectivity needs, there may well be a case for continuing with Arduino.

Also, if you don’t think you will be needing to change the language you use to Python or some other language, Arduino will do nicely.

If you want to start doing real IoT devices, you will face connection needs.

Arduino has Bluetooth and WLAN and phone network connection, so check those first.

If you need a single board due to space issues or power problems, look into the ESP32 type of things.

See if Pycom’s devices work for you – they have a nice ecosystem and an IDE for their own systems, but I am not 100% sure that their code is all open source.

If being fully open source is necessary, check MicroPython on ESP32

When you go the MicroPython way, you can still use free tools. In the Part 2 of the ESP32 post, I will show you how to install MicroPython and use uPyCraft to write your code for the fantastic tool that is ESP32.