Incompatible with Arduino built-in tone( ) function
Issue #58
resolved
Error result during compilation of a simple sketch using this lib and tone()
Arduino: 1.8.13 (Windows 10), Board: "Arduino 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
Here's a sample sketch
#include <NewPing.h>
#define TRIGGER_PIN 8 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 9 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
#define BUZZER 5
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.
}
void loop() {
Serial.print(sonar.ping_cm());
tone(BUZZER, 500);
delay(5000);
noTone(BUZZER);
}
Comments (3)
-
repo owner -
repo owner - changed status to resolved
-
repo owner This isn’t a bug. Both NewPing and tone use the same timer. This is well documented.
The solutions (including the error you were getting) can be found here:
https://bitbucket.org/teckel12/arduino-new-ping/wiki/Multiple Definition of "__vector_7" Error
- Log in to comment
Not a bug, both use the same timer, well documented and work-arounds provided.