0

members

Easy Basics: Project 076d ESP32 Development board - Dual Core with Arduino IDE

of Acoptex.com in ESP8266 ESP-32

Basics: Project 076d

Project name: ESP32 Development board - Dual Core with Arduino IDE

Tags: EESP32 Dev Module, ESP32 development board, ESP32 Development board with WiFi and Bluetooth, ESP32-DevKitC V4 development board, ESP-WROOM-32 module with ESP32‑D0WDQ6 chip, Espressif Systems, ESP32-based development board, ESP32 modules, ESP32-WROOM-32, ESP32-WROOM-32U, ESP32-WROOM-32D, ESP32-SOLO-1, USB-UART bridge, IOT, ESP-WROOM-32 Dev Module, ESP32 DEVKITV1, Installing the ESP32 Board in Arduino IDE, Uploading sketch, ESP32 Development board, Dual Core with Arduino IDE

Attachments: testsketchfinalsketch

In this project, you need these parts :

1. ESP32 development board with WiFi and Bluetooth and USB A / micro USB B cable 1 pc

2. Arduino IDE ( you can download it from here  )

3.Jumper cables F-M

4. Resistor 2 pcs (220 Ohm each)

5.LED 2 pc (can be of different color)

 

6. Breadboard 1 pc

General

We will learn how to run code on the ESP32 development board second core by creating tasks.

The ESP32 development board comes with 2 Xtensa 32-bit LX6 microprocessors: core 0 and core 1. So we speak about dual core. When you run code on Arduino IDE it runs on core 1 by default. We will show you how to run pieces of code simultaneously on both cores and make your ESP32 development board multitasking. However you don’t necessarily need to run dual core to achieve multitasking.


Understanding the ESP32 Development board with WiFi and Bluetooth

You can read more about it here.

Signals and connections of the ESP32 Development board with WiFi and Bluetooth

You can find more information (datasheets, schematics, pins descriptions, functional desgn descriptions) about each board (made by Espresiff Systems) by pressing Getting started link close to each board here.

Let's check our development board - ESP32 DEVKITV1with ESP-WROOM-32 module from Espressif Systems:

Pinout diagram for the ESP Wroom 32 breakout:

ESP32-WROOM-32 - ESP32-WROOM-32 module soldered to the development board. Optionally ESP32-WROOM-32D, ESP32-WROOM-32U or ESP32-SOLO-1 module may be soldered instead of the ESP32-WROOM-32.

USB-UART Bridge - A single chip USB-UART bridge provides up to 3 Mbps transfers rates.

BOOT button - Download button: holding down the Boot button and pressing the EN button initiates the firmware download mode. Then user can download firmware through the serial port.

EN button - Reset button: pressing this button resets the system.

Micro USB Port - USB interface. It functions as the power supply for the board and the communication interface between PC and the ESP module.

TX0, TX2 - transmit pin. GPIO pin

RX0, RX2  - receive pin.  GPIO pin

3V3 (or 3V or 3.3V) - power supply pin (3-3.6V). 

GND - ground pin.

EN - Chip enable. Keep it on high (3.3V) for normal operation.

Vin - External power supply 5VDC.

Wiring

Step by Step instruction

The ESP32 is currently being integrated with the Arduino IDE like it was done for the ESP8266. There’s an add-on for the Arduino IDE that allows you to program the ESP32 using the Arduino IDE and its programming language.

1. Installing ESP32 add-on in the Arduino IDE (Windows 10 OS)

  1. Download and install the latest Arduino IDE Windows Installer from arduino.cc
  2. Download and install Git and Git GUI from git-scm.com
  3. Search for Git GUI, right-click the icon and select “Run as administrator
  4. Select the Clone Existing Repository option.
  5. Select source and destination. Source Location: https://github.com/espressif/arduino-esp32.git
  6. Target Directory:C:/Users/[YOUR_USER_NAME]/Documents/Arduino/hardware/espressif/esp32
  7. Do not create the espressif/esp32 folders, because they will be created automatically.
  8. Click Clone to start cloning the repository.Wait a few seconds while the repository is being cloned.
  9. Open the folder: C:/Users/[YOUR_USER_NAME]/Documents/Arduino/hardware/espressif/esp32/tools
  10. Right-click the get.exe file and select “Run as administrator“.
  11. You will see that necessary files will be downloaded and upzipped. It will take some time.
  12. When get.exe finishes, you should see the following files in the directory.

2. Uploading test sketch

  1. Plug the ESP32 development board to your PC and wait for the drivers to install (or install manually any that might be required).
  2. Open Boards manager. Go to Tools -> Board -> Boards Manager… (in our case it’s the DOIT ESP32 DEVKIT V1)
  3. Select COM port that the board is attached to (if you don’t see the COM Port in your Arduino IDE, you need to install the ESP32 CP210x USB to UART Bridge VCP Drivers)
  4. Compile testsketch and upload it to your ESP32 development board. If everything went as expected, you should see a “Done uploading” message. (You need to hold the ESP32 on-board Boot button while uploading).
  5. Press the ESP32 on-board EN button to reboot it.
  6. When your ESP32 development board restarts open the Serial Monitor at a baud rate of 115200. You can check the core the Arduino sketch is running on.
  7.  

 3. Uploading final sketch

  1. Do wiring.
  2. Plug the ESP32 development board to your PC and wait for the drivers to install (or install manually any that might be required).
  3. Open Boards manager. Go to Tools -> Board -> Boards Manager… (in our case it’s the DOIT ESP32 DEVKIT V1)
  4. Select COM port that the board is attached to (if you don’t see the COM Port in your Arduino IDE, you need to install the ESP32 CP210x USB to UART Bridge VCP Drivers)
  5. Compile finalsketch and upload it to your ESP32 development board. If everything went as expected, you should see a “Done uploading” message. (You need to hold the ESP32 on-board Boot button while uploading).
  6. Press the ESP32 on-board EN button to reboot it.
  7. When your ESP32 development board restarts open the Serial Monitor at a baud rate of 115200. You will see that Task1 is running on core 0 (Blinks LED1 every 500ms) and Task2 is running on core 1 (Blinks LED2 every second).

Code

1.general info

You can use the following function to identify in which core the code is running: xPortGetCoreID(). If you use this function in your test sketch, you’ll see that both the setup() and loop() are running on core 1.

The Arduino IDE supports FreeRTOS for the ESP32 development board, which is a Real Time Operating system. This allows us to handle several tasks in parallel that run independently. Tasks are pieces of code that execute something. To assign specific parts of code to a specific core you need to create tasks. When creating a task you can choose in which core it will run, as well as its priority. Priority values start at 0, in which 0 is the lowest priority. The processor will run the tasks with higher priority first.

To create tasks you need:

  • Create a task handle. An example for Task1: TaskHandle_t Task1;
  • In the setup() create a a task assigned to a specific core using the xTaskCreatePinnedToCore function. That function takes several arguments, including the priority and the core where the task should run (the last parameter).

xTaskCreatePinnedToCore(

      Task1code, //Function to implement the task

      "Task1", //Name of the task

      10000,  //Stack size in words

      NULL,  //Task input parameter

      0,  //Priority of the task

      &Task1,  //Task handle

      0); //Core where the task should run

  • After creating the task you should create a function that contains the code for the created task. In this example you need to create the Task1code() function. Here’s how the task function looks like:

Void Task1code( void * parameter) {

  for(;;) {

    Code for task 1 - infinite loop

    (...)

  }

}

The for(;;) creates an infinite loop. So, this function runs similarly to the loop() function. You can use it as a second loop in your code. If during your code execution you want to delete the created task, you can use the vTaskDelete() function, that accepts the task handle (Task1) as argument: vTaskDelete(Task1);

2.finalsketch

The sketch starts by creating a task handle for Task1 and Task2 called Task1 and Task2. Then we assign GPIO 2 and GPIO 4 to the LEDs. In the setup() we initialize the Serial Monitor at a baud rate of 115200. We declare both LEDs as outputs. Then we create Task1 using the xTaskCreatePinnedToCore() function. Task1 will be implemented with the Task1code() function. We give the task priority 1 and assign it to core 0. We create Task2 using the same method. After creating the Task1 and Task2 we create the functions that will execute those tasks. The Task1code perfoms LED blinking every 500ms. The Task2code performs LED blinking every second.The loop() function stays empty.

The loop() in Arduino sketch runs on core 1. So, instead of creating a task to run on core 1, you can simply write your code inside the loop().

Summary

We have learnt how to run code on the ESP32 development board second core by creating tasks.

Libraries

  • No libraries required

Sketch

  • See attachments on the begining of this project


Other projects of Acoptex.com
Easy Raspberry basics: Project 26a Raspberry PI Zero W board - Enable SSH of Acoptex.com in Raspberry Pi Zero W 07-01-2019
Easy Raspberry basics: Project 24a Raspberry PI Zero W board - Apache web server of Acoptex.com in Raspberry Pi Zero W 05-01-2019

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 10-11-2018
Viewed: 241 times