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
Examples
Configure Pin as Input and Read Its Value
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
Configure Pin as Output and Write Its Value
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
bbb
— Connection to BeagleBone Black hardware
beaglebone
object
BeagleBone Black connection created using beaglebone
, specified as an
object.
pin
— GPIO pin identifier
pin identifier
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
direction
— Pin direction
'input'
| 'output'
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
current_direction
— Pin direction
'input'
| 'output'
| 'unset'
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
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)