Hi all,
I would like to getting measurements from more than three Ultrasonic
sensors HC-SR04. Actually I have three sensors and everything works fine
but when I open fourth echoPin app stops working - "ioio disconnected". My
internal class Looper:
class Looper extends BaseIOIOLooper
{
private DigitalOutput triggerPin_;
private PulseInput echoPin_;
private DigitalOutput triggerPin2_;
private PulseInput echoPin2_;
private DigitalOutput triggerPin3_;
private PulseInput echoPin3_;
private DigitalOutput triggerPin4_;
private PulseInput echoPin4_;
@Override
protected void setup() throws ConnectionLostException
{
showVersions(ioio_, "IOIO connected!");
echoPin_ = ioio_.openPulseInput(6,
PulseInput.PulseMode.POSITIVE);
triggerPin_ = ioio_.openDigitalOutput(7);
echoPin2_ = ioio_.openPulseInput(9,
PulseInput.PulseMode.POSITIVE);
triggerPin2_ = ioio_.openDigitalOutput(10);
echoPin3_ = ioio_.openPulseInput(12,
PulseInput.PulseMode.POSITIVE);
triggerPin3_ = ioio_.openDigitalOutput(13);
echoPin4_ = ioio_.openPulseInput(3,
PulseInput.PulseMode.POSITIVE);
triggerPin4_ = ioio_.openDigitalOutput(4);
}
@Override
public void loop() throws ConnectionLostException,
InterruptedException
{
try
{
triggerPin_.write(false);
Thread.sleep(5);
triggerPin_.write(true);
Thread.sleep(1);
triggerPin_.write(false);
echoSecondsSensor1 = (int) (echoPin_.getDuration() *
1000000);
echoDistanceCmSensor1 = echoSecondsSensor1 / 58;
triggerPin2_.write(false);
Thread.sleep(5);
triggerPin2_.write(true);
Thread.sleep(1);
triggerPin2_.write(false);
echoSecondsSensor2 = (int) (echoPin2_.getDuration() *
1000000);
echoDistanceCmSensor2 = echoSecondsSensor2 / 58;
triggerPin3_.write(false);
Thread.sleep(5);
triggerPin3_.write(true);
Thread.sleep(1);
triggerPin3_.write(false);
echoSecondsSensor3 = (int) (echoPin3_.getDuration() *
1000000);
echoDistanceCmSensor3 = echoSecondsSensor3 / 58;
triggerPin4_.write(false);
Thread.sleep(5);
triggerPin4_.write(true);
Thread.sleep(1);
triggerPin4_.write(false);
echoSecondsSensor4 = (int) (echoPin4_.getDuration() *
1000000);
echoDistanceCmSensor4 = echoSecondsSensor4 / 58;
updateViews();
Thread.sleep(20);
} catch (InterruptedException e)
{
ioio_.disconnect();
} catch (ConnectionLostException e)
{
throw e;
}
}
2. I read that I can create new thread in setup and maybe that will solve
my issue, but I don't know exactly how can I do that. Code below doesn't
work
thread1 = new Thread(new Runnable()
{
@Override
public void run()
{
try
{
echoPin_ = ioio_.openPulseInput(6,
PulseInput.PulseMode.POSITIVE);
triggerPin_ = ioio_.openDigitalOutput(7);
}
catch (ConnectionLostException cle)
{
}
}
});
thread1.start();
Can anyone help?
Regards,
Bartek
--
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.