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).
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
}
}
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.