Multicore Arduino, the Easy Way




Whether you’re a newbie or a seasoned developer in the field of Arduino, the likelihood is more than high that you’ve only done single core programming up until now. There’s nothing to be ashamed of; in fact, I did my first multicore programming using the Arduino IDE just a few days ago. I, and all the other Arduino fans, are simply in love with the ease of use of the IDE and the minimum configuration required to get started with microcontroller development. That very same environment, and the almost complete absence of any complex setup, can now be used for multicore development.

We’ll show you how to program six parallel MCU cores in just a bit, but first let’s reason why several cores are better than one.

Why Use Multicore?

If your project is about reading a sensor value or making an LED blink every now and then without any complex calculations, it probably doesn’t really matter whether your board’s MCU has one or 100 cores. The speed and performance of your application is most likely to be very similar — at least from what a human being can perceive. However, with several cores, you can develop far more advanced solutions with complex algorithms and computations, such as FFT analysis, gesture recognitions, edge computing, predictive maintenance, and even simple real-time 3D renderings. Below, we’ll go through how to leverage the Arduino IDE for multicore programming using Sony’s Spresense. This board not only has six parallel Arm cores, but the clock speed of them is 156 MHz. Still, the board is power efficient enough to run on battery if needed.

Now, let’s get to it!

Step 1: Install the Spresense Board with the Arduino IDE

The Spresense Arduino package version 1.3.0 and newer supports multicore programming using the Arduino IDE. If you haven’t installed it already, the easiest way to do it is to follow the steps on the Spresense developer website.

Step 2: Opening the Sample Code

The example we’ll be using for Arduino multicore programming employ one main core and four sub cores.

From the File menu in the Arduino IDE, open the example:
File → Examples → MultiCore MP → Boot → Main

This main.ino sketch includes the MultiCore MP library and boots each sub core usingMP.begin(subid) in a For loop:

Step 3: Compile and Upload the Main Core Sketch

In order to upload the sketch to the correct core of the Spresense board, select MainCore from the Arduino IDE Tools menu: Tools → Core → MainCore

Next, press the Upload button to compile and upload the main core sketch to the Spresense board:

Step 4: A Quick Pre-Test

If the upload was successful, the main core is now programmed. As a quick pre-test, you can open the Serial Monitor and observe the print-out. As you notice, the main core is running fine while there’s an error reported for each of the sub cores since we haven’t yet programmed them. This is what we’ll do in the next step.

Step 5: Programming the Sub ores

From the Arduino IDE File menu, open:File → Examples → MultiCore MP → Boot → Sub1

In the setup() function, MP.begin() notifies the main core that start-up of the sub core is complete. In the loop() function, MPlog() prints out “loop” for each iteration and flashes the first LED.

Step 6: Compile and Upload the Sub Core Sketches

Select SubCore 1 from Arduino IDE Tools menu:Tools → Core → SubCore 1.

Press the Upload button to compile and upload to the sub core sketch to the Spresense board.

Now, repeat step 5 and 6 to compile and upload the sub core sketches 2, 3, and 4.

Step 7: The Final Test!

If all the sub core sketches uploaded correctly, the four LEDs are blinking and the Serial Monitor shows a log print-out from all the cores:

Voila! (Yeah, that’s fancy French for “wow, I can’t believe I just did my first Arduino multicore programming!”)

If you’d like to program all the cores in one sketch, follow the Multicore MessageHello example on the Spresense developer website. For more in-depth details on multicore programming using the Arduino IDE, check out the Spresense Arduino IDE developer guide.

Additional sample projects based on the Spresense board can also be found on Hackster.


Multicore Arduino, the Easy Way was originally published in Hackster Blog on Medium, where people are continuing the conversation by highlighting and responding to this story.





Original article: Multicore Arduino, the Easy Way
Author: Daniel Sandblom