Arduino Nano RP2040 Support

Hi All, I have been having issues with trying to get motor control working with the Arduino Nano RP2040. I have some pretty simple code that I have built using the many examples. I am using an 8 pole BLDC with built in Hall sensors, and a simpleFOCmini board. I have used this code without issue on an Arduino UNO and then tried to use the same code just compiled to the Nano RP2040. I have also tried to incrementally check the individual parts of the code. The hall sensor works without issue on the RP2040, but I cannot seem to get the motor working. When running the code on the Uno the items you would expect are printed to the terminal and the calibration is completed. When running on the RP2040 the code compiles and seems to run but no information is printed and the motor does not go through a calibration. I guess what I am trying to figure out is if the Arduino Nano RP2040 is supported, or if there is a particular driver I might need, or if I should just stick with the Uno. I have attached my code below, and would really appreciate any support. I have been quite stuck on this.

#include <SimpleFOC.h>
// software interrupt library
#include <PciManager.h>
#include <PciListenerImp.h>

// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(8);
BLDCDriver3PWM driver = BLDCDriver3PWM(11, 10, 9, 8);

// hall sensor instance
HallSensor sensor = HallSensor(7, 6, 5, 8);

// Interrupt routine intialisation
// channel A and B callbacks
void doA(){sensor.handleA();}
void doB(){sensor.handleB();}
void doC(){sensor.handleC();}
// If no available hadware interrupt pins use the software interrupt
PciListenerImp listenA(sensor.pinA, doA);
PciListenerImp listenB(sensor.pinB, doB);
PciListenerImp listenC(sensor.pinC, doC);

// velocity set point variable
float target_velocity = 0;
// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_velocity, cmd); }

void setup() {

  // use monitoring with serial 
  Serial.begin(115200);
  // enable more verbose output for debugging
  // comment out if not needed
  SimpleFOCDebug::enable(&Serial);
  digitalWrite(12, LOW);

  // initialize sensor sensor hardware
  sensor.pullup = Pullup::USE_INTERN;
  sensor.init();
  sensor.enableInterrupts(doA, doB, doC);
  PciManager.registerListener(&listenA);
  PciManager.registerListener(&listenB);
  PciManager.registerListener(&listenC);
  // software interrupts
  // PciManager.registerListener(&listenerIndex);
  // link the motor to the sensor
  motor.linkSensor(&sensor);

  // driver config
  // power supply voltage [V]
  driver.voltage_power_supply = 20;
  driver.voltage_limit = 12;
  // driver.pwm_frequency = 5000;
  driver.init();
  // link the motor and the driver
  motor.linkDriver(&driver);

  // aligning voltage [V]
  motor.voltage_sensor_align = 2;

  // velocity PI controller parameters
  motor.PID_velocity.P = 0.15;
  motor.PID_velocity.I = 2.5;
  motor.PID_velocity.D = 0;
  motor.LPF_velocity.Tf = 0.1;

  // motor.P_angle.P = 10;
  // motor.P_angle.D = .01;
  // motor.P_angle.I = .01;
  // default voltage_power_supply
  motor.voltage_limit = 2;
  motor.foc_modulation = FOCModulationType::SpaceVectorPWM;

  // set motion control loop to be used
  // motor.controller = MotionControlType::velocity;
  motor.controller = MotionControlType::torque;
  // velocity low pass filtering time constant


  // comment out if not needed
  motor.useMonitoring(Serial);

  // initialize motor
  motor.init();
  // align sensor and start FOC
  motor.initFOC();

  // add target command T
  command.add('T', doTarget, "target voltage");

  Serial.println(F("Motor ready."));
  Serial.println(F("Set the target velocity using serial terminal:"));
  _delay(1000);
}


void loop() {
  motor.loopFOC();
  motor.move(target_velocity);
  motor.monitor();
  command.run();
}

Hi @lbeardslee

I suppose you’ve already tried the usual debugging steps? Did you try paring back the code to run in open loop and not using the commander, hall sensor, or debug over serial? I’m not very good at debugging so I usually add way too many Serial.prinln() statements to see just how far the code runs before having an issue. You might find that one line might cause your program to be completely stuck and can dig deeper from there. RP2040 should be supported Raspberry Pi Pico boards | Arduino-FOC.

@Rosewill2 I feel like this is something that I have tried, but in an effort to figure it out I tried a variety of different things. I will take a step back when I get a chance and try to systematically test the open loop control. Thanks for the advice!