Using Multiple Processor Cores on the ESP32
/Most computers, particularly tiny embedded ones, have a single processor core. This means that they can do just one thing at a time. If you want a computer like this to appear to perform multiple actions at the same time it must execute a tiny “slice” of each action in turn to give the illusion of parallel activity.
However, the ESP32 has two processor cores, which means that it can run two “threads” of execution in the same program code. This has suddenly become very interesting to me, as I don’t want the LEDS to flicker when the computer controlling them has to go off and talk to the network.
It turns out that running tasks on different processors in the ESP32 is actually pretty easy. I used this guide here to get started. Then I slightly changed my program so that the code that drives the leds runs on one thread and the code that talks to the network runs on another.
It just worked. I was amazed. And there was no flicker on the display. One core in ESP32 is continuously running a function that redraws the display and the other core is waiting for network messages.
If you’re wondering how it all works, and whether you can get your hands on the code, I’m going to write a howto and put the whole thing on GitHub really soon.