Am i reaching the limit of the RPi pico on arduino core?

If i change value of the code for max motor (quantity of 4) speed to 100 steps per second max in that range or slower, the servos stay armed and kind of work like they should but still not exactly perfect. what i mean by that is if i move the servo controls too fast the servos do not react at all.

i am using a raspberry pi pico on arduino core i thought it would be fast enough to process everything as fast as i wanted. when i run the stepper motors at full speed, at up to the set 10,000 steps per second max, the servos will immediately disarm and stop working the instant i start serial control even if i have not moved the controls yet.

i have the controls updating through serial at 60 times per second in every test. even at 1,000 steps per second max the servos do not work. my question is, how can i make the servos function properly while still being able to have some speed on the stepper motors? any performance optimizations available?

will it require a better microcontroller? if so, what microcontroller is fast enough? can a raspberry pi 4 4gb with bms do it? if so, dare i ask what python3 library would be a viable replacement to accelstepper? here is the arduino sketch

#include <Servo.h>
#include <AccelStepper.h>
#include <MultiStepper.h>
#define ENABLE_L 7
#define MODE0_L 6
#define MODE1_L 5
#define MODE2_L 4
#define RESET_SLEEP_L 17
#define ENABLE_R 8
#define MODE0_R 9
#define MODE1_R 10
#define MODE2_R 11
#define RESET_SLEEP_R 16
AccelStepper MotorFL(1, 1, 0); //STEP, DIR
AccelStepper MotorFR(1, 14, 15);
AccelStepper MotorRL(1, 3, 2);
AccelStepper MotorRR(1, 12, 13);
Servo xGimbal;
Servo yGimbal;
boolean newData = false;
const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];
int xGimbalReceive = 90;
int yGimbalReceive = 90;
int MotorFLData = 0;
int MotorFRData = 0;
int MotorRLData = 0;
int MotorRRData = 0;
int MotorFLReceive = 1500;
int MotorFRReceive = 1500;
int MotorRLReceive = 1500;
int MotorRRReceive = 1500;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  xGimbal.attach(18);
  yGimbal.attach(19);
  xGimbal.write(90);
  yGimbal.write(90);
  pinMode(ENABLE_L, OUTPUT);
  pinMode(ENABLE_R, OUTPUT);
  pinMode(MODE0_L, OUTPUT);
  pinMode(MODE1_L, OUTPUT);
  pinMode(MODE2_L, OUTPUT);
  pinMode(MODE0_R, OUTPUT);
  pinMode(MODE1_R, OUTPUT);
  pinMode(MODE2_R, OUTPUT);
  pinMode(RESET_SLEEP_L, OUTPUT);
  pinMode(RESET_SLEEP_R, OUTPUT);
  
  digitalWrite(ENABLE_L, LOW);
  digitalWrite(ENABLE_R, LOW);
  digitalWrite(MODE0_L, HIGH);
  digitalWrite(MODE1_L, HIGH);
  digitalWrite(MODE2_L, LOW);
  digitalWrite(MODE0_R, HIGH);
  digitalWrite(MODE1_R, HIGH);
  digitalWrite(MODE2_R, LOW);
  digitalWrite(RESET_SLEEP_L, HIGH);
  digitalWrite(RESET_SLEEP_R, HIGH);

  MotorFL.setMaxSpeed(10000);
  MotorFR.setMaxSpeed(10000);
  MotorRL.setMaxSpeed(10000);
  MotorRR.setMaxSpeed(10000);
}
 
void loop() {
  recvWithStartEndMarkers();
  MotorFL.runSpeed();
  MotorFR.runSpeed();
  MotorRL.runSpeed();
  MotorRR.runSpeed();
  if (newData == true) {
    strcpy(tempChars, receivedChars);
    parseData();
    MotorFLData = MotorFLReceive - 2000;
    MotorFRData = MotorFRReceive - 2000;
    MotorRLData = MotorRLReceive - 2000;
    MotorRRData = MotorRRReceive - 2000;
    MotorFL.setSpeed(MotorFLData);
    MotorFR.setSpeed(MotorFRData);
    MotorRL.setSpeed(MotorRLData);
    MotorRR.setSpeed(MotorRRData);
    xGimbal.write(xGimbalReceive);
    yGimbal.write(yGimbalReceive);
    newData = false;
  }
}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char PythonRead;
    while (Serial.available() > 0 && newData == false) {
      PythonRead = Serial.read();
      if (recvInProgress == true) {
          if (PythonRead != endMarker) {
              receivedChars[ndx] = PythonRead;
              ndx++;
              if (ndx >= numChars) {
                  ndx = numChars - 1;
              }
          }
          else {
              receivedChars[ndx] = '\0'; // terminate the string
              recvInProgress = false;
              ndx = 0;
              newData = true;
          }
      }

      else if (PythonRead == startMarker) {
          recvInProgress = true;
      }
    }
}

void parseData() {      // split the data into its parts

    char * strtokIndex; // this is used by strtok() as an index

    strtokIndex = strtok(tempChars,",");
    MotorFLReceive = atoi(strtokIndex);
    
    strtokIndex = strtok(NULL, ",");
    MotorFRReceive = atoi(strtokIndex);

    strtokIndex = strtok(NULL, ",");
    MotorRLReceive = atoi(strtokIndex);

    strtokIndex = strtok(NULL, ",");
    MotorRRReceive = atoi(strtokIndex);

    strtokIndex = strtok(NULL, ",");
    xGimbalReceive = atoi(strtokIndex);

    strtokIndex = strtok(NULL, ",");
    yGimbalReceive = atoi(strtokIndex);
}

here is a photo of the project. at the moment i am looking for smoother spinning wheels to 3d print that dont require lots of screws and bearings. i have been told it looks like a bomb. quite a big battery wrapped in kapton tape and lots of wire i know.

Not a complaint, but I’m curious why you chose steppers as traction motors.

they are faster than hobby servos. probably could have went with encoded dc motors? brushless even maybe? i thought it would be easiest to work with steppers but not very strong without a heatsink on the drv8825's

well its happening. surely the raspberry pi pico would be able to handle this new setup? i just ordered a 4in1 esc to go with my spare brushless quadcopter motors. with a 3d printed gear reduction they should be fine. hopefully the KY-040 will work for the rotary encoder

GreatScott on youtube shows how to use a hard drive motor i have a full bin of those that are bad. should be much more reliable https://youtu.be/tjCJ3MlFt7g

Are you sure your stepper motors are capable of 10000 steps per second? Not spinning at all is about what I’d expect if you try to run a stepper too fast.

What's your battery voltage? ISTR that I have been able to run steppers to 9,000 steps/second with AccelStepper on a 32-bit arduino, but I had to get up to 30V to run a NEMA17 size stepper at that speed.

As lastchancename suggested, steppers aren't really a great choice for traction motors. They're slow and inefficient.

Dead HD's? Don't forget the voice coil magnets with Mu metal cages, and maybe take the whole VC mechanism, rock a mirror with that!

Your descriptions leave so much out. The Pi is running what? Does the Pi have an OS? I have a 3B+ and a 4, not a 0.

You might need more power or less motors too.

a Pi Pico is a cortex M0+ board that runs an Arduino Core, either on top of mBed on top of the RPi Pico Toolkit (using code from Arduino) or "bare toolkit" on top of the RPi Toolkit (which is on bare metal, sort-of) using a core from Earl Philhower

It's a pretty zippy 125MHz chip, at least natively.

I'm a little worried because presumably AccelStepper needs to use microsecond timing, and the pico:

  1. Starts out with a relatively unusual timer implementation.
  2. Has additional code added by the sdk.
  3. Has mBed on top of that, in the Arduino case.
    Each of those adds some overhead and "uncertainty", and I'm not sure that the final result is precise enough, or fast enough, to implement 40k steps/s (4 motors times 10k steps means a step every 25us, right?)

Test sketch:

void setup() {
  Serial.begin(9600);
  while (!Serial) ;
  Serial.println("\nmicros() test\n");
}

uint32_t times[100];

void loop() {
  for (int i = 0; i < 100; i++) {
    times[i] = micros();
  }
  for (int i = 0; i < 100; i++) {
    Serial.print(times[i]);
    if (i > 0) {
      Serial.print("   (-"); Serial.print(times[i]-times[i-1]); Serial.print(")");
    }
    Serial.println();
  }
  while (Serial.read() < 0) ;
}

Shows the Arduino core takes 4-5 us to run micros(), and Earl's core takes between 0 and 1us.

AccelStepper has been clocked at 16ksteps/second on a Due. I assume that's just one motor.
I've personally run it at 9,000 steps/second (until I ran out of current due to power supply voltage limitations) on an Adafruit Metro M0 Express (SAMD21G CPU), again one motor.

Now, will it run 4 motors at that speed? Depends on how the pulse update routine is written, but I wouldn't be surprised if it worked.

Thats not even whats happening i dont know where you got that from.

The stepper motors run fine its the servos im having an issue with. They handle more than 10k at 12v each unless the pi pico cpu is limited to the point that its not going that fast

You did let me know that it's easier to code AVR pins than ARM pins.

OP should have gotten the 600MHz Teensy 4.1, it's got an M4F and onboard SD!

I was trying to get a clear picture, Westfw gave me good answers.

that is fast! but seeing as how i have to drop step rate to 100-150 per second, is it really the problem for why my servos stop working when i go for control on serial? sure if im reaching total of 40k steps but 100? maybe something else is happening?

this is my result
micros() test

18779686
18779709 (-23)
18779715 (-6)
18779720 (-5)
18779724 (-4)
18779728 (-4)
18779733 (-5)
18779737 (-4)
18779742 (-5)
18779746 (-4)
18779750 (-4)
18779755 (-5)
18779759 (-4)
18779764 (-5)
18779768 (-4)
18779772 (-4)
18779777 (-5)
18779781 (-4)
18779785 (-4)
18779790 (-5)
18779794 (-4)
18779799 (-5)
18779803 (-4)
18779807 (-4)
18779812 (-5)
18779816 (-4)
18779821 (-5)
18779825 (-4)
18779829 (-4)
18779834 (-5)
18779838 (-4)
18779842 (-4)
18779847 (-5)
18779851 (-4)
18779856 (-5)
18779860 (-4)
18779864 (-4)
18779869 (-5)
18779873 (-4)
18779878 (-5)
18779882 (-4)
18779886 (-4)
18779891 (-5)
18779895 (-4)
18779899 (-4)
18779904 (-5)
18779908 (-4)
18779913 (-5)
18779917 (-4)
18779921 (-4)
18779926 (-5)
18779930 (-4)
18779935 (-5)
18779939 (-4)
18779943 (-4)
18779948 (-5)
18779952 (-4)
18779956 (-4)
18779961 (-5)
18779965 (-4)
18779970 (-5)
18779974 (-4)
18779978 (-4)
18779983 (-5)
18779987 (-4)
18779992 (-5)
18779996 (-4)
18780000 (-4)
18780005 (-5)
18780009 (-4)
18780013 (-4)
18780018 (-5)
18780022 (-4)
18780027 (-5)
18780031 (-4)
18780035 (-4)
18780040 (-5)
18780044 (-4)
18780049 (-5)
18780053 (-4)
18780057 (-4)
18780062 (-5)
18780066 (-4)
18780070 (-4)
18780075 (-5)
18780079 (-4)
18780084 (-5)
18780088 (-4)
18780092 (-4)
18780097 (-5)
18780101 (-4)
18780106 (-5)
18780110 (-4)
18780114 (-4)
18780119 (-5)
18780123 (-4)
18780127 (-4)
18780132 (-5)
18780136 (-4)
18780141 (-5)

How many motors? And why not DC motors through a multi-motor driver using PWM?
Your batteries should last longer. Check the mass of those HD motors.

Not sure about the serial conflict, that's not software serial is it?
Also set your baud rate to like 115200 to clear the buffers faster.

already using 115200, using 4 motors total. id say 12ah will last a few hours as it is

im not having an issue with serial i dont think, im having an issue with servo movement being effected by speed of stepper motor.