Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: Teensy++2 problem with servo() and tone()

  1. #1
    Junior Member
    Join Date
    Feb 2019
    Posts
    3

    Teensy++2 problem with servo() and tone()

    Hello
    I want to use in my program the library servo () and tone ().
    I have an error message at compile time.
    What is the solution ? thanks you

    Here is error message:
    C:\Users\YANNIC~1.ANX\AppData\Local\Temp\arduino_b uild_506991\libraries\Servo\Servo.cpp.o:C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Servo/Servo.cpp:113: first defined here

    c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

    collect2.exe: error: ld returned 1 exit status

    Plusieurs bibliothèque trouvées pour "Servo.h"
    Utilisé : C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Servo
    Non utilisé : C:\Program Files (x86)\Arduino\libraries\Servo
    Erreur de compilation pour la carte Teensy++ 2.0


    here is the program (File > Examples > 02.Digital > toneMelody.)
    I just add "include servo.h"


    Code:
    #include <Servo.h>
    
    /*
      Melody
    
      Plays a melody
    
      circuit:
      - 8 ohm speaker on digital pin 8
    
      created 21 Jan 2010
      modified 30 Aug 2011
      by Tom Igoe
    
      This example code is in the public domain.
    
      http://www.arduino.cc/en/Tutorial/Tone
    */
    
    #include "pitches.h"
    
    // notes in the melody:
    int melody[] = {
      NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
    };
    
    // note durations: 4 = quarter note, 8 = eighth note, etc.:
    int noteDurations[] = {
      4, 8, 8, 4, 4, 4, 4, 4
    };
    
    void setup() {
      // iterate over the notes of the melody:
      for (int thisNote = 0; thisNote < 8; thisNote++) {
    
        // to calculate the note duration, take one second divided by the note type.
        //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
        int noteDuration = 1000 / noteDurations[thisNote];
        tone(8, melody[thisNote], noteDuration);
    
        // to distinguish the notes, set a minimum time between them.
        // the note's duration + 30% seems to work well:
        int pauseBetweenNotes = noteDuration * 1.30;
        delay(pauseBetweenNotes);
        // stop the tone playing:
        noTone(8);
      }
    }
    
    void loop() {
      // no need to repeat the melody.
    }

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,277
    The second problem is that you have multiple servo libraries installed on your computer, at least two : The one which comes with Teensyduino and the one which you have installed in Arduino via their library manager.

    You'll have to identify the one which you need to use (normally the Teensyduino one) and to uninstall/delete all others.

    Then, with a bit of luck, the first (linker definition) problem will go away. If not, we'll have to look deeper in the remaining servo library. Please understand that most development effort goes actually into the newer Teensy MCUs which are based on much more powerful ARM 32bit cores and while the older and weaker AVR 8bit stuff is basically still supported, there is much less usage and thus much less testing when a newer Teensyduino version comes out. Thus, small bugs might remain unseen for some time but as soon as they are precisely diagnosed, they can rapidly be fixed.

  3. #3
    Junior Member
    Join Date
    Feb 2019
    Posts
    3
    I deleted the servo directory in C: \ Program Files (x86) \ Arduino \ libraries \

    I have the following error message:

    c:\program files (x86)\arduino\hardware\tools\avr\avr\include\stdli b.h: In function 'malloc':

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy\mal loc.c:134:7: warning: 'sfp2' may be used uninitialized in this function [-Wmaybe-uninitialized]

    if (sfp2)

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy\mal loc.c:76:40: note: 'sfp2' was declared here

    struct __freelist *fp1, *fp2, *sfp1, *sfp2;

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy\mal loc.c:135:20: warning: 'sfp1' may be used uninitialized in this function [-Wmaybe-uninitialized]

    sfp2->nx = sfp1->nx;

    ^

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy\mal loc.c:76:33: note: 'sfp1' was declared here

    struct __freelist *fp1, *fp2, *sfp1, *sfp2;

    ^

    C:\Users\YANNIC~1.ANX\AppData\Local\Temp\arduino_b uild_757799/core\core.a(Tone.cpp.o): In function `__vector_32':

    C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy/Tone.cpp:219: multiple definition of `__vector_32'

    C:\Users\YANNIC~1.ANX\AppData\Local\Temp\arduino_b uild_757799\libraries\Servo\Servo.cpp.o:C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Servo/Servo.cpp:113: first defined here

    c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

    collect2.exe: error: ld returned 1 exit status

    Erreur de compilation pour la carte Teensy++ 2.0

  4. #4
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,277
    Ok... now I have also identified the other problem: The tone functions use the AVR Timer3. The Servo library tries to use the AVR Timer1 and Timer3. So, both libraries can not be used together without modification...

  5. #5
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,277
    The Servo library can be modified to use only timer1. Open Servo.h with a text editor and modify / comment out / add as follows from line 71 :
    Code:
    #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
    //#define _useTimer3
    #define _useTimer1
    //typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;
    typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
    Then, your sketch compiles without errors in Arduino 1.8.8 with Teensyduino 1.4.5 installed.

  6. #6
    Junior Member
    Join Date
    Feb 2019
    Posts
    3
    I made the change
    This compiles without error
    Thank you so much !

  7. #7
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,277
    You are welcome!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •