GPIO Programming for Push button and ON/OFF (spdt) switch

Started by Narender, November 26, 2018, 08:36:43 AM

Previous topic - Next topic


Hi iam using following code to access gpios of A64 board.
Code works fine when i use ON/OFF switch, prints 1 consistently in OFF position and prints 0 consistently in ON postion.

Problem is when i use Push button for the same code, it works fine when button is pushed, but when button is in open position, it is printing 1 and 0 randomly. Does any else also faced such problem

#!/usr/bin/env python
"""Basic blinking led example.

import os
import sys

if not os.getegid() == 0:
    sys.exit('Script must be run as root')

from time import sleep
from pyA64.gpio import gpio
from pyA64.gpio import port

button = port.PE15

gpio.setcfg(button, gpio.INPUT)

state = gpio.input(button)
print state