Go Down

Topic: Using HC-SRO4 distance module and generating tone at the same time? (Read 1 time) previous topic - next topic


Hello, I'm trying to create a project that would involve using the distance module (HC-SRO4) as well as a speaker to generate sound. However, I run into some trouble when compiling whenever I try to use both at once. It will give me this error:

core.a(Tone.cpp.o): In function `__vector_7':
C:\Users\Drew\Desktop\arduino-1.0.4\hardware\arduino\cores\arduino/Tone.cpp:535: multiple definition of `__vector_7'
NewPing\NewPing.cpp.o:C:\Users\Drew\Desktop\arduino-1.0.4\libraries\NewPing/NewPing.cpp:214: first defined here

If I have only the code for the distance module, it compiles fine. If I have only the code for generating tone, it compiles fine. But when ! try to combine the two it won't let me. Does anybody know why this may be?


I think it means that both libraries are trying to use the same interrupt.  When I look in the datasheet "Vector Number 7" is the watchdog timer vector.  Maybe it means the vector at address 7.  That would be the Timer 2 Compare Register A interrupt.  That makes more sense.

I guess the two libraries are not compatible. :(
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


The rangefinder really doesn't need a library. This code is from my book 'Hacking Electronics' p 155.

Code: [Select]

// range_finder_budget
// Arduino Uno or Leonardo

int trigPin = 9;
int echoPin = 10;
int gndPin = 11;
int plusPin = 8;

int lastDistance = 0;

void setup()
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(gndPin, OUTPUT);
  digitalWrite(gndPin, LOW);
  pinMode(plusPin, OUTPUT);
  digitalWrite(plusPin, HIGH);

void loop()

int takeSounding_cm()
  digitalWrite(trigPin, LOW);
  digitalWrite(trigPin, HIGH);
  digitalWrite(trigPin, LOW);
  int duration = pulseIn(echoPin, HIGH);
  int distance = duration / 29 / 2;
  if (distance > 500)
    return lastDistance;
    lastDistance = distance;
    return distance;

int takeSounding_in()
  return takeSounding_cm() * 2 / 5;
I write books about Arduino and Electronics: http://simonmonk.org

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131