Input monitoring

I am trying to detect an input change at a GPIO pin.
I have the following python script, based on the cpp script here:
https://github.com/mbientlab/MetaWear-SDK-Cpp/blob/5bbf7be238dd16a8a04a9fb9f9c3010e8268c23d/cppdocs/source/gpio.rst

I can get the ADC measurements from the same pin successfully but can’t get input monitoring to work.
I hope I am missing something simple… any help would be appreciated.


from mbientlab.metawear import MetaWear, libmetawear, parse_value
from mbientlab.metawear.cbindings import *
from time import sleep
from threading import Event
import thread
import time
import sys

def state_handler(data):
print("Edge detected...")
print("%s" % (parse_value(data)))

state_handler_fn = FnVoid_DataP(state_handler)

device = MetaWear(sys.argv[1], device = 'hci1')
device.connect()
print("Connected (1)")
sleep(1.0)

int_signal0 = libmetawear.mbl_mw_gpio_get_pin_monitor_data_signal(device.board, 3)
libmetawear.mbl_mw_datasignal_subscribe(int_signal0, state_handler_fn)
libmetawear.mbl_mw_gpio_set_pin_change_type(device.board, 0, GpioPinChangeType.ANY)
libmetawear.mbl_mw_gpio_start_pin_monitoring(device.board, 0)

for x in range (0,10,1):
print("Looping...")
sleep(2.0)

sleep(1.0)
print("Disconnecting...")
device.disconnect()

Comments

  • Which gpio pin are you monitoring? Your code uses both '3' and '0'.

  • I have tried a number of different pins (end eventually made the error in the code above), but I double checked and re-tested pins 0, 2, 3... with all the functions using the same pin number as per the code below (for pin 0):

    int_signal0 = libmetawear.mbl_mw_gpio_get_pin_monitor_data_signal(device.board, 0)
    libmetawear.mbl_mw_datasignal_subscribe(int_signal0, state_handler_fn)
    libmetawear.mbl_mw_gpio_set_pin_change_type(device.board, 0, GpioPinChangeType.ANY)
    libmetawear.mbl_mw_gpio_start_pin_monitoring(device.board, 0)

  • edited June 2018

    Quoting myself from the other thread, which in turn quotes the first statement from Input Monitoring section of the linked gpio doc:

    The firmware can also monitor the digital state of the input signal and alert the user if the state changes

    Just because the ADC value changes does not mean the digital state has changed.

  • I'm pulling the pin down to 0V from 3V.

  • Yes but is the digital state changing?
    Also, please provide a circuit diagram showing how the sensor is powered and connected to your board .

This discussion has been closed.