关于GPIO的输入怎么不稳定,悬空测试一会儿true  一会儿false

  • baiye009 wrote: 2024-03-06 4:13 各位大佬,能否帮忙看下这个GPIO 输入问题。
    from periphery import GPIO
    import time

    Write_Pin = 55
    Read_Pin = 54

    Write_GPIO = GPIO(Write_Pin, "out")
    Read_GPIO = GPIO(Read_Pin, "in")

    i = 1
    try:
    while True:
    try:
    #Write_GPIO.write(True)
    #pin_state = Read_GPIO.read()
    #print(f"Pin state: {pin_state}")

    #Write_GPIO.write(False)
    pin_state = Read_GPIO.read()
    print(f"i=%d Pin state: {pin_state}"%i)

    time.sleep(1)

    i = i+1

    except KeyboardInterrupt:
    Write_GPIO.write(False)
    break

    except IOError:
    print("Error")

    finally:
    Write_GPIO.close()
    Read_GPIO.close()
    您好,这是我在 luckfox-pico plus 进行测试的结果,使用您的代码没有复现您的问题。
    gpio_test.jpg
    在硬件上如果有焊接排针请检查是否是因为引脚短接;
    在软件上如果有配置设备树请检查是否是设备树设置问题;

    希望这能帮助您解决问题。
  • 感谢您的回复,我这边排查一下