Help reading data from GPIO pins?

Hi,

I'm trying to read data from a moisture sensor attached to the GPIO pins on MetaWearC, but I am not recieving any data.  I can stream info from the development app, so the device is hooked up correctly, but I don't see much (anything) in the documentation on how to read from GPIO pins in my own app.

I've modified the FreeFall app like so:

            var gpio = metawear.GetModule<IGpio>();
            gpio.Pins[0].ClearOutput();  // Set GPIO0 to Ground
            gpio.Pins[2].SetPullMode(MbientLab.MetaWear.Peripheral.Gpio.PullMode.Down); // Read ADC on GPIO2

            await gpio.Pins[2].Adc.AddRouteAsync(source =>
                source.Stream(data => System.Diagnostics.Debug.WriteLine(String.Format("{0}: ", data))) // never breaks
            );

I've looked at the source for the Android app, but my java isn't so good.  From what I can tell it uses a timer to trigger the reads, but this is not usable for me because the reads need to happen on-device (I can't be requesting 5 reads every second, that'll kill battery).

Any examples on how I can setup the metawearC to poll it's GPIO pins?  (From there I run the signal through filters and then send to device!).

Thanks!

Comments

  • Note: This is how the "Start" button is implemented:

                var gpio = metawear.GetModule<IGpio>();
                gpio.Pins[2].Monitor.Start();
  • The API reference was mistakenly placed where the howto documentation was supposed to be.  This has been corrected and can refer to the Timer module to implement what you need:
  • Thanks for the pointer (note - the links in the documentation still 404)

    Unfortunately, this doesn't seem to get me closer to my goal.

    If I call 
        gpio.Pins[2].Adc.Read();

    A read result is streamed to my device, all fine & dandy.
    Adding the call 
        _timerTask = await metawear.ScheduleAsync(500, false, () => gpio.Pins[2].Adc.Read());

    seems to achieve nothing.

    What are the steps I need to take to run a steady poll on my sensor?

    Also note: the documentation implies that ScheduleAsync would be necessary with IForcedDataProducer, but I assume the same is true for IAnalogDataProducer.  If both these classes have the same signature/requirements, it might pay to merge them?  Be a bit clearer perhaps.

  • Read the 2nd section in the aforementioned link.

    For streaming purposes, make sure you schedule the task after creating the route.
  • Oh nuts... now I see it...

    Thanks for the RTFM :-)
  • Hi..i am a new user here. As per my knowledge the MetaWear firmware comes with a timer that can be used to schedule tasks on the board. Unlike using a <span class="pre">Timer</span> or <span class="pre">Handler</span> from the
    Android side, the MetaWear timer is only used with MetaWear commands and solely exists on the board.

    Use Schedule Async to schedule tasks to be run in the future. Typically this is used with the forced data producer’s Read function to have the board periodically request data
    from that producer.

This discussion has been closed.