PaulStoffregen / AltSoftSerial

Software emulated serial using hardware timers for improved compatibility
http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
338 stars 132 forks source link

Conflict with Servo: Multiple definitions #48

Closed KarelPeeters closed 6 years ago

KarelPeeters commented 6 years ago

Description

When creating both a Servo and a AltSoftwareSerial object I get a compiler error.

Steps To Reproduce Problem

Make sure this library is in the libraries folder of the Arduino IDE, and try to compile the code below.

Hardware & Software

Arduino UNO Board: Arduino UNO Arduino IDE version 1.8.5 (but also happens when compiling with PlatformIO) Arduino AVR Boards 1.6.20 Windows 10

Arduino Sketch

#include <Arduino.h>
#include <AltSoftSerial.h>
#include <Servo.h>

AltSoftSerial bluetooth;
Servo servo;

void setup() {}
void loop() {}

Errors or Incorrect Output

libraries\Servo\avr\Servo.cpp.o (symbol from plugin): In function `ServoCount':

(.text+0x0): multiple definition of `__vector_11'

libraries\AltSoftSerial\AltSoftSerial.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.
PaulStoffregen commented 6 years ago

Yes, this is a well known conflict. From the web page:

AltSoftSerial uses a 16 bit hardware timer to generate the transmit output and measure the receive input waveforms. Any other library which needs the same timer, and the PWM pins which depend upon that timer, will not work.

KarelPeeters commented 6 years ago

Ah that's unfortunate, I was hoping this library would allow me to use a Servo and something SoftwareSerial-like at the same time. Sorry for the dumb issue.

davidbitton commented 6 years ago

I'm seeing this issue as well with SoftPWM. Is there a way I can "move" which timer is being used? I tried #define ALTSS_USE_TIMER3 with little luck. Is there any workaround? I need to take receipt of serial data and output correlating PWM on a Pro Mini. Thanks.

davidbitton commented 6 years ago

I think I "solved" my problem. I'm going to use a Pro Micro in lieu of a Pro Mini. The 32u4 proc will be causative to AltSoftSerial using Timer3; leaving Timer1 for SoftPWM. Thanks.

PaulStoffregen commented 6 years ago

Yes, this is a well known conflict. From the web page:

AltSoftSerial uses a 16 bit hardware timer to generate the transmit output and measure the receive input waveforms. Any other library which needs the same timer, and the PWM pins which depend upon that timer, will not work.

On boards using AVR ATMEGA328P, there is only one 16 bit timer. It is a known limitation of this cheap hardware. These libraries which require a 16 bit timer can not magically add more hardware timers. Only you can do that, but using a better board with more capable hardware.

davidbitton commented 6 years ago

After a bunch of sleuthing, I settled on that 32u4 proc which has an adequate number of timers. However one problem; not enough pins. I had to make a change in the boards.h file because the Micro Pro board doesn't have an accessible pin 13.