bulut

Have you tried connecting it and using the sample NewPing sketch? By the pin labels, it sounds like it could work as-is. The 120V is a little confusing, but the specs seems a little thin to begin with. Got a picture or more information?

Tim[/quote]

i tried simple new ping sketch but it just reads up to 40cm and not so much accurate , in you sketch the ping pulse is 1 pulse with 10us width i think if we manipulate the code to 2 or 3 pulses with 16us width it will solve my problem,and i think we have to increase the frequency too.how should we change the code?

bulut

*_triggerOutput &= ~_triggerBit; // Set the trigger pin low, should already be low, but this will make sure it is.delayMicroseconds(4); // Wait for pin to go low, testing shows it needs 4uS to work every time.*_triggerOutput |= _triggerBit; // Set trigger pin high, this tells the sensor to send out a ping.delayMicroseconds(10); // Wait long enough for the sensor to realize the trigger pin is high. Sensor specs say to wait 10uS.*_triggerOutput &= ~_triggerBit; // Set trigger pin back to low.

i need 16 bursts with period of 21us and frequency of 40KHZ for my trigger , how should i change the code?

i tried simple new ping sketch but it just reads up to 40cm and not so much accurate , in you sketch the ping pulse is 1 pulse with 10us width i think if we manipulate the code to 2 or 3 pulses with 16us width it will solve my problem,and i think we have to increase the frequency too.how should we change the code?

The 1 pulse / 10uS width is just to trigger the sensor. The sensor detects this and then sends out it's own multiple pulses. In other words, the sensor doesn't just send out one 10uS pulse, we just trigger it. I have not seen a sensor that doesn't automatically send out multiple pulses from a trigger. Are you sure it's not ready doing this? The fact that it reads distances appears that it's working. Do you even know the maximum sensor distance? Maybe it's only 40cm. Also, you may need to change the uS to CM conversion if your sensor puts out different values. The URM37 sensor is a good example of this. For the URM37 you set US_ROUNDTRIP_CM to 50, as that's how it converts and outputs the distance values.

bulut

The 1 pulse / 10uS width is just to trigger the sensor. The sensor detects this and then sends out it's own multiple pulses. In other words, the sensor doesn't just send out one 10uS pulse, we just trigger it. I have not seen a sensor that doesn't automatically send out multiple pulses from a trigger.

i know it how the sensor works but this sensor dosnt operate with 1 pulse / 10 us it works with 16 pulses with period of 21us and frequency of 40KHZ if i can apply this to my sensor it will work, now i just want to know how should i produce this 16 pulses(40KHZ)

Quote

Do you even know the maximum sensor distance? Maybe it's only 40cm

the maximum is 5 meter , it reads 40cm but not accurate it has 13cm error.

So, you're trying to use just the sensor without the control board? Many people have tried doing this and I have yet to hear of anyone who was successful. The same is true with the typical HC-SR04 type sensors. You can't just use the sensors without the control board.

Basically, if you want to use these sensors, you're going to need to interface with the control board, not the sensors directly. It's not something that can be fixed with software. You need hardware to amplify the signals, issue the pings, etc. You can't just connect them to an Arduino, they won't work that way.

believe me if we apply the 16 pulses with 21us period with 40KHZ frequency i will be work i am sure, so please tell me how to change the code to produce this pulses .

The NewPing library doesn't do the ultrasonic pulses. It only triggers the control board which does the pulses. It's very odd that this control board doesn't do these pulses (that's one of the duties of the control board). I've never heard of a control board that doesn't do the required pulses that the control board's decoder requires. It only makes sense that the control board would issue the correct pulses that it needs on the decode side. It could be how you're doing the ping trigger. Maybe you're not doing the trigger, but actually just a single fire? In other words, maybe you're connecting to the wrong place on the control board.

In any case, doing these pulses is outside the scope of the NewPing library as it would drastically change things and be specific to one individual control board.

What you'll need to do is create your own control function or library. In order to do the pulses with accuracy, you'll need to look into PWM. I don't think the standard Arduino PWM will work as you need to set a frequency of around 47 kHz (21uS) while the maximum Arduino PWM is 1 kHz. Using timers you can get as high as 64 kHz, but I believe the next step would be 32 kHz so you could still have a problem.

I'd really try to get the control board to do the correct pulses (that's its job anyway). If you can't, try looking for PWM library that can do high frequency pulses.

vsodhani

I am using the new Ping library with my code and have hit a dead end. My code is running a SparkFun stepper motor in a loop where it slowly increments the RPM. I eventually want to control the speed based on the distance measurement from my Ping((( sensor, but I've dumbed it down to find the error. It's not the best code for my motor, but for example sake it works. The problem is that even though I use the ping_timer like in the example calling:

sonar.ping_timer(echoCheck);

stops the motor from moving. once I comment that line out the motor starts working again. below is the code. any ideas?

void loop(){ // Notice how there's no delays in this sketch to allow you to do other processing in-line while doing distance pings.

if (millis() >= pingTimer) { // pingSpeed milliseconds since last ping, do another ping. pingTimer += pingSpeed; // Set the next ping time. sonar.ping_timer(echoCheck); // Send out the ping, calls "echoCheck" function every 24uS where you can check the ping status. }

Serial.print("setting RMP = "); Serial.println(rpm); motor.setSpeed(rpm); Serial.println(); Serial.println(); motor.step(100, FORWARD, SINGLE); rpm = rpm +10; delay(1000);} void echoCheck() { // Timer2 interrupt calls this function every 24uS where you can check the ping status. // Don't do anything here! if (sonar.check_timer()) { // This is how you check to see if the ping was received. // Here's where you can add code. Serial.print("Ping: "); Serial.print(sonar.ping_result / US_ROUNDTRIP_CM); // Ping returned, uS result in ping_result, convert to cm with US_ROUNDTRIP_CM. Serial.println("cm"); }

if (millis() >= pingTimer) { // pingSpeed milliseconds since last ping, do another ping. pingTimer += pingSpeed; // Set the next ping time. sonar.ping_timer(echoCheck); // Send out the ping, calls "echoCheck" function every 24uS where you can check the ping status. }

I am using the new Ping library with my code and have hit a dead end. My code is running a SparkFun stepper motor in a loop where it slowly increments the RPM. I eventually want to control the speed based on the distance measurement from my Ping((( sensor, but I've dumbed it down to find the error. It's not the best code for my motor, but for example sake it works. The problem is that even though I use the ping_timer like in the example calling:

sonar.ping_timer(echoCheck);

stops the motor from moving. once I comment that line out the motor starts working again. below is the code. any ideas?

I'd start debugging this by removing the Serial.print/Serial.println stuff inside the echoCheck subroutine. This is only there for a test, you should eventually replace it with code that processes the ping result. But for now you can simply delete it. If it still doesn't work correctly, it could be that the AFMotor library is also using the same timer that NewPing is using to do the stepper motor control.

Also, cyclegadget is correct, you're not really using the pingTimer correctly. Both ping_timer() and the pingTimer variable are designed to be used WITHOUT delays. If you're using delays, it's going to not work correctly.

Basically, if you're going to use delays, you should not use any of the polling (pingTimer) stuff and shouldn't use the ping_timer() method. You should just use the standard ping() method. If you want to create a more event driven sketch, you need to be comfortable with not using delay commands.

I simplified your sketch and used the standard ping() method (well, ping_cm() which is ping that converts the result to centimeters). This may make more sense and be a closer fit to what you're trying to do.

that code was taken straight from the NewPingEventTimer example code, and as far as I can tell should not always be true.

It is always true, because you're adding delays and telling it to start right away, yet then adding a full second delay. Basically, you need to either create an event driven/polling type sketch, or one with delays. Combining the two could give you problems.

It doesn't seem you're comfortable with an event driven/polling type sketch. So, you shouldn't really try to use any example NewPing sketch that uses the ping_timer() method. Stick with ping(), ping_cm(), ping_in(), and ping_median() till you're comfortable with not using the delay() command in your sketch.

vsodhani

thank you for your response. i am new to events. so i tried taking out all the delays and also tried calling the ping function directly but i had the same results. i'm going to look into the adafruit motor library to see if it is using the timer as the new ping library.