Norway


Whether you’re a newbie or a seasoned developer in the field of , 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 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.

- 1 rjZ6E54mYw0sJ18mf ElyQ - Multicore Arduino, the Easy Way

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 0 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 - 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.

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

- 1 pdU0lujYlNgPNwbB0fgstQ - Multicore Arduino, the Easy Way
- 1 mSYFhqJ1pr4ywqL5R9jK9A - Multicore Arduino, the Easy Way

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

- 1 dnRCb3D8w8iZFt9B67bz g - Multicore Arduino, the Easy Way

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

- 1 ZUlgMGNOvZhskKUVHMxuIw - Multicore Arduino, the Easy Way

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

- 1 pDCEORPWZWeXD0zyHKN7TQ - Multicore Arduino, the Easy Way

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.

- 1 HFGaXXOGCC777JHgg xXcg - Multicore Arduino, the Easy Way

Step 5: Programming the Sub ores

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

- 1 pdU0lujYlNgPNwbB0fgstQ - Multicore Arduino, the Easy Way
- 1 RK13Z6Oy rOjNKtrDFslaA - Multicore Arduino, the Easy Way

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.

- 1  G7MHi80VXBPoFOUb71jPw - Multicore Arduino, the Easy Way

Step 6: Compile and Upload the Sub Core Sketches

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

- 1 JTkUkXEJupIdRJ0HufMCog - Multicore Arduino, the Easy Way

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:

- 1 xj7CBBmJJMfe5KRgL8F qA - Multicore Arduino, the Easy Way

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.

- 1 8 YOyZPmY2Lhloa6m aPpQ - Multicore Arduino, the Easy Way

- stat event post - Multicore Arduino, the Easy Way


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.



Source link

LEAVE A REPLY

Please enter your comment!
Please enter your name here