1

I have a very simple setup android-things setup where a GPIO (output) generates very short (10u) pulse, and I'm trying to read that pulse through another GPIO (input).

However, my logs are weirding me out: how could I get two "false" readings in a row? If I have a light switch, I can't turn it off twice in a row... I need to turn it on in between, right? Can the GpioCallback drop events? Is my time too short? Can there be a soft ramp between voltages that doesn't ever count as an "edge"?

val gpioIn = PeripheralManagerService().openGpio(gpioPinName)
gpioIn.setEdgeTriggerType(Gpio.EDGE_NONE) // reset for Android Things bug
gpioIn.setDirection(Gpio.DIRECTION_IN)
gpioIn.setActiveType(Gpio.ACTIVE_HIGH)
gpioIn.setEdgeTriggerType(Gpio.EDGE_BOTH) // I should get all changes, right?
gpioIn.registerGpioCallback(object : GpioCallback() {
    override fun onGpioEdge(gpio: Gpio?): Boolean {
        netLog((gpio?.value  ?: "null").toString())
        return true
    }
    override fun onGpioError(gpio: Gpio?, error: Int) {
        netLog("GPIO $gpio Error event $error")
    }
})

results in

06-02 06:33:37.052 I/NetGpioListener: NET GPIO LISTENER: 118730013 true
06-02 06:33:37.091 I/NetGpioListener: NET GPIO LISTENER: 118769152 false
06-02 06:33:37.094 I/NetGpioListener: NET GPIO LISTENER: 118772102 false
Benjamin H
  • 5,164
  • 6
  • 34
  • 42
  • I'd like to reproduce your issue. What gpio output are you using? – Blundell Jun 05 '17 at 10:48
  • I was listening on pin 20 and I literally took a wire from the VCC and gently placed it in the input pin port and "wiggled" it a lot. Very scientific, I know. :) – Benjamin H Jun 05 '17 at 20:59

1 Answers1

2

Yes, this is fairly common with noisy input signals like pushbuttons, relay contacts, and "wiggly wires". The signal bounce that occurs during contact closure can happen very rapidly such that not every edge trigger event is captured by the input registers.

This is true of all GPIO systems (not just Android Things), and one reason why signal debounce is such a common practice. The debounce code in the button driver was actually written to handle cases like this to ensure they didn't generate false events.

devunwired
  • 62,780
  • 12
  • 127
  • 139