Can't use tone when using this library

Issue #14 resolved
Jaime Iniesta created an issue

I've seen that if you try to use a tone to make a beep with a piezo, the compilation fails.

This is the program, basically it's your example code (which works great, thanks), with a line added to add a tone.

#include <NewPing.h>

#define TRIGGER_PIN  12
#define ECHO_PIN     11
#define MAX_DISTANCE 200

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

void setup() {
  Serial.begin(115200);
}

void loop() {
  delay(100);
  tone(8, 1000, 20);

  Serial.print("Ping: ");
  Serial.print(sonar.ping_cm());
  Serial.println("cm");
}

And it fails with this compilation error:

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: error: ld returned 1 exit status
exit status 1

Comments (3)

  1. Tim Eckel repo owner

    This isn't a bug, You're getting the error because both NewPing and tone use timer 2 and there's several solutions. This is documented both on a wiki page and a link to the wiki page on the home page of NewPing. Searching for "vector_7" on Google should also direct you to the referred to wiki page. Here's a direct link to the wiki page on the "vector_7" error:

    Multiple Definition of `__vector_7' Error

  2. Log in to comment