Servo.h + Altserial Doesnt work together

Status
Not open for further replies.

mpkuse

New member
Hi,I have a teensy2++. I am trying to control 4 servos (with Servo.h). I have an HC-12 module connected to altserial and RX-TX correctly connected to pins 25 and 4. I have verified that a standalone altserial only program works.

However, as I use Servo.h with Altserial I get the following compiler error:
```
Arduino: 1.8.8 (Linux), TD: 1.45, Board: "Teensy++ 2.0, Serial, 16 MHz, US English"

/tmp/arduino_build_577445/libraries/Servo/Servo.cpp.o: In function `__vector_17':
/home/mpkuse/Downloads/teensy_setup/arduino-1.8.8-linux64/arduino-1.8.8/hardware/teensy/avr/libraries/Servo/Servo.cpp:106: multiple definition of `__vector_17'
/tmp/arduino_build_577445/libraries/AltSoftSerial/AltSoftSerial.cpp.o:/home/mpkuse/Downloads/teensy_setup/arduino-1.8.8-linux64/arduino-1.8.8/hardware/teensy/avr/libraries/AltSoftSerial/AltSoftSerial.cpp:156: first defined here
Multiple libraries were found for "Servo.h"
/home/mpkuse/Downloads/teensy_setup/arduino-1.8.8-linux64/arduino-1.8.8/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld: Disabling relaxation: it will not work with multiple definitions
Used: /home/mpkuse/Downloads/teensy_setup/arduino-1.8.8-linux64/arduino-1.8.8/hardware/teensy/avr/libraries/Servo
collect2: error: ld returned 1 exit status
Not used: /home/mpkuse/Downloads/teensy_setup/arduino-1.8.8-linux64/arduino-1.8.8/libraries/Servo
Error compiling for board Teensy++ 2.0.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
```
What could be a possible way around? Do I need to use the TimerOne based calls for PWMs?
 
Yup, both libs are trying to use the same timer.

You can change AltSoftSerial by editing config/AltSoftSerial_Boards.h. Look for these lines:

Code:
// Teensy++ 2.0
//
#elif defined(__AVR_AT90USB1286__) && defined(CORE_TEENSY)

 #define ALTSS_USE_TIMER1
 #define INPUT_CAPTURE_PIN               4 // receive
 #define OUTPUT_COMPARE_A_PIN           25 // transmit
 #define OUTPUT_COMPARE_B_PIN           26 // unusable PWM
 #define OUTPUT_COMPARE_C_PIN           27 // unusable PWM

 //#define ALTSS_USE_TIMER3
 //#define INPUT_CAPTURE_PIN            17 // receive
 //#define OUTPUT_COMPARE_A_PIN         16 // transmit
 //#define OUTPUT_COMPARE_B_PIN         15 // unusable PWM
 //#define OUTPUT_COMPARE_C_PIN         14 // unusable PWM

Hopefully you can see from the comments you'll need to use pins 16 & 17 once you change the timer config.
 
Status
Not open for further replies.
Back
Top