Help reading data from GPIO pins?
in C#
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!
This discussion has been closed.
Comments
<span class="pre">Timer</span>
or<span class="pre">Handler</span>
from theAndroid 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.