Here is the simplest way to get code running parallel with two separate cores on the ESP32.

TaskHandle_t core0;
TaskHandle_t core1;

void setup() {
// setup  void core0code() subroutine on core 0 with priority 1
   xTaskCreatePinnedToCore( core0code, "core0", 10000, NULL, 1, &core0, 0);   
    
// setup  void core1code() subroutine on core 1 with priority 1
   xTaskCreatePinnedToCore( core1code, "core1", 10000, NULL, 1, &core1, 1);   
       
   pinMode(26, OUTPUT);  pinMode(27, OUTPUT); //setup 2 Gpio's for demo
  }

void loop() {
  // isnt this weird no code in the main program loop,
  // yes it can be used (don't quote me at momo but its attached to core 0... i think!!)

  }    

void core0code( void * pvParameters ){
  for(;;){     // for(;;) {  }  creates an endless executable loop...
   digitalWrite(26, HIGH);  delay(444);
   digitalWrite(27, LOW);   delay(555);
        }
}

void core1code( void * pvParameters ){
  for(;;){
   digitalWrite(26, LOW);  delay(666);
   digitalWrite(27, HIGH); delay(777);
         }
}

 

GroG

5 years 7 months ago

Wow Gareth ! 

I was just getting it primarily for the wifi - but 2 cores & bluetooth as well ?
Thanks for the guidance .... now just have to wait ..

is it here? ... nope..
is it here? ... nope..
is it here? ... nope..
is it here? ... nope..

...

Indeed Bluetooth&Wifi ... though they cannot (as yet) be used at the same time...

I have used the split cores on a number of projects here... its just great to load a core with code and basically forget it. (no issues to date...YAY).

Cavet :- if you are using the Serial.print (to console) in both core then you are asking for some interesing results.....(trust me on that one ;-)