Timer for GPIO

Hi,

With the code below I expect the timer to be scheduled every 2000ms but I keep getting much faster ADC streaming (about 10Hz)

Please suggest 
Thanks
Udi

timerModule.scheduleTask(new Timer.Task() {
@Override
public void commands() {
gpioModule.readAnalogIn((byte) GPIO_Num, Gpio.AnalogReadMode.ADC);
}
}, 2000, false).onComplete(new AsyncOperation.CompletionHandler<Timer.Controller>() {
@Override
public void success(Timer.Controller result) {
timerControler = result;
result.start();
}
});

Comments

  • I gave your code a try and I am getting ADC values every 2 seconds.  Are you running it from a clean state?
  • The 'clean state' bothers me - I might be doing something wrong. 
    My application requires to connect to the board on user's demand, do some GPIO ADC streaming and shut down everything (for battery saving). It seems that the shutting down is not done properly since the streaming rate in the consecutive connections is accelerated as if old streams are still active and firing thus shortening the initial sampling interval. 
    My stream shut down code is:
    gpioStreamRouteManager.unsubscribe(GPIO_STREAM_KEY);
    gpioStreamRouteManager.remove();
    timerControler.remove();
    timerModule.removeTimers();
    mwBoard.removeRoutes();
    mwBoard.disconnect();


    Please suggest
    Thanks
    Udi
  • There's no reason to tear everything down before you disconnect; all you need to do is stop the timer.  It's possible that you are cutting the BLE connection before all commands are received by the board.  You can utilize the disconnect from the Debug class to have the board terminate the connection instead.
  • Something like 
    Debug debugModule= (Debug) mwBoard.getModule(Debug.class);
    debugModule.disconnect();
    ?
    Is it different than 
    mwBoard.disconnect();
  • OK, the following code seems to execute the board disconnection (without this code restarting the program leaves the board binded and adverised MAC is not seen)
    try {
    Debug debugModule = (Debug) mwBoard.getModule(Debug.class);
    debugModule.disconnect();
    } catch (Exception e) {
    e.printStackTrace();
    }
    However, it throws NullPointerException with the following StackTrace:
    DetailMessage = Attempt to invoke interface method 'void com.mbientlab.metawear.module.Debug.disconnect()' on a null object reference
    Any suggestions?
    Thanks for your support
    Udi

  • edited April 2016
    Yes, I explained the difference in my post:  "You can utilize the disconnect from the Debug class to have the board terminate the connection instead".

    You cannot call getModule unless you have an active BLE connection.

This discussion has been closed.