Contenido principal

readDigitalPin

R2026b

Read logical value from GPIO input pin

    Description

    Add-On Required: This feature requires the MATLAB Coder Support Package for NVIDIA Jetson and NVIDIA DRIVE Platforms add-on.

    pinvalue = readDigitalPin(hwobj,pinNumber) returns the logical value of a digital pin.

    If the pin is not configured, this function configures the pin as a GPIO input.

    If the pin is a GPIO output, or if another interface (I2C, Serial, SPI) uses the pin, this method returns an error message.

    example

    Examples

    collapse all

    Create a connection from MATLAB® to the NVIDIA® Jetson™ board.

    hwobj = jetson;
    

    To display the available digital GPIO pins on the board, access the AvailableDigitalPins property of the jetson object. The output depends on your specific hardware board.

    hwobj.AvailableDigitalPins
    
    ans =
    
    7    11    12    13    15    16    18    19    
    21    22    23    24    29    31    32    33    
    35    36    37    38    40
    

    Connect your digital device to an available GPIO pin. In this example, the AvailableDigitalPins property shows pin 7 is available. Configure pin 7 as a digital input.

    configurePin(hwobj,7,"DigitalInput")
    

    Read the value from pin 7. In this example, the readDigitalPin function returns 1, which indicates a positive voltage signal on the pin.

    value = readDigitalPin(hwobj,7)
    
    value =
    
      1

    Input Arguments

    collapse all

    Connection to a specific NVIDIA hardware board, specified as a jetson object.

    GPIO pin number, specified as an integer.

    To get a list of valid pin numbers, use the AvailableDigitalPins property of the jetson object. To view a diagram of the pins for your Jetson board, use the showPins function.

    Output Arguments

    collapse all

    Logical value of the pin, returned as a scalar.

    Version History

    Introduced in R2021b

    See Also

    Functions

    Objects