getDuration() would return you whatever last pulse width was measured last.
What you want is to add a ioio_.sync() followed by input.getDurationSync(),
which will guarantee that the pulse has been obtained after the strobe.
However, looking at this now, there's a small chance that you'll miss the
pulse this way. Ideally, the sync() call would have its "send" half inside
the batch and "wait" half outside. Unfortunately, this is not currently
possible (although easy enough to add if you need to).


On Sun, Apr 13, 2014 at 7:22 PM, Vic Wintriss <[email protected]> wrote:

> I am trying to use the Parallax Ping))) ultrasonic sensor with a ioio V1
> board, using the IOIO00503 library.  I get a good looking signal...see the
> attached scope view, but the input.getDuration() call returns 16.8 micro
> seconds most of the time, called 2 times per second.  Every once in a while
> I get the proper number.
>
>  Any ideas? Here is the code:
>
> import ioio.lib.api.DigitalOutput;
>
> import ioio.lib.api.IOIO;
>
> import ioio.lib.api.PulseInput;
>
> import ioio.lib.api.PulseInput.PulseMode;
>
> import ioio.lib.api.exception.ConnectionLostException;
>
>
> public class UltraSonicSensors
>
> {
>
> private static final int LEFT_ULTRASONIC_INPUT_PIN = 35;
>
> private static final int LEFT_STROBE_ULTRASONIC_OUTPUT_PIN = 15;
>
> private final PulseInput leftInput;
>
> private DigitalOutput leftStrobe;
>
> private float leftDistance;
>
> private IOIO ioio;
>
>
>  public UltraSonicSensors(IOIO ioio) throws ConnectionLostException
>
> {
>
>  this.leftInput = ioio.openPulseInput(LEFT_ULTRASONIC_INPUT_PIN,
> PulseMode.POSITIVE);
>
>  this.leftStrobe = ioio.openDigitalOutput(
> LEFT_STROBE_ULTRASONIC_OUTPUT_PIN);
>
>  this.ioio = ioio;
>
> }
>
>
>  public void read() throws ConnectionLostException, InterruptedException
>
> {
>
>  read(leftStrobe, leftInput);
>
> }
>
>
>  private void read(DigitalOutput strobe, PulseInput input) 
> throwsConnectionLostException, InterruptedException
>
> {
>
>  ioio.beginBatch();
>
>  strobe.write(true);
>
>  strobe.write(false);
>
>  ioio.endBatch();
>
>  this.leftDistance =  input.getDuration();
>
> }
>
>
>  public float getLeftDistance()
>
> {
>
>  return leftDistance;
>
> }
>
> }
>
> --
> 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/d/optout.
>

-- 
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/d/optout.

Reply via email to