StepperMotor + OLEDwithEncoder Navigation - Interruption Issues

Hi Community!

I have a new Project where I am working on.
With an ESP32-Wroom Board I try to implement the functionality of an Stepper Motor which should spin in different directions. For Settings//Navigation and so on, i also added an KY-040 Rotary Encoder and an I2C OLED Display. Also, a active BLE Connection is active.

So far so good - developement was done in two different branches, the encoder+the navigation in the OLED Display works great and also the stepper functionality is like it should be in combination with BLE.

My Problem is now, if I am marrying those two parts together everything works as excepted BUT ONLY(!!!) if the Encoder stays untouched! The ISR used to check the encoder state is interrupting in such a way, that the stepper stucks visibile and turns like it should if the encoder is in its final position :frowning:

Does somebody else have experience with an behaviour like this and can help me to solve that problem?
My first thought was, I move the Stepper Motor Control function to core 1. But I am not sure how to do this and another aspect is, that the whole BLE functionality is still running in core 1…

Stepper Functionality in main loop is quite simple:

if(StepperRunning && StepperDirection){
way = TURNFULL;
StepperDirection = false;
//DEBUG_SERIAL.println(“Direction CLK”);
StepperRunning = false;
}else if (StepperRunning && !StepperDirection){
way = -TURNFULL;
StepperDirection = true;
//DEBUG_SERIAL.println(“Direction CCLK”);
StepperRunning = false;
}

if (!StepperRunning){
StepperRunning = myStepper.runToPosition(way);
}

the runToPosition Class Function i use is:

bool StepperControl::runToPosition(long absolut){

if(_positionNEW != absolut){
    _Stepper->setCurrentPosition(0);
    _Stepper->moveTo(absolut);
    _positionNEW = absolut;
    DEBUG_SERIAL.print("[Stepper] New Position Recieved: ");
    DEBUG_SERIAL.println(_positionNEW);
}

if((_positionNEW > stepperPosition() && _positionNEW >= 0) || (_positionNEW < stepperPosition() && _positionNEW < 0)){
    
    if((_Stepper->speed() >= _maxSpeed && _positionNEW >= 0) || (abs(_Stepper->speed()) >= _maxSpeed && _positionNEW <0)){
        _state = RSPD;
    }

    switch (_state){
        case RSPD:
            _Stepper->runSpeed();
            break;
        case RJSTR:
            _Stepper->run();
            break;
        default:
            break;
        }

    return false;
}else{
    _state = RJSTR;
    _positionNEW = 0;
    DEBUG_SERIAL.print("[Stepper] Position reached! ");
    DEBUG_SERIAL.println(_Stepper->currentPosition());
    return true;
}

};