Go Down

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

Murat_Artan

Sir, I am starting to use HC-SR04 ultrasonic sensor with Arduino DUE. May I ask which library I should use with NewPing Library. And could you tell important details it may help me to be succeed. I am a begginer.

teckel

Sir, I am starting to use HC-SR04 ultrasonic sensor with Arduino DUE. May I ask which library I should use with NewPing Library. And could you tell important details it may help me to be succeed. I am a begginer.
I assume you mean what methods to use with the NewPing Library?  ping() ping_cm() ping_in() ping_median() will all work with the Due.  The timer methods won't work as they require the ATmega chip.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

Murat_Artan

I was going to work with  ping() ping_cm() ping_in() ping_median().  Thank you

swilkens

Hello and happy new year!

Quick question regarding platform support; does this library provide support for the newer range of boards? i.e. the Nano Every - which is to replace the nano. It's an ATMega4809 chip.

Based on the output, it looks like this board misses some timers.

*edit* - Looking at the official site (which I couldn't find before posting, apologies) it seems this hardware is indeed unsupported.

https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home

teckel

Hello and happy new year!

Quick question regarding platform support; does this library provide support for the newer range of boards? i.e. the Nano Every - which is to replace the nano. It's an ATMega4809 chip.

Based on the output, it looks like this board misses some timers.

*edit* - Looking at the official site (which I couldn't find before posting, apologies) it seems this hardware is indeed unsupported.

https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home
Hello and happy new year!

Quick question regarding platform support; does this library provide support for the newer range of boards? i.e. the Nano Every - which is to replace the nano. It's an ATMega4809 chip.

Based on the output, it looks like this board misses some timers.

*edit* - Looking at the official site (which I couldn't find before posting, apologies) it seems this hardware is indeed unsupported.

https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home
There's been a lot of new hardware released over the years. As new hardware is released, the library may be tweaked to fully accommodate new boards. The latest  boards are no different.

Like always, the library will work with ALL boards with the non-timer methods. The timer methods may require code to accommodate. Anyone is free to submit a pull request that will add support for a new chipset, just like always.

In other words, NewPing will work with the latest boards, and the timer methods will also work as the community submits a pull request to accommodate. This is how it always has been and still is true today.
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

Olivier31830

Hi,
I try to use SR04T with arduino Uno and newping  to measure distance under water ...
Do you think it's possible and when ?
I dont' find examples ....
I have some results  over 80cm but it' s not so good...
Olivier 31830

teckel

Hi,
I try to use SR04T with arduino Uno and newping  to measure distance under water ...
Do you think it's possible and when ?
I dont' find examples ....
I have some results  over 80cm but it' s not so good...
Olivier 31830

The sensor your using is designed to measure solid surface objects through the air. They won't work underwater.  You would need to use a sensor designed for underwater usage.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

tsmacinspires

Hello! Thanks for this lovely library!
I'm using the following code to tell an actuator to move positions when something is in the way. I've got it to "stop," to adjust the actuator when something is in the way, but I cannot figure out where/how to add code to say "nothing is in the way, hold actuator in this position"
Said another wait, if nothing is sensed to actuator should be in "Go" position, when something is sense it's changed to "Stop" position.
Thanks!

/*
  Vehicle will have four sensors across the front.
  Sensors are named by location: Left (L), Middle Left (ML), Middle Right (MR), Right (R)
  Sensors Used: JSN-SR04T / RB-Dfr-720 :: Weatherproof Ultrasonic Sensor w/ Separate Probe
  http://www.robotshop.com/en/weatherproof-ultrasonic-sensor-separate-probe.html
  Uses NewPing Library: https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home
*/

#include <NewPing.h>

#define SONAR_NUM 4      // Number of sensors.
#define MAX_DISTANCE 130 // Maximum distance (in cm) to ping.
#define PING_INTERVAL 33
unsigned long pingTimer[SONAR_NUM];
uint8_t currentSensor = 0;


NewPing sonar[SONAR_NUM] = {   // Sensor object array.
  NewPing(3, 2, MAX_DISTANCE), // Each sensor's trigger pin, echo pin, and max distance to ping.
  NewPing(5, 4, MAX_DISTANCE),
  NewPing(6, 7, MAX_DISTANCE),
  NewPing(9, 8, MAX_DISTANCE)
};

void setup(void)
{
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
  pingTimer[0] = millis() + 75;
  for (uint8_t i = 1; i < SONAR_NUM; i++)
  pingTimer = pingTimer[i - 1] + PING_INTERVAL;

  pinMode(0, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);

}

void loop() {
 for (uint8_t i = 0; i < SONAR_NUM; i++) {
   if (millis() >= pingTimer) {
     pingTimer += PING_INTERVAL * SONAR_NUM;
     sonar[currentSensor].timer_stop();
     currentSensor = i;
     sonar[currentSensor].ping_timer(echoCheck);
   }
 }
 // Other code that *DOESN'T* analyze ping results can go here.
 
}

void echoCheck() {
 if (sonar[currentSensor].check_timer())
   pingResult(currentSensor, sonar[currentSensor].ping_result / US_ROUNDTRIP_CM);
 
}

void pingResult(uint8_t sensor, int cm) {
 // The following code would be replaced with your code that does something with the ping result.
 Serial.print(sensor);
 Serial.print(" ");
 Serial.print(cm);
 Serial.println("cm");
 digitalWrite(12, HIGH);
 delay(20);
 digitalWrite(11, LOW);
 Serial.println("STOP");
 delay(100);
 
}



teckel

Hello! Thanks for this lovely library!
I'm using the following code to tell an actuator to move positions when something is in the way. I've got it to "stop," to adjust the actuator when something is in the way, but I cannot figure out where/how to add code to say "nothing is in the way, hold actuator in this position"
Said another wait, if nothing is sensed to actuator should be in "Go" position, when something is sense it's changed to "Stop" position.
Thanks!

/*
  Vehicle will have four sensors across the front.
  Sensors are named by location: Left (L), Middle Left (ML), Middle Right (MR), Right (R)
  Sensors Used: JSN-SR04T / RB-Dfr-720 :: Weatherproof Ultrasonic Sensor w/ Separate Probe
  http://www.robotshop.com/en/weatherproof-ultrasonic-sensor-separate-probe.html
  Uses NewPing Library: https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home
*/

#include <NewPing.h>

#define SONAR_NUM 4      // Number of sensors.
#define MAX_DISTANCE 130 // Maximum distance (in cm) to ping.
#define PING_INTERVAL 33
unsigned long pingTimer[SONAR_NUM];
uint8_t currentSensor = 0;


NewPing sonar[SONAR_NUM] = {   // Sensor object array.
  NewPing(3, 2, MAX_DISTANCE), // Each sensor's trigger pin, echo pin, and max distance to ping.
  NewPing(5, 4, MAX_DISTANCE),
  NewPing(6, 7, MAX_DISTANCE),
  NewPing(9, 8, MAX_DISTANCE)
};

void setup(void)
{
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
  pingTimer[0] = millis() + 75;
  for (uint8_t i = 1; i < SONAR_NUM; i++)
  pingTimer = pingTimer[i - 1] + PING_INTERVAL;

  pinMode(0, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);

}

void loop() {
 for (uint8_t i = 0; i < SONAR_NUM; i++) {
   if (millis() >= pingTimer) {
     pingTimer += PING_INTERVAL * SONAR_NUM;
     sonar[currentSensor].timer_stop();
     currentSensor = i;
     sonar[currentSensor].ping_timer(echoCheck);
   }
 }
 // Other code that *DOESN'T* analyze ping results can go here.
 
}

void echoCheck() {
 if (sonar[currentSensor].check_timer())
   pingResult(currentSensor, sonar[currentSensor].ping_result / US_ROUNDTRIP_CM);
 
}

void pingResult(uint8_t sensor, int cm) {
 // The following code would be replaced with your code that does something with the ping result.
 Serial.print(sensor);
 Serial.print(" ");
 Serial.print(cm);
 Serial.println("cm");
 digitalWrite(12, HIGH);
 delay(20);
 digitalWrite(11, LOW);
 Serial.println("STOP");
 delay(100);
 
}



That code will never work how you're using it.  Can I ask where you got that base code from?  I need to somehow get people to stop using it and without knowing where you are getting the code I can't stop people from using it.

Basically, you're using two different programming paradigms in the same program, which simply isn't going to work.  I can give you the correct base code you should be using, but I really need to know how exactly you decided to use this code in the first place to stop the insanity!

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

Go Up