Adding another GPIO channels
Hi, I am a mbientlab metawear RG sensor user. I connected the board with 2 pressure sensors on GPIO Pin 2 and Pin 3. My project dependence is com.mbientlab:metawear:2.5.0. If I use one gpio, the graph can display normally. But if i add another gpio,the two gpio values will interfere with each other.My code shows as follows.I do not know why it happened.
---------------------------------------------------------------------------------------------------------------
private final AsyncOperation.CompletionHandler<RouteManager> GpioStreamSetup_2 = new AsyncOperation.CompletionHandler<RouteManager>() {
@Override
public void success(RouteManager result) {
streamRouteManager2 = result;
result.subscribe(streamKey2, new RouteManager.MessageHandler() {
@Override
public void process(Message message) {
final short gpioValue2 = message.getData(Short.class);
......
}
}
}
}
private final AsyncOperation.CompletionHandler<RouteManager> GpioStreamSetup_3 = new AsyncOperation.CompletionHandler<RouteManager>() {
@Override
public void success(RouteManager result) {
streamRouteManager3 = result;
result.subscribe(streamKey3, new RouteManager.MessageHandler() {
@Override
public void process(Message message) {
final short gpioValue3 = message.getData(Short.class);
......
}
}
}
}
-------------------------------------------------------------------------------------
protected void setup() {
gpioModule_2.routeData().fromAnalogIn(gpioPin2, Gpio.AnalogReadMode.ADC).stream(streamKey).commit()
.onComplete(GpioStreamSetup_2);
gpioModule_3.routeData().fromAnalogIn(gpioPin3, Gpio.AnalogReadMode.ADC).stream(streamKey_3).commit()
.onComplete(GpioStreamSetup_3);
timerModule_2.scheduleTask(new Timer.Task() {
@Override
public void commands() {
gpioModule_2.readAnalogIn(gpioPin2, Gpio.AnalogReadMode.ADC);
gpioModule_3.readAnalogIn(gpioPin3, Gpio.AnalogReadMode.ADC);
}
}, GPIO_SAMPLE_PERIOD, false).onComplete(new AsyncOperation.CompletionHandler<Timer.Controller>() {
@Override
public void success(Timer.Controller result) {
result.start();
}
});
}
This discussion has been closed.
Comments
01-20 11:07:45.222 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 621
01-20 11:07:45.273 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 1
01-20 11:07:45.273 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 618
01-20 11:07:45.317 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 1
01-20 11:07:45.320 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 1
01-20 11:07:45.389 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 618
01-20 11:07:45.424 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 622
01-20 11:07:45.463 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 1
01-20 11:07:45.465 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 620
01-20 11:07:45.524 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 621
01-20 11:07:45.524 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 1
01-20 11:07:45.524 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 619
01-20 11:07:45.560 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 1
01-20 11:07:45.562 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 619
01-20 11:07:45.624 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 1
01-20 11:07:45.630 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 621
01-20 11:07:45.633 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 621
01-20 11:07:45.724 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 620
01-20 11:07:45.758 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 623
01-20 11:07:45.759 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 1
01-20 11:07:45.765 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 613
01-20 11:07:45.805 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 618
01-20 11:07:45.859 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 1
01-20 11:07:45.902 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 622
01-20 11:07:45.999 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 1
01-20 11:07:46.006 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 626
01-20 11:07:46.059 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 627
01-20 11:07:45.222 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 621
01-20 11:07:45.273 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 1
01-20 11:07:45.273 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 618
01-20 11:07:45.317 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 1
01-20 11:07:45.320 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 1
01-20 11:07:45.389 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 618
01-20 11:07:45.424 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 622
01-20 11:07:45.463 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 1
01-20 11:07:45.465 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 620
01-20 11:07:45.524 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 621
01-20 11:07:45.524 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 1
01-20 11:07:45.524 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 619
01-20 11:07:45.560 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 1
01-20 11:07:45.562 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 619
01-20 11:07:45.624 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 1
01-20 11:07:45.630 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 621
01-20 11:07:45.633 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 621
01-20 11:07:45.724 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 620
01-20 11:07:45.758 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 623
01-20 11:07:45.759 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 1
01-20 11:07:45.765 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 613
01-20 11:07:45.805 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 618
01-20 11:07:45.859 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 1
01-20 11:07:45.902 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 622
01-20 11:07:45.999 18253-18253/com.mbientlab.metawear.app W/module: gpioValue2 is 1
01-20 11:07:46.006 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 626
01-20 11:07:46.059 18253-18253/com.mbientlab.metawear.app W/module: gpioValue3 is 627
protected void setup() {
gpioModule_2.routeData().fromAnalogIn(gpioPin2, Gpio.AnalogReadMode.ADC).stream(streamKey_2).commit()
.onComplete(GpioStreamSetup_2);
gpioModule_2.routeData().fromAnalogIn(gpioPin3, Gpio.AnalogReadMode.ADC).stream(streamKey_3).commit()
.onComplete(GpioStreamSetup_3);
timerModule_2.scheduleTask(new Timer.Task() {
@Override
public void commands() {
gpioModule_2.readAnalogIn(gpioPin2, Gpio.AnalogReadMode.ADC);
// gpioModule_2.readAnalogIn(gpioPin3, Gpio.AnalogReadMode.ADC);
}
}, GPIO_SAMPLE_PERIOD, false).onComplete(new AsyncOperation.CompletionHandler<Timer.Controller>() {
@Override
public void success(Timer.Controller result) {
result.start();
}
});
}
Then gpioValue2 and gpioValue3 will not interfere with each other.But the gpioValue3 is digital,i need analog values.
I again change my code like this :