Adding another GPIO channels

edited January 2018 in Android
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();
}
});
}

Comments

  • Post the code that is actually adding data to the graph.
  • edited January 2018
    private final AsyncOperation.CompletionHandler<RouteManager> GpioStreamSetup_2 = new AsyncOperation.CompletionHandler<RouteManager>() {
    @Override
    public void success(RouteManager result) {
    streamRouteManager = result;
    result.subscribe(streamKey_2, new RouteManager.MessageHandler() {
    @Override
    public void process(Message message) {
    final short gpioValue2 = message.getData(Short.class);
    LineData data = chart.getData();
    if (startTime == -1) {
    data.addXValue("0");
    startTime = System.currentTimeMillis();
    } else {
    data.addXValue(String.format(Locale.US,"%.2f", sampleCount_2 * samplingPeriod));
    }

    temp2 = (float) (gpioValue2 *0.056 -1.287);
    if(temp2<0){
    temp2=0;
    }
    data.addEntry(new Entry(temp2, sampleCount_2), 0);
    Log.w("pressure", "temp2 is " + temp2);
    savaPressure(temp2);
    sampleCount_2++;
    if (atomicBoolean.get()) {
    UpdatePressure();
    Log.w("gpiopressure", "send" + System.currentTimeMillis() + "ppppp" + PublicStatic.UploadFrequence);
    atomicBoolean.compareAndSet(true, false);
    }

    }

    });

    }

    };
    ----------------------------------------------------------------------
    I added one gpio values to one graph like that,in my project ,I used two gpio pin ,the problem is if i use two gpio pin ,the two gpio values will interfere with each other.I found the problem existed in the code as follows:
    -----------------------------------------------------------------------
    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();
    }
    });
    --------------------------------------------------------------------------
    But i do not know how to solve it.
  • What is GpioStreamSetup_3?

    It sounds like your code is adding points to the same data series instead of using 2 data series.
  • edited January 2018
    private final AsyncOperation.CompletionHandler<RouteManager> GpioStreamSetup_3 = new AsyncOperation.CompletionHandler<RouteManager>() {
    @Override
    public void success(RouteManager result3) {
    streamRouteManager_3= result3;
    result3.subscribe(streamKey_3, new RouteManager.MessageHandler() {
    @Override
    public void process(Message message) {
    final short gpioValue3 = message.getData(Short.class);
    LineData data2 = chart2.getData();
    if (startTime1 == -1) {
    data2.addXValue("0");
    startTime1 = System.currentTimeMillis();
    } else {
    data2.addXValue(String.format("%.2f", sampleCount_3 * samplingPeriod));
    }
    temp3 = (float) (gpioValue3 *0.056 -1.287);
    if(temp3<0){
    temp3=0;
    }
    data2.addEntry(new Entry(temp3, sampleCount_3), 0);
    Log.w("pressure", "temp3 is " + temp3);
    //savaPressure(temp3);
    sampleCount_3++;
    if (atomicBoolean.get()) {
    UpdatePressure();
    atomicBoolean.compareAndSet(true, false);
    }
    }
    });
    }
    };
    ----------------------------------------------
    Thank you for your answer.Maybe you are right,my datas from two gpio pins are added to the same data series,but I do not know where is the data series code. 
  • Checkout the barometer code for examples on drawing multiple lines on the same chart.
  • Hi,Eric.
    In my project ,if i only press the sensor on Gpio3,then datas of gpio2 and gpio3 showing in two charts are as following.In fact ,the gpioValue2 should be 1,but now ,gpioValue2 and gpioValue3  interfere with each other.How can I distinguish them, and where is the main code ?

    -------------------------------------------------------------------------
    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
    ---------------------------------------------------------------------
  • Please post some screens that illustrate the problem you are having and post the full code.

    Have you taken a look at the barometer code as previously suggested?
  • edited January 2018
    public class GpioPressueFragment extends SingleDataSensorFragment {
    private static java.util.Timer timer = new java.util.Timer(true);
    private static AtomicBoolean atomicBoolean = new AtomicBoolean(true);

    private TimerTask task;
    private final String streamKey_2= "gpio_2_stream";
    private final String streamKey_3= "gpio_3_stream";
    private static final int GPIO_SAMPLE_PERIOD = 33;

    private SharedPreferences mySharedPreferences;
    private SharedPreferences userInfoSharePreferences;
    private SharedPreferences.Editor editor;

    public static float temp2;
    public static float temp3;
    private byte gpioPin2 = 2;
    private byte gpioPin3 = 3;
    private int readMode = 0;
    private int chartSet = 0;
    private Gpio gpioModule_2;
    // private Gpio gpioModule_3;
    private Timer timerModule_2;
    // private Timer timerModule_3;
    private long startTime = -1;
    private long startTime1 = -1;
    private OkHttpUtil httpUtil = new OkHttpUtil();
    private float pressure_max, pressure_min, pressure_average;
    private int count = 1;
    private DecimalFormat df = new DecimalFormat("0.00");


  • edited January 2018
     private final AsyncOperation.CompletionHandler<RouteManager> GpioStreamSetup_2 = new AsyncOperation.CompletionHandler<RouteManager>() {
    @Override
    public void success(RouteManager result) {
    streamRouteManager = result;
    result.subscribe(streamKey_2, new RouteManager.MessageHandler() {
    @Override
    public void process(Message message) {
    final short gpioValue2 = message.getData(Short.class);
    LineData data = chart.getData();
    if (startTime == -1) {
    data.addXValue("0");
    startTime = System.currentTimeMillis();
    } else {
    data.addXValue(String.format(Locale.US,"%.2f", sampleCount_2 * samplingPeriod));
    }

    Log.w("module", "gpioValue2 is " + gpioValue2);

    temp2 = (float) (gpioValue2 *0.056 -1.287);
    if(temp2<0){
    temp2=0;
    }
    data.addEntry(new Entry(temp2, sampleCount_2), 0);
    savaPressure(temp2);
    sampleCount_2++;
    if (atomicBoolean.get()) {
    UpdatePressure();
    Log.w("gpiopressure", "send" + System.currentTimeMillis() + "ppppp" + PublicStatic.UploadFrequence);
    atomicBoolean.compareAndSet(true, false);
    }

    }

    });

    }

    };

  • edited January 2018
    private final AsyncOperation.CompletionHandler<RouteManager> GpioStreamSetup_3 = new AsyncOperation.CompletionHandler<RouteManager>() {
    @Override
    public void success(RouteManager result) {
    streamRouteManager_3= result;
    result.subscribe(streamKey_3, new RouteManager.MessageHandler() {
    @Override
    public void process(Message message) {
    final short gpioValue3 = message.getData(Short.class);
    LineData data2 = chart2.getData();
    if (startTime1 == -1) {
    data2.addXValue("0");
    startTime1 = System.currentTimeMillis();
    } else {
    data2.addXValue(String.format("%.2f", sampleCount_3 * samplingPeriod));
    }
    Log.w("module", "gpioValue3 is " + gpioValue3);
    temp3 = (float) (gpioValue3 *0.056 -1.287);
    if(temp3<0){
    temp3=0;
    }
    data2.addEntry(new Entry(temp3, sampleCount_3), 0);
    Log.w("pressure", "temp3 is " + temp3);
    sampleCount_3++;
    if (atomicBoolean.get()) {
    UpdatePressure();
    atomicBoolean.compareAndSet(true, false);
    }

    }

    });

    }

    };

  • edited January 2018
    private void UpdatePressure() {
    JSONObject json = new JSONObject();
    try {
    json.put("sensorData1", temp2);
    json.put("sensorData2",temp3);
    json.put("sensorData3", 0);
    json.put("sensorData4", 0);
    json.put("count", 0);
    json.put("gait", 0);
    json.put("time", System.currentTimeMillis());
    json.put("patientMobile",userInfoSharePreferences.getString("id","0"));
    } catch (JSONException e) {
    e.printStackTrace();
    }
    httpUtil.postJson(HttpUrl.NLF_DATA, json.toString(), getActivity(), new OkHttpUtil.HttpCallBack() {
    @Override
    public void onSusscess(JSONObject data) {
    return;
    }
    });
    }

    class AutomicSetBooleanTask extends TimerTask {
    public void run() {
    Log.w("send", "senddddd");
    atomicBoolean.set(true);
    }
    }

    public GpioPressueFragment() {
    super(R.string.navigation_fragment_gpio, "adc", R.layout.fragment_gpio, GPIO_SAMPLE_PERIOD / 1000.f, 0, 1023);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    return super.onCreateView(inflater, container, savedInstanceState);
    }
    @Override
    public void onViewCreated(final View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    userInfoSharePreferences = getActivity().getSharedPreferences("user_login",
    Activity.MODE_PRIVATE);
    mySharedPreferences = getActivity().getSharedPreferences("pressuresHistory",
    Activity.MODE_PRIVATE);
    editor = mySharedPreferences.edit();



    if (task != null)
    {
    task.cancel();
    }

    task = new AutomicSetBooleanTask();

    Log.w("gpiopressure", "Upload");
    timer.schedule(task, 0, PublicStatic.UploadFrequence);
    max = 60;
    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setAxisMaxValue(max);
    leftAxis.setLabelCount(2,false);

    YAxis leftAxis2 = chart2.getAxisLeft();
    leftAxis2.setAxisMaxValue(max);
    leftAxis2.setLabelCount(2,false);
    }

  • edited January 2018
    @Override
    protected void boardReady() throws UnsupportedModuleException
    {
    gpioModule_2 = mwBoard.getModule(Gpio.class);
    // gpioModule_3 = mwBoard.getModule(Gpio.class);
    timerModule_2 = mwBoard.getModule(Timer.class);

    }

    @Override
    protected void fillHelpOptionAdapter(HelpOptionAdapter adapter)
    {
    adapter.add(new HelpOption(R.string.config_notice, R.string.config_contect));
    }

    @Override
    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();
    }
    });
    }


    @Override
    protected void clean() {
    timerModule_2.removeTimers();
    }

    @Override
    protected void resetData(boolean clearData) {
    super.resetData(clearData);
    if (clearData) {
    startTime = -1;
    startTime1 = -1;
    }
    }
    }
  • Hi,I have posted the full code.But I do not know how to post imag of my chats.And I have taken a look at the barometer code as previously suggested.

    The problem is ,In my project ,if i only press the sensor on Gpio3,then datas of gpio2 and gpio3 showing in two charts are as following.In fact ,the gpioValue2 should be 1,but now ,gpioValue2 and gpioValue3  interfere with each other.How can I distinguish them, and where is the main code ?

    -------------------------------------------------------------------------
    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
    ---------------------------------------------------------------------
  • edited January 2018
    • Do you have the sensors correctly connected to the gpio pins?  This interference you are describing could be due to the sensors being incorrectly writed.
    • Does the same issue with gpioValue2 if you repeat the test but don't use the data route for gpio pin 3?
    • What do you mean by "where is the main code"?  

    What I'm getting at is that you need to start eliminating potential causes of error.  For example, start with a blank app and try to stream gpio data from the two pins to Logcat.  If that works, then add in the graphs.  If not, then you can start to narrow down the root cause.
  • edited January 2018
    Question1: I connected pressure  sensors  to the gpio pin2 and the gpio pin3 refering to the instruction manual.
    Question2: If I do like this:(The code for gpioPin3 is annotated)
      @Override
    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  the chat showing values of gpioPin2 is correct,the chat showing values of gpioPin3 is null,the issue is the same with  gpioPin2.

    Question3:  "where is the main code"means that,I doubt values from gpioPin2 and gpioPin3 are  added to the same data series ,so they interfere with each other.But I can not find the main code or the variable  that determines the wrong effect.
  • edited January 2018
    Right, so assuming individual gpio pins work, you still need to determine if both can work together.  Please follow these debug steps
    1. Create a blank app that has two buttons
      • One button starts the test i.e. sets up the routes and timer
      • One button stops the test i.e. removes the routes and timer
    2. Modify the subscribers to only print the ADC values to Logcat
    3. Press the start button and check that the appropriate values are received by pins 2 and 3
    4. Stop the test and repeat several times to confirm that everything is working

    If this part isn't working, then forget about trying to add your data to a graph.

    By the way, API v2 is deprecated (2.5.0 is nearly 2 years old).  I would also take this time to update your code to API v3.
  • edited January 2018
    Hello,thank you for your advice,if I change my code like this :
    @Override
    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)*/;

    gpioModule_2.routeData().fromDigitalIn(gpioPin3).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);
    gpioModule_2.readDigitalIn(gpioPin3);
    }
    }, 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.

  • edited January 2018
    I again change my code like this :
    @Override
    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)*/

    gpioModule_2.routeData().fromAnalogIn(gpioPin3, Gpio.AnalogReadMode.ABS_REFERENCE).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);
    gpioModule_2.readAnalogIn(gpioPin3, Gpio.AnalogReadMode.ABS_REFERENCE);

    }
    }, GPIO_SAMPLE_PERIOD, false).onComplete(new AsyncOperation.CompletionHandler<Timer.Controller>() {
    @Override
    public void success(Timer.Controller result) {
    result.start();
    }
    });
    }
    ----------------------------
    Then gpioValue2 and gpioValue3 will also not interfere with each other.And the gpioValue3 is analog. It is so amazing!! By the way ,you are so patient to answer my questions,thank you so much~~
  • Yes, that is interesting and good information to know.  However, you still need to isolate your gpio code as previously discussed and we can work from there.


    Again, API v2 is no longer supported.  Please take this time to update your code to use API v3.
Sign In or Register to comment.