Pages: [1]   Go Down
Author Topic: multiple definition of `__vector_7'  (Read 2695 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I wanted upload this code:
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!
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 146
Posts: 5535
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so what does this exactly mean?
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 146
Posts: 5535
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok so, I did not search well enough.

the Tone library uses:
Code:
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:
 
Code:
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
Code:
uint8_t

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

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 146
Posts: 5535
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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

Quote
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 smiley-sad

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

Ontario
Offline Offline
God Member
*****
Karma: 25
Posts: 883
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
The original ping library should work fine.  I would recommend going with that.
you sir, are my hero.

it works now. Thank you!
Logged

Pages: [1]   Go Up
Jump to: