Go Down

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

Jumbosize

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?

johnwasser

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: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Si

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()
{
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(gndPin, OUTPUT);
  digitalWrite(gndPin, LOW);
  pinMode(plusPin, OUTPUT);
  digitalWrite(plusPin, HIGH);
}

void loop()
{
  Serial.println(takeSounding_in());
  delay(500);
}

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

int takeSounding_in()
{
  return takeSounding_cm() * 2 / 5;
}
--
My New Arduino Book: http://www.arduinobook.com

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!

Arduino
via Egeo 16
Torino, 10131
Italy