Main Content

writeDigitalPin

Write logical value to GPIO output pin

    Description

    example

    writeDigitalPin(hwobj,pinNumber,value) sets the logical value of a GPIO pin to 0 or 1.

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

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

    Examples

    collapse all

    Configure a GPIO pin as a digital output and write its logical value.

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

    hwobj = jetson
    
    hwobj = 
    
      jetson with properties:
    
               DeviceAddress: 'jetson-board-name'
                        Port: 22
                   BoardName: 'NVIDIA Jetson TX2'
                 CUDAVersion: '10.0'
                cuDNNVersion: '7.6'
             TensorRTVersion: '6.0'
                  SDLVersion: '1.2'
                 V4L2Version: '1.14.2-1'
            GStreamerVersion: '1.14.5'
               OpenCVVersion: '4.1.1'
                     GPUInfo: [1x1 struct]
                  WebcamList: []
        AvailableDigitalPins: [7 11 12 13 15 16 18 19 21 22 23 24 29 31 32 33 35 36 37 38 40]
    

    The AvailableDigitalPins property shows the list of available digital GPIO pins.

    Show the location of all the GPIO pins on your device.

    showPins(hwobj)

    J21 header pinout of Jetson TX2 development board

    Display the AvailableDigitalPins.

    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, for example GPIO 11.

    Configure pin GPIO 11 as a digital output.

    configurePin(hwobj,11,'DigitalOutput')   

    Write a logical value of 1 to pin GPIO 11.

    writeDigitalPin(hwobj,11,1)

    The logical value of 1 sets the signal voltage on pin GPIO 11 to high.

    Input Arguments

    collapse all

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

    GPIO pin number, specified as a scalar. This argument does not accept vectors because the hardware cannot access multiple pins simultaneously.

    To get a list of valid pin numbers, use the AvailableDigitalPins property of the jetson object. For example, hwobj.AvailableDigitalPins.

    Example: 12

    Data Types: double

    Logical value of the pin, specified as a scalar.

    Example: 1

    Data Types: double | logical

    See Also

    Functions

    Objects

    Introduced in R2021b