Added an include library statement and won't compile

Had code working. Added #include <Servo.h> , Then compile failed with "exit fail 1. Error compiling for board Uno.

Had another sketch with the #include <Servo.h> in the sketch and it still compiles.

What is wrong?

Thanks in advance

Please post the full sketch that produces the error and the full error message, using code tags for both

Are you sure that the error line does not actually say

#include <servo.h>

Which Arduino board are you compiling for ?

I have narrowed down the issue. It appears that if I just #include " #include <Servo.h>" and no other libraries it compiles. If I add "#include <LocoNet.h>" then it won't compile. There must be something in the LocoNet.h library that conflicts with the servo.h library. While there is lots of documentation on the servo library I can't find much documentation on the loconet library. It is a Uno board but if I change the board to a Mega I get the same error.

Think it is somekind of library conflict issue

Forgot to mention that if I have just the loconet library it compiles. Blows up just when have both.

The sketch just have the 2 include statements.

Hi @trainman. I'm going to ask you to provide the full output from a compilation.


:red_exclamation_mark: This procedure is not intended to solve the problem. The purpose is to gather more information.


Please do this:

  1. Select Sketch > Verify/Compile from the Arduino IDE menus.
  2. Wait for the compilation to fail.
  3. You will see a "Compilation error: ..." notification at the bottom right corner of the Arduino IDE window. Click the "COPY ERROR MESSAGES" button on that notification.
  4. Open a reply here on this forum topic by clicking the "Reply" button.
  5. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
  6. Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
    This will paste the compilation output into the code block.
  7. Move the cursor outside of the code block markup before you add any additional text to your reply.
  8. Click the "Reply" button to publish the post.

In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here.

Click here for attachment instructions

  1. Open any text editor program.
  2. Paste the copied output into the text editor.
  3. Save the file in .txt format.
  4. Open a reply here on this forum topic by clicking the "Reply" button.
  5. Click the "Upload" icon (Upload icon) on the post composer toolbar:

    The "Open" dialog will open.
  6. Select the .txt file you saved from the "Open" dialog.
  7. Click the "Open" button.
    The dialog will close.
  8. Click the "Reply" button to publish the post.

Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.

I think I have the info you request

Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Uno"





















libraries\LocoNet\utility\ln_sw_uart.cpp.o (symbol from plugin): In function `setTxPortAndPin(unsigned char volatile*, unsigned char)':

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

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

collect2.exe: error: ld returned 1 exit status

Multiple libraries were found for "Servo.h"

 Used: D:\OneDrive\Documents\Arduino\libraries\Servo

 Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\libraries\Servo

exit status 1

Error compiling for board Arduino Uno.



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

``My Sketch has 2 lines added to the basic blank sketch
#include <Servo.h>
#include <LocoNet.h>

If I comment out either one the sketch compiles.  Leave both in and it bombs

Thanks for the help

The AT328 data sheet says that _vector_11 is the Timer1 Input Capture Vector and indeed in LocoNet.h ReadMe I see

This library uses TIMER1 & ICP (UNO)

The Servo.h library for Arduino uses Timer1 for generating the necessary pulse-width signals to control servos. This creates a conflict with Timer1's Input Capture Event feature.

Try using a library called ServoTimer2.h which uses Timer2 and avoids the conflict. It is available through the library manager.

Big THANK YOU!'
I compiled with the ServoTimer2 library and no error. I am hoping that the function calls to the library are the same as the Servo library. I will test out today hopefully.

If that works I will add a second turnout to the sketch and add to my train layout.

Thanks again

Well the saga continues. Something is amiss. ServoTimes2 must not have the same functions as Servo.

If I type in this sketch it compiles and the servo moves back and forth:

#include <Servo.h>
Servo myservo;
void setup() {
  // put your setup code here, to run once:
myservo.attach(5);
}
void loop() {
  // put your main code here, to run repeatedly:
myservo.write(0);
delay(1000);
myservo.write(120);
delay(1000);
}

if I simply change <Servo.h> to <ServoTimer2.h> it compiles but the servo does not move back and forth

I also noticed that when Servo is used it is highlighted in red in the sketch whil when ServoTimer2 is used it is not highlighted in the sketch. Not sure why that happens either.

The write() function in the ServoTimer2 library expects a value for the required pulse width in microseconds as its parameter rather than the target angle in degrees. It is analogous to the writeMicroseconds() function in the normal Servo library

Try values between 1000 and 2000 microseconds in your sketch

Don't worry about the colour of keywords, they are not significant for the operation of the sketch

Tnanks for very quick reply.

That seems to get me movement.

Is there a way to convert micoseconds to an angle?

The servo is connected to a model railroad switch. In previous code that did not include the Loconet library the servo moved to the open at 68 degrees and closed at 91 degrees.

Or is there another alternative servo library that does not use timer1?

Thanks in advance

Meant to end message with "Or is there another alternative servo library that does not use timer1 and writes in degrees?"

To convert angles to a pulse width in microseconds you need to know a number of things

  • How many degrees can the servo move through bearing in mind that it may not be able to move through 180 degrees
  • What range of microsecond values is associated with the move ment of the servo from one extreme to the other
  • Given those values you can derive a formula to convert degrees to microseconds

In a perfect world the range of microsecond values would be 100 to 200 for 180 degrees of movement but you are not in a perfect world

The standard Servo library actually calls writeMicroseconds() after doing the calculation like this

    value = map(value, 0, 180, SERVO_MIN(),  SERVO_MAX());
  }
  this->writeMicroseconds(value);

In practice it is probably easier to find the required microsecond values for required angles by experimentation as it may be different for different servos

Thanks. I think I can figure it out using your logic.