Go Down

Topic: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 (Read 128 times) previous topic - next topic

AWOL

Quote
This is part of the sketch I am using:

This is part of an answer I am giving: tone.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

basile-laderchi


This is part of the sketch I am using:

This is part of an answer I am giving: tone.


That's exactly why I replaced the tone function with this function:
Code: [Select]
void toneWorkaround(byte tonePin, int frequency, int duration) {
  int period = 1000000L / frequency;
  int pulse = period / 2;
  for (long i = 0; i < duration * 1000L; i += period) {
    digitalWrite(tonePin, HIGH);
    delayMicroseconds(pulse);
    digitalWrite(tonePin, LOW);
    delayMicroseconds(pulse);
  }
}


Even after this modification to my code though the Parallax PING))) refuses to work when using the NewPing library.

Right now the Parallax PING))) is working and returning correct values with this code:
Code: [Select]

long ping(byte pingPin) {
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  pinMode(pingPin, INPUT);
  long duration = pulseIn(pingPin, HIGH);
  return duration;
}


basile

P.S.: robot's full code as is right now: http://pastebin.com/jc2sgQ4t

teckel


This is part of the sketch I am using:
Code: [Select]
#include <NewPing.h>

NewPing sonar = NewPing(A4, A4, 300);

void setup() {
}

void loop() {
  tone(12, 2999, 3000);
}


When I try to verify the sketch I always get this error:
Code: [Select]
core.a(Tone.cpp.o): In function `__vector_7':
C:\...\arduino-1.0\hardware\arduino\cores\arduino/Tone.cpp:523: multiple definition of `__vector_7'
NewPing\NewPing.cpp.o:C:\...\Documents\Arduino\libraries\NewPing/NewPing.cpp:214: first defined here


Even when I comment out or delete the 3rd line ("NewPing sonar = ...") I still get the same error.

basile

P.S.: I am using a Parallax PING))) sensor on an Arduino UNO board and I think (I am not sure because the test has been performed by a friend) that when it is connected to A4 (as in the example) it doesn't work. Unfortunately right now there are no digital ports available.


Just comment out line 214, 216, and 217 in NewPing.cpp if you're not using the interrupt method of NewPing.  Commenting out the "NewPing sonar=" line won't help as the library files are loaded via the #include <NewPing.h>

Not sure what can be done to fix this without manually commenting out the lines.  If anyone has any suggestions I'd appreciate it.  At least the solution is very straight-forward and simple.

Tim
Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone

caseyd

For this line in the example:
Serial.print(uS / US_ROUNDTRIP_IN); // Convert ping time to distance in cm and print result (0 = outside set distance range)

Is there a way to have "outside distance range" read the MAX_DISTANCE value instead of 0?

teckel


For this line in the example:
Serial.print(uS / US_ROUNDTRIP_IN); // Convert ping time to distance in cm and print result (0 = outside set distance range)

Is there a way to have "outside distance range" read the MAX_DISTANCE value instead of 0?


First, that would probably be a bad idea because a value of MAX_DISTANCE would indicate there was something there.  In other words, you wouldn't know if there was actually something exactly at 200cm away or if there was no ping echo if MAX_DISTANCE was set to 200.

With that said, you can easily do what you want.  See the following code snippet:

Code: [Select]

  long uS = sonar.ping();
  if (uS == NO_ECHO) uS = MAX_DISTANCE;
  Serial.print(uS);


Tim
Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone

Go Up