Linear Actuator with Xiao nRF52840

Hi, I have a code for moving a linear actuator in and out that works well in arduino uno but doen’t work in Xiao nRF52840. Can you please tell me what should I do different for it to work?

/* The code will move a linear actuator to position according to a reading from an external pushbutton

 Parts required:

  - servo motor

  - 220 OHM RESISTOR

  - Switch (push button)

  */

#include <Servo.h>

Servo myServo;

int const potPin = A0;  // analog pin used to connect the pushbutton

int pushVal;             // variable to read the value from the analog pin

//int keyVal;              // variable to hold the reading from the push button

#define PIN_SERVO (9)



void setup()

{

  myServo.attach(PIN_SERVO);

  Serial.begin(9600);  // open a serial connection to your computer

   

}

void loop()                       //go to location according to reading from external potentiometer.

{

  pushVal = analogRead(potPin);  // read the value of the pushbutton

  // print out the value to the Serial Monitor

  Serial.print("pushVal: ");

  Serial.println(pushVal);

if (pushVal>600){

  myServo.writeMicroseconds(1010);

  delay(2500);

  myServo.writeMicroseconds(1690);

  delay(1500);

}

 }

I had a similar problem driving a haptic motor with the XIAO nRF52840. It worked on the Arduino, but the XIAO would not run the haptic motor. Not even a little bit. I ended up adding a 2605L haptic driver and it worked great after that. Maybe try something like the Adafruit PCA9685 16-Channel Servo Driver. 16 channels may be a little overdoing it, but it looks fairly small and inexpensive. Or maybe someone makes a single channel. Good luck.

Hi, I’m using an Actuonics linear motor (P8) and it comes with its own driver (Ext-R). Can’t it work in this constellation with Xiao? Maybe I need to change something in the code or use a library other than Servo.h?

Hi there,
According to there web site the (R) variant is Arduino compatible. So it should work,
Be sure the voltage settings, Xiao is a 3.3v device. FYI
HTH
GL :slight_smile: PJ

R Series
All of our R-series units use the same 3-wire configuration as rotary RC servos and 
are plug and play compatible with most RC receivers. These units can also be 
operated via Arduino using the Arduino servo library.
 The "R" series are only available as a 6V unit.

I connect 12V externally to the driver so that’s not the problem. I also though it should work, but it doesn’t… Again, in Arduino uno it works well weather I connect it to its 5 ot 3.3V.

Will this work?

//#define PIN_SERVO (9)
#define PIN_SERVO 9

Unfortunately no, but thanks for trying.

Will this work?
#define PIN_SERVO 10
or
#define PIN_SERVO D9

For reference.
C:\Users\xxxx\AppData\Local\Arduino15\packages\Seeeduino\hardware\mbed\2.9.2\variants\SEEED_XIAO_NRF52840_SENSE\pins_arduino.h : 82

// Digital pins
// -----------
#define D0  (0u)
#define D1  (1u)
#define D2  (2u)
#define D3  (3u)
#define D4  (4u)
#define D5  (5u)
#define D6  (7u)
#define D7  (8u)
#define D8  (9u)
#define D9  (10u)
#define D10 (11u)

#define D29 (30u)
#define D30 (31u)

WOW it worked! Thank you very much!!!