Thank you for a quick response.
I tried your suggestion, but it did not work:
sonarTrigger.write(false);
sonarEcho = ioio_.openPulseInput(
new DigitalInput.Spec(ECHO_PIN),
PulseInput.ClockRate.RATE_2MHz,
PulseInput.PulseMode.POSITIVE,
true);
sonarTrigger.write(true);
echoSeconds = sonarEcho.getDuration() * 1000 * 1000;
sonarEcho.close();
It hangs when trying to execute the getDuration() call after setting the
output high. Only now and then it might get one or to readings before
getting stuck.
However, when using a negative input mode, it consistently returned around
240us with a target, indicating the echo end pulse is detected.
Even adding a 1-5ms delay between the pulse open and output high made no
difference.
The hw and sw versions are:
hw is sprk0016
boot IOIO0306
firmware IOIO0326
and
IOIOllib 3.30
I tried the latest IOIOlib 5.02 but it requires a newer boot/firmware as
far as I can see from the error code trying to connect.
With my code as in the first post, I tried to connect an oscilloscope and
it shows a negative pulse of about 2ms (the low and high output) then a
short period before a negative pulse of about 200 us when a target is in
range.
Without a target, there is a very long time to the echo end. I was not able
to catch it, old 10Mhz scope.
What I meant in the first post, when I mentioned that the results varied ,
was that the echo end pulse width varied a lot.
The distance also varies, but that could be caused by extra reflections etc.
As my solution seems to work without hanging up, for the moment there is no
need to waste more of your time.
Maybe I some time later update the IOIO sw and try the latest IOIOlib.
Den torsdag den 30. januar 2014 18.13.14 UTC+1 skrev Ytai:
>
> I don't have "an answer", but a few things to try:
>
> 1. At first, simplify: ditch the echoCheck and stay with the negative
> pulse.
> 2. Try to open the pulse input AFTER setting your digital output low,
> then set it high and get a single reading from the pulse input (not the
> waitXXX version). Finally, close it. At least for now, this will eliminate
> any suspects in the form of synchronization problems (e.g. you're reading
> a
> value that has been generated before your output pulse actually went
> through).
> 3. Look at the signal with an oscilloscope or a logic analyzer if you
> have access to them.
>
>
>
> On Thu, Jan 30, 2014 at 4:01 AM, Carl Pedersen
> <[email protected]<javascript:>
> > wrote:
>
>> A bit late, but I have just got a DSM-IO Ultrasonic module which also has
>> one pin for a combined output and input.
>> I have also tried to connect with a DigitalOutput tied together with a
>> PulseInput (waitPulseGetDuration()) as many others have done, and it did
>> not work.
>>
>> As I have understood, a PulseInput requires two edges in order to fire,
>> and the DSM-IO only needs a negative pulse in order to start, then the line
>> is high until either an echo is received or a time-out reached.
>> According to the specs I have found, when a target is detected, a
>> negative pulse of about 150 us is used to indicate a target is found
>> whereas a 10ms pulse means no target within range.
>>
>> One solution is to use 3pins, two PulseInput plus one DigitalOut.
>> Presumably the DSM-IO is triggered on the positive going edge of the
>> trigger pulse, hence it should not matter if is 10us or several ms.
>> As I use a bluetooth connection, the length is probably as above, around
>> 40ms.
>>
>> To make it working, here is a cut from the code I have used for testing a
>> sonar-like implementation.
>>
>> sonarTrigger is the DigitaOut.
>> echoEnd is the PulesInput in NEGATIVE mode.
>> sonarEcho is the PulesInput in POSITIVE mode.
>>
>> sonarTrigger.write(false);
>> TimeUnit.MICROSECONDS.sleep(10); //I know, not needed
>> sonarTrigger.write(true);
>>
>> //Wait for echo end pulse
>> echoCheck = echoEnd.waitPulseGetDuration() * 1000 * 1000;
>> //Then get last echo length
>> echoSeconds = sonarEcho.getDuration() * 1000 * 1000;
>> echoDistCm = echoSeconds / 29 /2;
>>
>> The waitPulseGetDuration() should always be released as the DSM-IO module
>> always returns a negative pulse at the end.
>> In the meantime, getDuration() has been triggered on the positive edge of
>> the trigger pulse and the timing stops at the negative edge of the start of
>> the end pulse. This is stored in a double, echoSeconds.
>>
>> Obviously, there is a start delay, presumably 250us, which should be
>> subtracted from the result before calculating the distance.
>> The value in echoCheck might be used to accept/reject the distance.
>> However, using the debugger in eclipse for check, the results have varied
>> so I am not sure how it works.
>>
>>
>>
>> Den torsdag den 20. juni 2013 07.15.07 UTC+2 skrev Ytai:
>>>
>>> BTW, there are equivalent sensors with separate pins for input and
>>> output or, even simpler, with a single analog pin that presents a voltage
>>> that's proportional to the distance from the target, which can be read with
>>> an AnalogInput.
>>>
>>>
>>> On Thu, Jun 20, 2013 at 5:13 PM, Ytai Ben-Tsvi <[email protected]> wrote:
>>>
>>>> If you're talking about the parallax module that has a single pin for
>>>> both input and output, this might be a bit tricky...
>>>> You may pull this off by connecting two pins together, one working as a
>>>> PulseInput and the other as a DigitalOutput.
>>>> Read the wiki for beginBatch() / endBatch().
>>>>
>>>>
>>>> On Thu, Jun 13, 2013 at 2:30 AM, Vic Wintriss <[email protected]>wrote:
>>>>
>>>>> I'm using a parallax ultrasonic sensor on our robots. It requires a
>>>>> short pulse to start the ultrasonic ping.
>>>>>
>>>>> Do you have an example of how to use the beginBatch()/endBatch() with
>>>>> a digital output write(true), write(false) sequence?
>>>>>
>>>>> On Jun 12, 2013, at 4:42 AM, Ytai Ben-Tsvi <[email protected]> wrote:
>>>>>
>>>>> Over Bluetooth, this number is not unreasonable.
>>>>> You can get a much smaller width (a few usec) if you wrap these
>>>>> instructions with a beginBatch() / endBatch() loop.
>>>>> What is *really* the question here? There might be a better way to do
>>>>> what you're trying to do.
>>>>>
>>>>>
>>>>> On Wed, Jun 12, 2013 at 4:49 PM, Vic Wintriss <[email protected]>wrote:
>>>>>
>>>>>> What is the minimum pulse width I will get with the following
>>>>>> DigitalOutput code:
>>>>>>
>>>>>> rightStrobe.write(true);
>>>>>> rightStrobe.write(false);
>>>>>>
>>>>>> It looks like I am getting 40 millisecs with an android phone.
>>>>>>
>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "ioio-users" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send an email to [email protected].
>>>>>> To post to this group, send email to [email protected].
>>>>>>
>>>>>> Visit this group at http://groups.google.com/group/ioio-users?hl=en.
>>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to a topic in the
>>>>> Google Groups "ioio-users" group.
>>>>> To unsubscribe from this topic, visit https://groups.google.com/d/
>>>>> topic/ioio-users/YeZxBUL_Uto/unsubscribe?hl=en.
>>>>> To unsubscribe from this group and all its topics, send an email to
>>>>> [email protected].
>>>>>
>>>>> To post to this group, send email to [email protected].
>>>>>
>>>>> Visit this group at http://groups.google.com/group/ioio-users?hl=en.
>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "ioio-users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> To post to this group, send email to [email protected].
>>>>>
>>>>> Visit this group at http://groups.google.com/group/ioio-users?hl=en.
>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "ioio-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/ioio-users.
>>
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/groups/opt_out.