multiple definition of `__vector_7'

Hi,

I wanted upload this code:

// ---------------------------------------------------------------------------
// Example NewPing library sketch that does a ping about 20 times per second.
// ---------------------------------------------------------------------------
#include <NewPing.h>
#include <Tone.h>
#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

Tone tone1;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
tone1.begin(13);
}

void loop() {
  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  unsigned int Value = (uS / US_ROUNDTRIP_CM);
  Serial.print("Ping: ");
  Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)
  Serial.println("cm");
  
  if (Value <= 10)
  { 
  tone1.play(NOTE_CS4);
}
}

but when I upload it gives the error message:
" Tone\Tone.cpp.o: In function __vector_7': D:\Documents\arduino-1.0.1-windows\arduino-1.0.1\libraries\Tone/Tone.cpp:439: multiple definition of __vector_7'
NewPing\NewPing.cpp.o:D:\Documents\arduino-1.0.1-windows\arduino-1.0.1\libraries\NewPing/NewPing.cpp:214: first defined here "

What does this mean? and how can I fix this?
Thanks!

Usually it means you have two interrupt handlers defined for the same interrupt.

so what does this exactly mean?

mcremers:
so what does this exactly mean?

I think it means you tried to combine two libraries (Tone and NewPing) and they both want to use the same interrupt. I don't know, I don't use those libraries.

so, yeah I thought something as well.. because the error says ' multiple definitions'
But I've got no idea which ones.. I look into both libraries, but couldn't find anything where they use or define the same thing

ok so, I did not search well enough.

the Tone library uses:

class Tone
{
  public:
    void begin(uint8_t tonePin);
   
bool isPlaying();
    
void play(uint16_t frequency, uint32_t duration = 0);
  
void stop();

  
private:
    static uint8_t _tone_pin_count;
   
 uint8_t _pin;
   
int8_t _timer;
};


#endif;

and the New Ping library uses:

class NewPing {
	public:
		NewPing(uint8_t trigger_pin, uint8_t echo_pin, int max_cm_distance = MAX_SENSOR_DISTANCE);
		unsigned int ping();
		unsigned int ping_in();
		unsigned int ping_cm();
		unsigned int ping_median(uint8_t it = 5);
		unsigned int convert_in(unsigned int echoTime);
		unsigned int convert_cm(unsigned int echoTime);
		void ping_timer(void (*userFunc)(void));
		boolean check_timer();
		unsigned long ping_result;
		static void timer_us(unsigned int frequency, void (*userFunc)(void));
		static void timer_ms(unsigned long frequency, void (*userFunc)(void));
		static void timer_stop();

so they both use the uint8_t

what can I change and how?
It would be awesome if someone could help me.

so they both use the
Code:
uint8_t

what can I change and how?
It would be awesome if someone could help me.

uint8_t is just a variable type description, one can use that as many times and in as many included libraries as one wants. It would be like saying there is a conflict because two functions both use integer variables. The conflict must be elsewhere.

Lefty

hmm right.. I can't find anything which is in the 2 libraries the same and isn't meant to..

it's going to be something like this:

ISR(...)
{
}

But...the problem goes much deeper than that. If they're both using the same interrupt for something they're probably using the same hardware timer as well. Sharing a hardware resource might not be something you can work around.

mcremers:
hmm right.. I can't find anything which is in the 2 libraries the same and isn't meant to..

I think you will have to look at the .cpp files in the tone and ping libraries where the actual code is for any conflicts. *.h files are mostly just to declare variables, functions, and methods used for the library.

Lefty

I think you will have to look at the .cpp files in the tone and ping libraries where the actual code is for any conflicts. *.h files are mostly just to declare variables, functions, and methods used for the library.

thanks lefty, I was indeed searching into the .h files
I've found the problem in the .cpp files

it's going to be something like this:

ISR(...)
{
}

But...the problem goes much deeper than that. If they're both using the same interrupt for something they're probably using the same hardware timer as well. Sharing a hardware resource might not be something you can work around.

So, yes. they both use the same interrupt.

ISR(TIMER5_COMPA_vect) { .....

Which means I'm probably not able to work with these 2 libraries together? That would be a pity :frowning:

But I thank you all for your helps and thoughts guys! appreciate it.

There are several threads regarding incompatibility of libraries that make novel use of interrupts. Here's one:

http://arduino.cc/forum/index.php/topic,126251.0.html

NewPing is a common culprit, as is NewSoftSerial.

As an end-user there's not much you can do to resolve this as it is a pretty low-level issue.

The original ping library should work fine. I would recommend going with that.

The original ping library should work fine.  I would recommend going with that.

you sir, are my hero.

it works now. Thank you!

Comment line #326 to line #340 in NewPing.cpp file if not using ATmega* board.

// #if defined (AVR_ATmega32U4) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
// ISR(TIMER4_OVF_vect) {
// intFunc(); // Call wrapped function.
// }
// #elif defined (AVR_ATmega8) || defined (AVR_ATmega16) || defined (AVR_ATmega32) || defined (AVR_ATmega8535) // Alternate timer commands for certain microcontrollers.
// ISR(TIMER2_COMP_vect) {
// intFunc(); // Call wrapped function.
// }
// #elif defined (arm)
// // Do nothing...
// #else
// ISR(TIMER2_COMPA_vect) {
// intFunc(); // Call wrapped function.
// }
// #endif

1 Like

Thank you very much bishnoink, that solved the problem with NewPing and IR libraries!