Edge Detection with Timeout Setting

This section describes how to use the demo program to verify edge detection works correctly on VisionFive 2 or VisionFive 2 Lite with and without timeout settings.

Hardware Setup

Connect pin ① and pin ② of the button to the breadboard first, and then connect pin ③ and pin ④ to VisionFive 2 or VisionFive 2 Lite. The following table and figure describe how to connect the button to the 40-pin GPIO Header:

Figure 1. Connect Button to 40-Pin Header
Button 40-Pin GPIO Header
Pin Number Pin Name
Pin ④ 37 GPIO60
Pin ③ 39 GND
Table 1. Connect MAX7219 to 40-Pin Header
MAX7219 40-Pin GPIO Header
Pin Number Pin Name
VCC 2 5V Power
GND 34 GND
DIN 40 GPIO44
CS 38 GPIO61
CLK 36 GPIO36

Run Demo Code

Perform the following steps on Debian of VisionFive 2 or VisionFive 2 Lite.

  1. Locate the directory where the test code, edge_detection_with_waiting_time.py, exists.

    1. Source into the Python3 Virtual Environment.

      source ./myvenv/bin/activate
    2. Install the dependency.
      python3 -m pip install pillow
    3. Get the directory where VisionFive.gpio exists.

      python3 -m pip show VisionFive.gpio
      Note: The output depends on how the application is installed.
    4. Enter the VisionFive.gpio directory.

      cd <VisionFive.gpio directory>
    5. Enter the sample-code directory.

      cd ./VisionFive/sample-code/
  2. Under the sample-code directory, execute the following command to run the demo code.

    sudo python  edge_detection_with_waiting_time.py
    Alternatively, you can also run the following command.
    sudo python3  edge_detection_with_waiting_time.py
    The terminal displays the following:
    # python3 edge_detection_with_waiting_time.py 
    *-----------------------Case 1-----------------------------------------------------*
    Note: don't press the key on pin 37 once within 5 seconds !!!
    Case 1: 5-second timeout. The code waits 5 seconds for you to press the button. If you do not press the button, no edge detection.
    Edge hasn't been detected within 5 seconds  while setting 5 seconds to timeout.
    The return value of GPIO.event_detected(37) within 5 seconds: False
    
    *-----------------------Case 2-----------------------------------------------------------------------*
    Please press the key on pin 37 once at any time !!!
    Case 2: Infinite wait. The code waits forever until you press the button. If you press the button at any time, edge is detected successfully.
    Edge has detected while setting -1 to timeout,
    timeout -1 means waiting until edge is detected.
    
    The return value (True) of GPIO.event_detected(37) should be True.
    The return value (False) of GPIO.event_detected(37) should be False, because of the secondly reading.
    Note: For details about the source code, see edge_detection_with_waiting_time.py Source Code.
  3. (Optional) Exit the Python3 Virtual Environment.

    deactivate