执行演示代码

执行以下操作,以在昉·星光 2的Debian系统上运行演示代码:

  1. 找到测试代码pud_test.py所在的目录:
    1. 执行以下命令以获取VisionFive.gpio所在的目录:
      pip show VisionFive.gpio
      示例结果:
      Location: /usr/local/lib64/python3.9/site-packages
      注:

      实际输出取决于应用的安装方式。

    2. 如前一步输出中所示,执行以下操作进入目录/usr/local/lib64/python3.9/site-packages
      cd /usr/local/lib64/python3.9/site-packages
    3. 执行以下命令进入sample-code目录:
      cd ./VisionFive/sample-code/
  2. sample-code目录下,执行以下命令以运行演示代码:
    sudo python pud_test.py

    或者,您也可以执行以下命令:

    sudo python3 pud_test.py
    结果:

    终端显示如下:

    # python3 pud_test.py
    *----------------------Start testing------------------------------*
    
    Step 1: set input to direction of GPIO pin 31.
    
    Step 2: the default input level is HIGH.
    
    Step 3.1: set PUD_DOWN to input direction of GPIO pin 31.
    
    Step 3.2: the input level with pull_down enabled is LOW.
    
    Step 4.1: set PUD_UP to input direction of GPIO pin 31.
    
    Step 4.2: the input level with pull_up enabled is HIGH.
    
    *---------------------------end test------------------------------*

    结果显示GPIO PUD功能正常。