Show Posts
Pages: 1 [2] 3 4 ... 31
16  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: March 04, 2014, 01:59:03 pm
To convert the results to millimeters, just multiply the centimeter results by 10.
multiplying adds 0 at the end nothing more...
You want it to print mm instead of cm in the console?
If so change the abbreviations in the sketch:
Code:
Serial.println("cm");
to
Code:
Serial.println("mm");
And do as  john21403 says to mathematically  convert cm to mm.
that changes only printed text ..


but i need real measured values in mm not  cm
because cm result is rounded to full cm, but i need to see fraction
and i cant find where the rounding process is in code..

Just use the ping() method instead of ping_cm() then do your own conversion from distance at the speed of sound to mm.  Without your sketch it's hard to tell you exactly what to do.  But, it would be something like this:

Code:
#include <NewPing.h>

NewPing sonar(12, 11, 200); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}

void loop() {
  delay(50);                     // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  Serial.print("Ping: ");
  Serial.print(sonar.ping()/6); // Send ping, get distance in mm and print result (0 = outside set distance range)
  Serial.println("mm");
}

Keep in mind, I'm dividing by 6 although 5.7 to 5.9 may yield more accurate distances, with the disadvantage of much larger and slower code to do floating point math.  So, you could do something like "sonar.ping()/5.7" if you'd like, but your code will be much larger.

Also, keep in mind that the sensor is not accurate down to a mm level, which is why people typically round to the cm level.  It can give very stable results at a cm level.  However, using the above sketch will give wildly different results each time with no consistency or even more accuracy.  Which is why others have just suggested that you multiply by 10 if you really just want to get a value in mm.  As it's no more accurate to use the above sketch, and if anything more confusing as the results are always different.

Tim
17  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: March 04, 2014, 12:39:01 pm
I am having problems compiling v1.5 for the Arduino Due. It compiles and works great for Uno, Mega 2560, Yun and Leonardo.

I am using the 1.5.5 version of the IDE on Ubuntu 13.10.

Here is the result of the compile:
Code:
In file included from NewPingExample.ino:5:
/home/afy/sketchbook/libraries/NewPing/NewPing.h:113: fatal error: avr/io.h: No such file or directory
compilation terminated.

I realize that this is an IDE issue, but am asking if it has already been solved for others.

Thanks.

NewPing uses port registers and timer interrupts and is therefore designed for ATmega microcontrollers.  With that said, v1.6 of NewPing will support non-AVR microcontrollers for all but the ping_timer() method.  Meaning the following methods will work:

ping()
ping_in()
ping_cm()
ping_median()
convert_in()
convert_cm()

The ping_timer() method will not be functional as custom timer interrupt code would need to be written for every microcontroller variant which at this point is a never-ending task with all the ARM-based mircocontrollers being used in different projects both Arduino and others (like Teensy 3.0/3.1).

Tim
18  Using Arduino / Audio / Re: toneAC v1.2 - Twice the volume, higher quality, higher frequency, etc. on: December 02, 2013, 12:06:20 pm
I found the following line in your code "uint8_t _tAC_volume[] = { 200, 100, 67, 50, 40, 33, 29, 22, 11, 2 }; // Duty for linear volume control.". What is the meaning of this? Can I adapt this to realize my task?

Maybe it is possible to change it to something like: toneAC(freq, pulse_length,...) ?

The _tAC_volume array modifies the duty cycle depending on the volume you set.  It's not linear because linear doesn't provide an accurate sound output level.  It needs to be more logarithmic to make it sound correct.

If you want more linear steps, you could simply modify the _tAC_volume array to something linear that works for your task.  Not sure how well this would work, as toneAC is designed for audio output.  I would say when using toneAC for other tasks you should always use full volume as the volume is a hack that just happens to work for speakers.

Tim
19  Using Arduino / Sensors / Re: Distance measurement - need an alternative to sharp ir and ultrasound on: September 25, 2013, 11:13:12 am
Hi!
I need to know if there is a way to measure distance without the use of infrared and ultrasonic? The range will be between 3cm to 5m with +-1cm of accuracy and it needs to be fast. I am building soccer robots which track a ball with infrared light. So I can't used Sharp IR sensors because of interference or ultrasound sensors as they are too slow. Something very similar to the Sharp IR would be awesome!

I was looking into laser range sensors but have not had any luck with finding any.

Ultrasonic can sense distance 30 times a second.  Do you need it to be faster than that?

Tim
20  Using Arduino / Sensors / Re: Help interfacing with this ultrasonic sensor - DYP-ME007Y on: September 25, 2013, 11:11:18 am
That's what I imagined and, I thought that's what I was doing since I set the pin High for a specified time and bring it back down again, and afterwards, I'm measuring how long the echo pin stays high to derive the distance from the pulse width.

Nothing to do with pulse width.

Tim
21  Using Arduino / Sensors / Re: Help interfacing with this ultrasonic sensor - DYP-ME007Y on: September 25, 2013, 10:49:57 am
What does the PWM stand for, and what is it used for? Sorry for my ignorance, just interested to learn what's going on.

I used 12 and 11, as per one of the examples I found regarding your NewPing library. So since I'm using 10,11 now, I suppose this means 12 may be broken.

Marc

PWM is pulse width modulation.  These pins can be used to create a pulsed output at specific timing.

It's possible there's a problem with pin 12, or it could be that you had 11 and 12 switched, or a host of other possibilities. Best way to know is to switch just one of the pins that currently works with pin 12, then trying the other.  It's possible it only works for output and not input for example.

Tim
22  Using Arduino / Sensors / Re: Help interfacing with this ultrasonic sensor - DYP-ME007Y on: September 25, 2013, 09:07:38 am
Hi,

I managed to get some life out of this sensor this morning (chuffed, because I'm just starting with this stuff!).
I receveid a document from the manufacturer (in attachment). Despite that I didn't get it to work, until this morning. What did I change? Well I thought maybe I've destroyed the pins I was using with all my hapless trial and error, so I thought I would change the pins being used. Also, I found it to be confusing to have the trigger on a higher pin than the echo.
So when I looked at the Arduino to change the pins, I saw that some pins are marked ~ and on the corner of the arduino the following is "(PWM ~)" is etched. So I connected it to two ~ pins: 10 for Trigger & 11 for Echo. And suddenly it came alive!. This is my sketch

And its output seems to be as described in the document. 35ms if there is nothing detected, and a distance which seems to be correct when something is held at a distance of the sensor.

If you manage to integrate this sensor into the NewPing library please update this thread.

As you're not doing anything with PWM, it seems the "fix" was not that you're using PWM pins, but the pins you were using before don't work or you had them connected wrong.  What pins were you using before?

Tim
23  Using Arduino / Sensors / Re: help ultrasonic sensor and dc motor code on: September 20, 2013, 12:13:03 pm
and look at this code based on it :

Awesome!  So what is it supposed to do?  Does it work?  If not, what doesn't it do?

Tim

well... what am trying to do is to make the sensor read the dist after switching on the switch .. then when distance under a specific number ( here i just converted the distance to be as read from the sensor in microseconds) the motor of my robot arm will start moving towards the object in front of it ... but now am trying with 1 motor ... everything is working oky except in One place :
 else if( sonar.ping() <10000000000000000000000000000000000000000000000000000000000000000000000000000000000 ){ // the number is any microseconds 
    digitalWrite(enablePinHbridge, HIGH);
    digitalWrite(motor1Pin,HIGH);
    digitalWrite(motor2Pin,LOW);}
***********************************************************************
which is actually the basic of all the work smiley-sad
so I made this mapping and constrain instead ... but still not working... I think my mistake is in this place .. look at this one ;

else if( sonar.ping() <10000000000000000000000000000000000000000000000000000000000000000000000000000000000 ){ // the number is any microseconds
 float dist;// for the distance
     dist=analogRead(ECHO_PIN);
     dist=map(ECHO_PIN,0,1023,0,255);
     dist=constrain(ECHO_PIN,0,255);
    digitalWrite(enablePinHbridge, HIGH);
    analogWrite(motor1Pin,dist);
    digitalWrite(motor2Pin,LOW);}
**********************************************************
other things like connections and volts and current are working perfectly  ... but the code not !


What's with the huge number?  Maybe use a number within the range of the variable?

Tim
24  Using Arduino / Sensors / Re: help ultrasonic sensor and dc motor code on: September 20, 2013, 10:05:00 am
And how about some code tags this time?

Amen.
25  Using Arduino / Sensors / Re: Help interfacing with this ultrasonic sensor - DYP-ME007Y on: September 20, 2013, 10:04:29 am
The plan is to test this sensor in the near future.  I've been really busy the last few weeks and haven't had a chance.

Tim
26  Using Arduino / Sensors / Re: help ultrasonic sensor and dc motor code on: September 20, 2013, 07:45:48 am
and look at this code based on it :

Awesome!  So what is it supposed to do?  Does it work?  If not, what doesn't it do?

Tim
27  Using Arduino / Sensors / Re: help ultrasonic sensor and dc motor code on: September 19, 2013, 02:07:17 pm
I fixed those mistakes, and made it this code :

I suggest throwing your code out and using NewPing instead.  If you still have a problem, make sure you also state what you expect your code to do and what it is doing, not just that it's not working right.

Tim
28  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: September 19, 2013, 02:01:03 pm
I moved over to the Arduino base ping sensor and was getting to many fluctuations and problems with the built in delay... so I tried your version. Much better, but I am having issues with the LEDs. The fade kinda works however it is incredibly slow, and flickers and locks on and never goes off sometimes. The original fade, builds in fairly quickly and builds out after a set time if no ones around.

The whole installation works like this, as some one approaches the LED is triggered and it fades up, if you don't get inside the set distance then it fades back out, if you get inside or stand for a brief period of time the LED locks on for a set amount of time then if the sensor goes back to reading outside of the set distance the LED fades out but only after a set amount of time.

Probably best to first take a look at my Help for the 15 Sensors Example Sketch.  My guess is that you want to constantly make changes to the LED brightness and not just after a ping happens.  Better understanding and other example code for using the 15 sensor example sketch may help.  Without building your circuit, I can't really tell what you're trying to accomplish or why it's not working.  If the distances you are getting from the sensors using NewPing are correct, then the problem must be either with when you're executing the rest of the code or what your other code is doing.

Tim
29  Using Arduino / Audio / Re: RTTTL Library - Without the tone library on: August 28, 2013, 11:50:09 am
Hi, due to an incompatibility with my current program, I can not use the Tone library to play RTTL files, is there another library in which I can do this?

If there's a timer 2 compatibility issue and as a result you can't use the tone library, you can instead use my NewTone library which uses timer 1 instead.  NewTone is a drop-in replacement for tone so it would be very simple to impliment.

Another option (and maybe a better one) would be to use my toneAC library which also uses timer 1 and has many other benefits (twice as loud, uses fewer cpu cycles, more accurate, etc.).  It's not designed to be a drop-in replacement, and you would be limited to using specific pins for driving the speaker.  But, with very little effort you would have technically a better solution.  If nothing else, it would be louder (or allow you to control the volume).

Tim
30  Using Arduino / Audio / Re: Beep Sound on: August 28, 2013, 11:41:22 am
Frequency of beep, length of beep, and time between beeps.  It's then just a loop.

Tim
Pages: 1 [2] 3 4 ... 31