configurePin
Configure GPIO pin as digital input, digital output, or PWM output
Description
Input Arguments
mypi
— Connection to Raspberry Pi hardware board
raspi
object
Connection to the Raspberry Pi hardware board, specified as a raspi
object.
pinNumber
— GPIO pin number
scalar
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, enter
.mypi
.AvailableDigitalPins
Example: 12
Data Types: double
mode
— Mode used to configure the pin
'DigitalInput'
| 'DigitalOutput'
| 'PWM'
| 'Unset'
Mode used to configure the pin, specified as
'DigitalInput'
, 'DigitalOutput'
,
'PWM'
, or 'Unset'
.
Data Types: char
Output Arguments
pinMode
— Current configuration mode of pin
'DigitalInput'
| 'DigitalOutput'
| 'PWM'
| 'Unset'
Current configuration mode of pin, returned as
'DigitalInput'
, 'DigitalOutput'
,
'PWM'
, or 'Unset'
.
Examples
Configure Pin as Input and Read Its Value
Configure a GPIO
pin as
digital input and read its logical value.
Create a connection from MATLAB® to the Raspberry Pi board.
mypi = raspi
mypi = Raspi with Properties: DeviceAddress: 'raspberrypi-hysdu8X38o' Port: 18725 BoardName: 'Raspberry Pi Model B Rev 2' AvailableLEDs: {'led0'} AvailableDigitalPins: [4 7 8 9 10 11 14 15 17 18 22 23 24 25 27 30 31] AvailableSPIChannels: {} AvailableI2CBuses: {'i2c-0' 'i2c-1'} I2CBusSpeed: 100000
The AvailableDigitalPins
property shows the
list of available digital GPIO
pins.
Show the location of all the GPIO
pins
on your device.
showPins(mypi)
Display the AvailableDigitalPins
.
mypi.AvailableDigitalPins
ans = Columns 1 through 13 4 7 8 9 10 11 14 15 17 18 22 23 24 Columns 14 through 17 25 27 30 31
Connect your digital device to the first GPIO
pin
available, for example GPIO 4
.
Configure pin GPIO 4
as a digital input.
configurePin(mypi,4,'DigitalInput')
Read the value from pin GPIO 4
.
readDigitalPin(mypi,4)
ans = 1
The logical value of 1
indicates a positive
voltage signal on the pin GPIO 4
.
Configure Pin as Output and Write Its Value
Configure a GPIO
pin as
a digital output and write its logical value.
Create a connection from the MATLAB software to the Raspberry Pi board.
mypi = raspi
mypi = Raspi with Properties: DeviceAddress: 'raspberrypi-hysdu8X38o' Port: 18725 BoardName: 'Raspberry Pi Model B Rev 2' AvailableLEDs: {'led0'} AvailableDigitalPins: [4 7 8 9 10 11 14 15 17 18 22 23 24 25 27 30 31] AvailableSPIChannels: {} AvailableI2CBuses: {'i2c-0' 'i2c-1'} I2CBusSpeed: 100000
The AvailableDigitalPins
property shows the
list of available digital GPIO
pins.
Show the location of all the GPIO
pins
on your device.
showPins(mypi)
Display the AvailableDigitalPins
.
mypi.AvailableDigitalPins
ans = Columns 1 through 13 4 7 8 9 10 11 14 15 17 18 22 23 24 Columns 14 through 17 25 27 30 31
Connect your digital device to the first GPIO
pin
available, for example GPIO 4
.
Configure pin GPIO 4
as a digital output.
configurePin(mypi,4,'DigitalOutput')
Write a logical value of 1
to pin GPIO
4
.
writeDigitalPin(mypi,4,1)
The logical value of 1
sets the signal voltage
on pin GPIO 4
to high.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
You can also deploy
configurePin
on the Raspberry Pi hardware in MATLAB Online™.
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
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)