PWMServo library not compiling on adafruit itsybitsy m4 express but works on arduino uno

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
elliot4711
 
Posts: 1
Joined: Fri Oct 28, 2022 6:02 am

PWMServo library not compiling on adafruit itsybitsy m4 express but works on arduino uno

Post by elliot4711 »

Hello, I'm trying to adapt an itsybitsy m4 express for use as an RC-controller. For this I need to be able to control servos. The flight controller code I'm using uses the PWMServo library for this. The code is originally written for a teensy 4.0 but due to availability I'm trying to make it work with my itsybitsy m4 express.

I uploaded a test sketch to check if PWMServo works, but I keep getting the error message "undefined reference to `PWMServo::attach(int, int, int)'" or the full error message

Code: Select all

"Arduino: 1.8.19 (Windows 10), TD: 1.57, Board: "Adafruit ItsyBitsy M4 (SAMD51), Enabled, 120 MHz (standard), Small (-Os) (standard), 50 MHz (standard), Arduino, Off"

c:/users/elliot/appdata/local/arduino15/packages/adafruit/tools/arm-none-eabi-gcc/9-2019q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: sketch\sketch_oct28a.ino.cpp.o: in function `PWMServo::attach(int)':

C:\Users\Elliot\Documents\Arduino\libraries\PWMServo/PWMServo.h:81: undefined reference to `PWMServo::attach(int, int, int)'

c:/users/elliot/appdata/local/arduino15/packages/adafruit/tools/arm-none-eabi-gcc/9-2019q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: sketch\sketch_oct28a.ino.cpp.o: in function `loop':

C:\Users\Elliot\Documents\Arduino\sketch_oct28a/sketch_oct28a.ino:15: undefined reference to `PWMServo::write(int)'

c:/users/elliot/appdata/local/arduino15/packages/adafruit/tools/arm-none-eabi-gcc/9-2019q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\Elliot\Documents\Arduino\sketch_oct28a/sketch_oct28a.ino:19: undefined reference to `PWMServo::write(int)'

c:/users/elliot/appdata/local/arduino15/packages/adafruit/tools/arm-none-eabi-gcc/9-2019q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: sketch\sketch_oct28a.ino.cpp.o: in function `_GLOBAL__sub_I_myservo':

C:\Users\Elliot\Documents\Arduino\sketch_oct28a/sketch_oct28a.ino:3: undefined reference to `PWMServo::PWMServo()'

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board Adafruit ItsyBitsy M4 (SAMD51).
The code I am using is this example sketch:

Code: Select all

#include <PWMServo.h>

PWMServo myservo;  // create servo object to control a servo

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(SERVO_PIN_A);  // attaches the servo on pin 9 to the servo object
  //myservo.attach(SERVO_PIN_A, 1000, 2000); // some motors need min/max setting
}


void loop() {
  for(pos = 0; pos < 180; pos += 1) { // goes from 0 degrees to 180 degrees, 1 degree steps
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 180; pos>=1; pos-=1) {   // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}
Before uploading any code I followed this tutorial: https://learn.adafruit.com/introducing- ... y-m4/setup

Also I installed the PWMServo library using the arduino IDE library manager, and the library is visible under sketch-include library.

The weird thing is, this seems to compile successfully for AVR boards (I've tried the arduino uno and arduino mini), but as soon as I switch the board to the itsybitsy m4 express it gives the above error message. Interestingly, it also doesn't work with the arduino SAMD boards like the mkr1010 wifi, only the AVR boards. I don't understand how the code can find the library and work properly when compiling for an uno but not for the itsybitsy m4. I would appreciate any help in getting this to work on the itsybitsy m4 express.
Last edited by elliot4711 on Fri Oct 28, 2022 7:10 am, edited 1 time in total.

User avatar
adafruit_support_bill
 
Posts: 88097
Joined: Sat Feb 07, 2009 10:11 am

Re: PWMServo library not compiling on adafruit itsybitsy m4 express but works on arduino uno

Post by adafruit_support_bill »

PWMServo is a library from PJRC. They developed it for AVR and ARM based Teensy boards. Best to contact them for questions about support for other boards.
https://www.pjrc.com/teensy/td_libs_Servo.html

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”