Arduino single core limitation driving VL53L0X and TB6600 together

I am new to the Arduino world, but have some propeller chip (8 cores) experience.

Am I asking too much from a single core processor?

I am using a Seeeduino XIAO which runs at 48MHz (SAMD21G18) to communicate to my TB6600 stepper motor driver. I am utilizing the AccelStepper.h library. The motor is used in a continuous turning motion and I am pushing it to it's speed limit with 1/4 steps using stepper.setMaxSpeed(5000);.

Now I would like to add this VL53L0X Time-of-Flight (ToF) Laser Ranging Sensor as feedback loop into the mix. Is it recommended to dedicate the sensor communication task to another Seeeduino or can both codes be run simultaneously on just one core?

I had a look at Using FreeRTOS multi-tasking in Arduino - Arduino Project Hub but it looks like it adds an extra layer to the code.

The Uno is too 'small' to run much of freeRTOS. The ESP32 has freeRTOS built in and does a great job of multi tasking. Also, the ESP32 has 2 processors. One processor has 2 cores. Both cores and the other processor can all be running different code at the same time.

With that, take a look at the doing more then one thing at the same time tutorial. Using millis() a basic task switcher can be made with the Uno and Mega.

The DUE can run uMT which is, like freeRTOS, a RTOS. uMT runs really well on the Due as a multi-tasker.

In case you missed it, OP is not using an UNO :wink:

BOINK! Thanks for the pointer.

I had a second look at FreeRTOS and it looks promising. It sounds like a perfect fit with the extra RAM and speed a Seeeduino provides. Now I just need to wrap my head around it.

Datasheet for the sensor? How does it communicate?

The AccelStepper library is designed to multitask easily - just call run() frequently.

link to vl53l0x datasheet
I ordered from Amazon
this is the continuous_ranging sketch in the example library provided by Seeeduino:

#include "Seeed_vl53l0x.h"
Seeed_vl53l0x VL53L0X;
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
    #define SERIAL SerialUSB
#else
    #define SERIAL Serial
#endif
void setup() {
    VL53L0X_Error Status = VL53L0X_ERROR_NONE;
    SERIAL.begin(115200);
    Status = VL53L0X.VL53L0X_common_init();
    if (VL53L0X_ERROR_NONE != Status) {
        SERIAL.println("start vl53l0x mesurement failed!");
        VL53L0X.print_pal_error(Status);
        while (1);
    }
    VL53L0X.VL53L0X_continuous_ranging_init();
    if (VL53L0X_ERROR_NONE != Status) {
        SERIAL.println("start vl53l0x mesurement failed!");
        VL53L0X.print_pal_error(Status);
        while (1);
    }
}
void loop() {
    VL53L0X_RangingMeasurementData_t RangingMeasurementData;
    VL53L0X.PerformContinuousRangingMeasurement(&RangingMeasurementData);
    if (RangingMeasurementData.RangeMilliMeter >= 2000) {
        SERIAL.println("out of ranger");
    } else {
        SERIAL.print("distance::");
        SERIAL.println(RangingMeasurementData.RangeMilliMeter);
    }
    delay(100);
}

I think my main time constraint is how long it takes to communicate with the VL53L0X chip. I have not timed it and was just about to do that. On the stepper side, the motor can be run up to 1000 RPM. At 200 steps per round that is 3,333 pulses per second with 1:1 stepping. With 1/4 micro stepping the pulse per second required is 13,333. The pulse has a high and a low ... so it would call for 26,666 polarity switching per second along with some time between this. My Seeeduino runs at 48MHz, so that should be no problem.

I understand that the only line of code needed in the loop is

void loop() {
  readDistance();
  ...
  run();
}
void readDistance() {
  VL53L0X_RangingMeasurementData_t RangingMeasurementData;
  VL53L0X.PerformContinuousRangingMeasurement(&RangingMeasurementData);
  mm = RangingMeasurementData.RangeMilliMeter;
}