Simultaneous GPIO monitoring

Hello,

I want to monitor two sensor values using two GPIO pins of MetaWearC in MetaWear app,
Is it possible to show two sensor values in a graph simultaneously?

According to the discussion below,
https://mbientlab.com/community/discussion/comment/5849#Comment_5849
I checked the barometer code in Github to show pressure and altitude simultaneously.
I tried to edit the GPIO Fragment code to nest two timer.scheduleAsync, but it has not worked.

Comments

  • This is the code I make nesting.

    @Override
    protected void setup() {
            gpio.pin(gpioPin).analogAbsRef().addRouteAsync(source -> source.stream((data, env) -> {
                    final Float voltage = data.value(Float.class);
    
                    LineData chartData = chart.getData();
                    if (startTime == -1) {
                        chartData.addXValue("0");
                        cl = Calendar.getInstance();
                        startTime = System.currentTimeMillis();
                    } else {
                        if (chartXValues.size() <= sampleCount) {
                            chartData.addXValue(String.format(Locale.US, "%.2f", sampleCount * samplingPeriod));
                        }
                    }
    
                    if (chart.getValueCount() < sampleCount) {
                        chartData.addEntry(new Entry(voltage, sampleCount), 0);
                    }
    
            }));
    
        filenameExtraString = String.format(Locale.US, "%s_pin_%d", csvHeaderDataName, gpioPin);
        timer.scheduleAsync(GPIO_SAMPLE_PERIOD, false, () -> {
                    gpio.pin(gpioPin).analogAbsRef().read();
    
        }).onSuccessTask(task -> {
                    scheduledTask = task.getResult();
    
                    return gpio.pin(gpioPin2).analogAbsRef().addRouteAsync(source -> source.stream((data, env) -> {
                        final Float voltage2 = data.value(Float.class);
    
                        LineData chartData = chart.getData();
    
                        if (chart.getValueCount() < sampleCount) {
                            chartData.addEntry(new Entry(voltage2, sampleCount), 1);
                        }
                        sampleCount++; 
    
                    }));
                });
    
            timer.scheduleAsync(GPIO_SAMPLE_PERIOD, false, () -> {
                        gpio.pin(gpioPin2).analogAbsRef().read();
    
            }).onSuccess(task -> {
                scheduledTask2 = task.getResult();
    
                scheduledTask2.start();
                scheduledTask.start();
    
                return null;
    
            });
    }
    
  • What do you mean by "is has not worked"? Provide more details.

  • Hi Eric,
    Thank you for your attention.

    @Eric said:
    What do you mean by "is has not worked"? Provide more details.

    Though I tap "start sampling" toggle button first, sampling and graphing do not start.
    The curious thing is that, after tap the toggle button (stop) and clear the graph, sampling and graphing start by tapping the toggle button.
    Both data are collected and plotted in the graph, but the sampling rate is doubled.

  • edited March 2019

    FYI, I uploaded the video. https://streamable.com/t6hv6

Sign In or Register to comment.