Ping repeat calls
I have several STAMPS and Arduino, and I sometimes use Parallax sensors on the Arduino. In this case the Ping sensor on the arduino mega. I am running into a problem with the ping mounted to a servo at 90 degrees and ping, turning it to 0 and ping, then 180 and ping again. Works perfectly on the first and second pings, but I can't seem to get it to ping on the third call, even if I change the sequence to 90, 0, and 180. Still won't ping on the third try. It doesn't seem to have anything to do with the servo, because I get the same results if the servo is disconnected. Before each call to the ping, I set the signal low for 2 microseconds and then high for 5 microseconds before I make the pin input and read it. Is there something about the timing on the ping that I should understand? I will be glad to post the code, but since it is arduino mega code, I figured I'd get stoned. Sorry if this is too vague. .
Comments
I knew it! Arduino users are stoners.
I noticed in the Propeller Ping object the pin is pulled low before making it an input. I'd be surprised if this matters, but I noticed in the part of your post I didn't intentionally misread, that you don't say that you pull the line low prior to making it an input. Again, I'd be surprised if this matters.
I say go ahead an post your code. Blame me if people complain. If they do, I'll get stoned with you.:zombie:
When you post code, it will help if you follow these directions.
BTW, welcome to the forum . . . dude.
(My attempts at humor are going to get me in trouble someday.)
https://sites.google.com/site/parallaxinretailstores/
Just move the servo, wait (delay) for the servo to transit to its position, then call the pinging code. Note the sequence of setting the pin direction as either an INPUT or an OUTPUT, and when an OUTPUT changing it from LOW to HIGH.
The code was developed for an Uno, but in this regard the Mega isn't any different.
-- Gordon
The ping works perfectly even with the servo for the first two tries (straight ahead (90) and at zero ), but not the third try at 180 (I know I have 170...trying anything). I tried switching the two loops and doing 180 first, and then zero, but it made no difference.
BTW, I discovered that the code works perfectly if the servo is not connected, so I think you're on the right track, but I just can't seem to get around it.
Thank you again for responding.
Servos pull a lot of current when they first start moving. I've had a bunch of projects that kept resetting when a servo started moving. Sometimes a 1000uF capacitor on the Vin line will provide enough juice to keep the uC happy while the servo starts to move. Other times a separate battery for the uC is required.
Thanks and I will get back to you as soon as I try it.
I left the ping on the arduino and put the servo on another power souce and it worked like a charm.
Thank you very much.
Well, on to the the next stupid mistake....
Charlie
I'm glad I could give some useful advice after razzing you about the arduino.
My current favorite is to forget to have my separate power supplies share a common ground connection. The servos sometimes, sort of, work without a shared ground with the uC.