Go Down

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

Hi Tim,

I want to use 12 sensors, which is obviously achievable with your code, I have got 6 working really well so far so thank you.... however there are only 12 pins on the arduino uno, so I can only use 6 sensors (obviously 2pins per sensor). I see you can buy a Mux shield to add more inputs. Would this shield work with your code? (I'm very new to code). Would I need to change the code much to make it work? or is there a better / easier option?

Thanks again

cyclegadget

#256
Oct 26, 2012, 01:39 am Last Edit: Oct 26, 2012, 01:56 am by cyclegadget Reason: 1
@ bassmagnetic

Some time in the earlier pages, Tim made it possible to run each sensor from one digital pin, +5, and GND. So, the result is that 12 sensors require 12 digital pins.

Check the examples with his library.


EDIT: his discovery of the one pin method was reported on page 7 of this thread. I am not sure what page the addition was made to the examples.
Good links: Eagle tutorial= http://www.youtube.com/playlist?list=PLDE1858BD83D19C70
General Arduion tutorials = http://tronixstuff.wordpress.com
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123


Hi Tim,

I want to use 12 sensors, which is obviously achievable with your code, I have got 6 working really well so far so thank you.... however there are only 12 pins on the arduino uno, so I can only use 6 sensors (obviously 2pins per sensor). I see you can buy a Mux shield to add more inputs. Would this shield work with your code? (I'm very new to code). Would I need to change the code much to make it work? or is there a better / easier option?

Thanks again


cyclegadget is quite right, I've written the NewPing library to work using only one one pin for both trigger and echo.  So, with even the Uno you can connect 12 ping sensors using the NewPing library.  Basically, the library sets the pin to output, initiates the ping, quickly switches the same pin to input, and waits for the ping echo.  The syntax is just to specify the same pin for both trigger and echo.  Below is an example sketch as well as a schematic of how you connect the sensor.  You simply tie the pin to trigger and then jumper trigger to echo.

http://code.google.com/p/arduino-new-ping/wiki/NewPing_Single_Pin_Sketch

Before you rip your project apart and use the one pin method I would suggest doing just one sensor first.  The reason is that for some sensors this one pin technique doesn't work.  If you're using the HC-SR04, you should be good to go.  Others may need a little capacitor instead of the jumper.  I believe I docucmented in the release notes in NewPing.h exactly which sensors worked without the cap and those that needed the cap.  Check the release notes in NewPing.h for details.

Also, I'm always interested to see what multi ping sensor projects people are using with NewPing.  Once you get things working, post a pic.

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

Brilliant, thanks Tim, just tried that and it works fine with 1 sensor, I am using HC-SR04's.... much better than buying more bits!!

Now I just need to figure out how to combine this code with the NewPing15sensor code to make it work with more sensors, any ideas, is it easy to do?

I am needing to increase the number of sensors as I want to make sure that proximately to the speakers does not trigger sounds (so no one goes deaf!)

I am making an installation as part of a final piece for an MA, i'd be happy to send details and photos when its all up and running...

thanks again

andre


Brilliant, thanks Tim, just tried that and it works fine with 1 sensor, I am using HC-SR04's.... much better than buying more bits!!

Now I just need to figure out how to combine this code with the NewPing15sensor code to make it work with more sensors, any ideas, is it easy to do?

I am needing to increase the number of sensors as I want to make sure that proximately to the speakers does not trigger sounds (so no one goes deaf!)

I am making an installation as part of a final piece for an MA, i'd be happy to send details and photos when its all up and running...

thanks again

andre


Just take the 15 sensor sketch and for each sensor use the same trigger and echo pin.  For example, the first part of your sketch would look something like this:

Code: [Select]

#include <NewPing.h>

#define SONAR_NUM     12 // Number or sensors.
#define MAX_DISTANCE 200 // Maximum distance (in cm) to ping.
#define PING_INTERVAL 33 // Milliseconds between sensor pings (29ms is about the min to avoid cross-sensor echo).

unsigned long pingTimer[SONAR_NUM]; // Holds the times when the next ping should happen for each sensor.
unsigned int cm[SONAR_NUM];         // Where the ping distances are stored.
uint8_t currentSensor = 0;          // Keeps track of which sensor is active.

NewPing sonar[SONAR_NUM] = {   // Sensor object array.
  NewPing(2, 2, MAX_DISTANCE), // Using same pin for trigger and echo.
  NewPing(3, 3, MAX_DISTANCE),
  NewPing(4, 4, MAX_DISTANCE),
  NewPing(5, 5, MAX_DISTANCE),
  NewPing(6, 6, MAX_DISTANCE),
  NewPing(7, 7, MAX_DISTANCE),
  NewPing(8, 8, MAX_DISTANCE),
  NewPing(9, 9, MAX_DISTANCE),
  NewPing(10, 10, MAX_DISTANCE),
  NewPing(11, 11, MAX_DISTANCE),
  NewPing(12, 12, MAX_DISTANCE),
  NewPing(13, 13, MAX_DISTANCE)
};


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

After the substitution of the tone function with the toneWorkaround one and the change of the power supply of the PING))) (attached to A4) to getting it's power from the Arduino everything is working juuuust fine!!!
I am now using the ping_median for the pings just in case there is some interference.

Thanks again for the great library.

basile


After the substitution of the tone function with the toneWorkaround one and the change of the power supply of the PING))) (attached to A4) to getting it's power from the Arduino everything is working juuuust fine!!!
I am now using the ping_median for the pings just in case there is some interference.

Thanks again for the great library.

basile


Another solution would be to comment out line 214, 216, and 217 in NewPing.cpp if you're not using the interrupt method of NewPing.  You can then use the tone library without conflict.  In my development version, I've created a switch to do this if you're not using the timer interrupt method of NewPing.

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

I'm getting close to releasing a new version of the NewPing library.  Is anyone having any problems with it or want to suggest something new to add?  It's getting quite mature now so the updates probably won't happen as frequently.

I'm going to test it with the new 32-bit ARM Teensy 3.0 that I got last week.  If someone has the Arduino Due and would like to test NewPing with it, that would be appreciated.  Note, that the timer interrupt methods probably won't work with the new crop of 32-bit Arduinos.  So, all I really care about testing and supporting at this time is the standard ping() method.

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

jackryan

I've downloaded the v1.5 and tried it in arduino 1.0 but it wont compile. im using a cloned arduino board with atmega8. does it support older boards?

http://www.elab.ph/forum/index.php?topic=6698.0

this is the board im using.


I've downloaded the v1.5 and tried it in arduino 1.0 but it wont compile. im using a cloned arduino board with atmega8. does it support older boards?

http://www.elab.ph/forum/index.php?topic=6698.0

this is the board im using.


I know the timer interrupt methods won't work correctly with the ATmega8 due to the clock rate.  Never had anyone try a ATmega8 to know if it worked or not.  Be sure to start with the basics and try the sample sketch (using the standard ping() method).  If you're still getting compile errors, including them with your reply would be helpful to detect if it's a simple thing or something more complex.  As it stands, without the errors I can't even guess as v1.5 works just fine with Arduino 0023, 1.0, 1.0.1, and 1.0.2.

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

First, thanks for the lib! I love it.
Second I will apologize in advance if this has already been asked, but I can't seem to search just this topic so I may have missed it, if it was.

Has any one else experienced an error when attempting to use tone() along with this lib? When I attempt to include tone [e.g. tone(11,1000,20)] I get an error:
core.a(Tone.cpp.o): In function `__vector_7':
C:\Users\Dave\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino/Tone.cpp:523: multiple definition of `__vector_7'
NewPing\NewPing.cpp.o:C:\Users\Dave\arduino-1.0.1-windows\arduino-1.0.1\libraries\NewPing/NewPing.cpp:214: first defined here



Dear amatbrewer,

First, thanks for the lib! I love it.

It is a great lib indeed!


Second I will apologize in advance if this has already been asked, but I can't seem to search just this topic so I may have missed it, if it was.

you did miss it indeed! It's just on the previous page: http://arduino.cc/forum/index.php/topic,106043.msg959928.html#msg959928


Has any one else experienced an error when attempting to use tone() along with this lib?

I had stumbled upon this error just a while ago, and after searching around I found the toneWorkaround function in a book (Arduino Cookbook, page 307). You can find the function I used here: http://arduino.cc/forum/index.php/topic,106043.msg959970.html#msg959970

basile

CyklKent

I have a HC-SR04 sensor,  a 3.3v capable bluetooth module, and an Arduino Uno r3 (that is it besides spares of all three). I am using 10" jumper wires from the Arduino for power and pins 12 and 13. I am running newping with median(5). I have the HC-SR04 in a fixed position holder aiming at a 3 square inch surface that only moves in one direction directly away from the sensor (from 1" to 78"). This smooth/flat surface is accurately controlled to be square to the sensor for good signal return. With one sensor holder (this one is steel, fairly open air, and lightly holds the sensor around the two barrels) the readings are either perfect or up to 3% bad values (even after median(5) and the stationary object not very far away 15"). The other sensor holder (which is machined plastic, holds the barrels tightly, and encloses the sensor board) might work just as well or might give far more bad values. The erroneous distance values don't seem to be random. They are very similar numbers on a given day (a lot of 9" ±.3 one day, it might be around 3" another day).  The "test bed" is very controlled so I don't have items causing pings one day and not the next.  I bored out the tight fitting holder and hung the sensor in it with spacers to the sensor board 2 mounting holes and I didn't notice any change. I want to use this sensor and I know that this type of distance sensing isn't perfect, but I can't live with the "bad" days of the output. I can't enlarge the surface of the object being measured. I have tried changing all of the hardware with no change. I have tried USB 5v, 9vdc wall warts, and 4 x AA battery packs.  I have slowed the ping rate some. I have been trying to think through the possible problems (I will list some below):
Power pulsing (put a 1uF capacitor across the HC-SR04 Vcc and ground, and possibly across on the Arduino as well?).
Different sensor mounting (I don't know how much direct mechanical vibration problems there are at the receive barrel from the trigger).
Don't use pin13 due to the led.
The Arduino and bluetooth module need to be farther away from the sensor.
Use shielded cable instead of jumper wires.
Interference from something in the room.
Somehow pull the sensor farther back so I am not measuring the first 7" or so.
Maybe change to the HY SRF05 (I kind of doubt this will help).

Do you have any suggestions or do you think these sensors are just "flaky"?
Thank you.






Has any one else experienced an error when attempting to use tone() along with this lib? When I attempt to include tone [e.g. tone(11,1000,20)] I get an error:
core.a(Tone.cpp.o): In function `__vector_7':
C:\Users\Dave\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\arduino/Tone.cpp:523: multiple definition of `__vector_7'
NewPing\NewPing.cpp.o:C:\Users\Dave\arduino-1.0.1-windows\arduino-1.0.1\libraries\NewPing/NewPing.cpp:214: first defined here



If you're using the ping_timer() method with NewPing, you won't be able to use both the Tone library and NewPing as they both use Timer2.  If, however, you're using just the ping() method in NewPing, you'll be able to use the Tone library.  You'll just need to comment out a few lines in NewPing.cpp to avoid the conflict.  See this message for more details:

http://arduino.cc/forum/index.php/topic,106043.msg960630.html#msg960630

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


I have a HC-SR04 sensor,  a 3.3v capable bluetooth module, and an Arduino Uno r3 (that is it besides spares of all three). I am using 10" jumper wires from the Arduino for power and pins 12 and 13. I am running newping with median(5). I have the HC-SR04 in a fixed position holder aiming at a 3 square inch surface that only moves in one direction directly away from the sensor (from 1" to 78"). This smooth/flat surface is accurately controlled to be square to the sensor for good signal return. With one sensor holder (this one is steel, fairly open air, and lightly holds the sensor around the two barrels) the readings are either perfect or up to 3% bad values (even after median(5) and the stationary object not very far away 15"). The other sensor holder (which is machined plastic, holds the barrels tightly, and encloses the sensor board) might work just as well or might give far more bad values. The erroneous distance values don't seem to be random. They are very similar numbers on a given day (a lot of 9" ±.3 one day, it might be around 3" another day).  The "test bed" is very controlled so I don't have items causing pings one day and not the next.  I bored out the tight fitting holder and hung the sensor in it with spacers to the sensor board 2 mounting holes and I didn't notice any change. I want to use this sensor and I know that this type of distance sensing isn't perfect, but I can't live with the "bad" days of the output. I can't enlarge the surface of the object being measured. I have tried changing all of the hardware with no change. I have tried USB 5v, 9vdc wall warts, and 4 x AA battery packs.  I have slowed the ping rate some. I have been trying to think through the possible problems (I will list some below):
Power pulsing (put a 1uF capacitor across the HC-SR04 Vcc and ground, and possibly across on the Arduino as well?).
Different sensor mounting (I don't know how much direct mechanical vibration problems there are at the receive barrel from the trigger).
Don't use pin13 due to the led.
The Arduino and bluetooth module need to be farther away from the sensor.
Use shielded cable instead of jumper wires.
Interference from something in the room.
Somehow pull the sensor farther back so I am not measuring the first 7" or so.
Maybe change to the HY SRF05 (I kind of doubt this will help).

Do you have any suggestions or do you think these sensors are just "flaky"?
Thank you.


Your full sketch and picture of your test jig may shed some light on things.  I have a bunch of sensors, and none have ever had a bad day.  My guess is that there's either a problem in your sketch, you're getting some type of environment noise, or there's something causing an echo reading.  The sketch and picture should lead us in the right direction.

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

Go Up