Search code examples
carduinowifimulticoreesp32

Core 1 and 0 of ESP32 not working seperately


This is my code

#include <WiFi.h>
//#include "StepperMotor.h"
#define SDA_PIN 4
#define SCL_PIN 5

const char* ssid = "StepperMotorWireless";
const char* password = "";


WiFiServer server(9090);
WiFiClient client;

char buffer[50] = {0};
int buffercounter = 0;

TaskHandle_t StepperHandler;
TaskHandle_t WifiHandler;

void setup()
{
  Serial.begin(9600);
  SetWifi(ssid, password);
  pinMode(2, OUTPUT);

  xTaskCreatePinnedToCore(
    StepperLoop, /* Task function. */
    "StepperHandler",   /* name of task. */
    4000,     /* Stack size of task */
    NULL,      /* parameter of the task */
    2,         /* priority of the task */
    &StepperHandler,    /* Task handle to keep track of created task */
    1);        /* pin task to core 0 */
}

void SetWifi(const char* name, const char* password)
{
  WiFi.disconnect();
  WiFi.mode(WIFI_AP_STA);
  WiFi.softAP(name, password);
  delay(2000);
  IPAddress IP = WiFi.softAPIP();
  Serial.print("Server IP : ");
  Serial.println(IP);
  server.begin();
  server.setNoDelay(true);
  Serial.println("Server Started");
}


void availableMessage() {
  if (client && client.connected() && client.available()) {
    while (client.available()) {
      String message = client.readStringUntil('\n');
      Serial.println(message);
      char temp[50];
      message.toCharArray(temp, 50);
      client.flush();
    }
  }
}

void connectClient() {
  if (server.hasClient())
  {
    if (client = server.available()) {
      Serial.println("connected");
    }
  }
}

void StepperLoop( void * pvParameters ) {
  digitalWrite(2, HIGH);
  delay(1000);
  digitalWrite(2, LOW);
  delay(1000);
}



void loop()
{
 connectClient();
  availableMessage();
}

The problem is that my blinking LED is not 1 second long, so something is interrupting it (appearantly wifi is because that is the only other thing running). That is weird because every on the internet you look, the Wifi task is pinned to Core 0, and I am running my blink code on Core 1, so that should not be interfering.

I cant seem to fix this, could someone help me out?

BTW I am using arduino IDE


Solution

  • What does not blinking 1 second long mean? Have you measured the time or could you see it directly?

    Your LED/Stepper loop is not a loop! If you what the LED to blink more than once:

    void StepperLoop( void * pvParameters ) {
        while (1) {
            digitalWrite(2, HIGH);
            delay(1000);
            digitalWrite(2, LOW);
            delay(1000);
        }
    }