Main Content

configureDigitalPin

Configure GPIO pin as input or output

Add-On Required: This feature requires the MATLAB Support Package for BeagleBone Black Hardware add-on.

Description

example

configureDigitalPin(bbb,pin,direction) configures a specific GPIO pin as a digital input or digital output.

example

current_direction = configureDigitalPin(bbb,pin) returns the current configuration of a specific GPIO pin.

Examples

collapse all

You can configure a GPIO pin as digital input and read its logical value.

Create a connection from the MATLAB® software to the BeagleBone® Black hardware.

bbb = beaglebone
bbb = 

  beaglebone with properties:

           DeviceAddress: '192.168.7.2'
               BoardName: 'BeagleBone Black Rev 00C0'
           AvailableLEDs: {'USR0'  'USR1'  'USR2'  'USR3'}
    AvailableDigitalPins: {1x29 cell}
     AvailableAnalogPins: {'AIN0'  'AIN1'  'AIN2'  'AIN3'  'AIN4'  'AIN5'  'AIN6'}
        AvailablePWMPins: {}
    AvailableSPIChannels: {}
       AvailableI2CBuses: {'i2c-1'}
    AvailableSerialPorts: {}
        AvailableWebcams: {} 

The AvailableDigitalPins property shows the list of available digital pins.

Redisplay AvailableDigitalPins.

bbb.AvailableDigitalPins
ans = 

  Columns 1 through 5

    'P8_7'    'P8_8'    'P8_9'    'P8_10'    'P8_11'

  Columns 6 through 10

    'P8_12'    'P8_13'    'P8_14'    'P8_15'    'P8_16'

  Columns 11 through 15

    'P8_17'    'P8_18'    'P8_19'    'P8_26'    'P9_11'

  Columns 16 through 20

    'P9_12'    'P9_13'    'P9_14'    'P9_15'    'P9_16'

  Columns 21 through 25

    'P9_21'    'P9_22'    'P9_23'    'P9_24'    'P9_26'

  Columns 26 through 29

    'P9_27'    'P9_30'    'P9_41'    'P9_42'

Show the physical location of GPIO 60.

showPins(bbb)

The corresponding pin identifier is 'P9_12'. Connect the digital device that you are using to 'P9_12'.

Check whether 'P9_12' is already configured.

configureDigitalPin(bbb,'P9_12')
ans =

unset

Configure 'P9_12' as a digital input.

configureDigitalPin(bbb,'P9_12','input')

Read the value from pin 'P9_12'.

readDigitalPin(bbb,'P9_12')
ans =

  1

You can configure a pin as a digital output and write its logical value.

Create a connection from the MATLAB software to the BeagleBone Black hardware.

bbb = beaglebone
bbb = 

  beaglebone with properties:

           DeviceAddress: '192.168.7.2'
               BoardName: 'BeagleBone Black Rev 00C0'
           AvailableLEDs: {'USR0'  'USR1'  'USR2'  'USR3'}
    AvailableDigitalPins: {1x29 cell}
     AvailableAnalogPins: {'AIN0'  'AIN1'  'AIN2'  'AIN3'  'AIN4'  'AIN5'  'AIN6'}
        AvailablePWMPins: {}
    AvailableSPIChannels: {}
       AvailableI2CBuses: {'i2c-1'}
    AvailableSerialPorts: {}
        AvailableWebcams: {} 

The AvailableDigitalPins property shows the list of available digital pins.

Redisplay AvailableDigitalPins.

bbb.AvailableDigitalPins   
ans = 

  Columns 1 through 5

    'P8_7'    'P8_8'    'P8_9'    'P8_10'    'P8_11'

  Columns 6 through 10

    'P8_12'    'P8_13'    'P8_14'    'P8_15'    'P8_16'

  Columns 11 through 15

    'P8_17'    'P8_18'    'P8_19'    'P8_26'    'P9_11'

  Columns 16 through 20

    'P9_12'    'P9_13'    'P9_14'    'P9_15'    'P9_16'

  Columns 21 through 25

    'P9_21'    'P9_22'    'P9_23'    'P9_24'    'P9_26'

  Columns 26 through 29

    'P9_27'    'P9_30'    'P9_41'    'P9_42'

Show the location of GPIO 48.

showPins(bbb)

The corresponding pin identifier is 'P9_15'. Connect the digital device that you are using to 'P9_15'.

Configure pin 'P9_15'as a digital output.

configureDigitalPin(bbb,'P9_15','output')   

Write a logical value of 1 to pin 'P9_15'.

writeDigitalPin(bbb,'P9_15',1)

Input Arguments

collapse all

BeagleBone Black connection created using beaglebone, specified as an object.

GPIO pin identifier, specified as a character vector. This argument does not accept vectors because the board cannot access multiple pins simultaneously.

To get a list of valid pin identifiers, enter bbb.AvailableDigitalPins.

Example: P8_12

Data Types: double

Pin direction, specified as a character vector. Configures the pin as an input or an output. Accepts partial inputs.

Example: 'input'

Data Types: char

Output Arguments

collapse all

Pin direction, specified as a character vector. Returns 'unset' if the pin has not been configured since the last hardware start.

Example: 'unset'

Data Types: char

Version History

Introduced in R2015a