1

I have an Ultrasonic Distance Sensor with Passive Buzzer. The passive buzzer was set up with different tones. The buzzer will keep playing until the Ultrasonic Distance Sensor detect any obstruction items. However, the Arduino couldn't compile the code. it displays the error:


exit status 1
Error compiling for board Arduino/Genuino Uno.

Here is the full error message:

Arduino: 1.8.9 (Windows 10), Board: "Arduino/Genuino Uno"

Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':

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

libraries\NewPing\NewPing.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.

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

I could locate the function timer0_pin_port in Tone.cpp.o. But I couldn't find the same function in NewPing.cpp.o.

Because of the space limit, I counldn't post the NewPing.cpp.o here. You can download the NewPing.cpp.o here: https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home Tone.cpp.o is the original document in the library.

#include <NewPing.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 10 // Maximum distance we want to ping for (in centimeters). 
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(9600); // Open serial monitor at 115200 baud to see ping results.
  pinMode(2,OUTPUT);
}

void loop() {
  delay(50);                     // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  Serial.print("Ping: ");
  Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
  Serial.println("cm");
  if (sonar.ping_cm() == 0)
  tone(2,4000);
  else 
  tone(2,0);
}

Expected: The Buzzer will stop playing when the DIstance sensor detects any items. You have to use tone method to support different Tones. Or any similar functions that can support different tones.

Shaobo
  • 15
  • 5
  • You will have to make a [mcve] with all relevant information right here. – Yunnosch Apr 09 '19 at 04:52
  • The error message is telling you that `__vector_7` is duplicated, not `timer0_pin_port`. – Clifford Apr 09 '19 at 07:36
  • 1
    I think someone will ask the same problem later on. I found a useful topic in the Arduino forum. Click this link here: [Arduino Forum](http://forum.arduino.cc/index.php?topic=126251.0)
    Thanks to @PratikSampat
    – Shaobo Apr 09 '19 at 22:23

1 Answers1

2

From what I understand that the Tone and the NewPing library have a conflicting use of the same interrupt __vector_7. NewPing is known to have conflicting issues, I would suggest you use the original ping in Arduino. Here's a comprehensive example for it.

If you're certain that you're not using the ping_timer() method then in the NewPing.h file make TIMER_ENABLED to false.

Here's a link which talks about Multiple Definition of "__vector_7" Error further.

Here's the thread of a similar problem on the arduino forum.

Pratik Sampat
  • 330
  • 1
  • 12
  • Do you know anything about TIMER_ENABLE ? They added TIMER_ENABLED switch to get around compile-time "_vector_7" errors when using the Tone library. But I don't know how to use it. Do you have any ideas? (I couldn't use the ping method. The Ultrasonic Sensor I got, it's different from the one on the website. I have four pins rather than three. ) – Shaobo Apr 09 '19 at 22:15
  • Yeah, so if you're certain that you're not using the `ping_timer()` method then in the `NewPing.h` file make `TIMER_ENABLED ` to `false`. Let me know if it helped you, I'll update my answer to cover that case too. – Pratik Sampat Apr 10 '19 at 04:33
  • Yeah, I switched TIMER_ENABLE to false. And it works!!!!! Thank you so much. @Pratik Sampat – Shaobo Apr 11 '19 at 06:42
  • Glad I could help. If you could mark this answer as accepted it might help a few other people better who might stumble across this. :) – Pratik Sampat Apr 11 '19 at 08:20