Documentation Center

  • Trial Software
  • Product Updates

configureDigitalPin

Configure GPIO pin as input or output

Syntax

  • configureDigitalPin(mypi,pinNumber,direction)

Description

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

Examples

expand all

Configure Pin as Digital Input and Read Its Logical Value

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

Create a connection to the Raspberry Pi™ board.

mypi = raspi
mypi = 

  Raspi with Properties:

           DeviceAddress: 'raspberrypi-computername'
                    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 digital pins that are available.

Redisplay 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

Show the location of the GPIO 4.

showPins(mypi)

Connect the digital device you are using to GPIO 4.

Configure pin 4 as a digital input.

configureDigitalPin(mypi,4,'input')

Read the value from pin 4.

readDigitalPin(mypi,4)
ans =

  1

Configure Pin as Digital Output and Write Its Logical Value

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

Create a connection to the Raspberry Pi board.

mypi = raspi
mypi = 

  Raspi with Properties:

           DeviceAddress: 'raspberrypi-computername'
                    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 digital pins that are available.

Redisplay 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

Show the location of the GPIO 4.

showPins(mypi)

Connect the digital device you are using to GPIO 4.

Configure pin 4 as a digital output.

configureDigitalPin(mypi,4,'output')   

Write a logical value of 1 to pin 4.

writeDigitalPin(mypi,4,1)

Input Arguments

expand all

mypi — Connection to specific boardhandle

Connection to a specific board, specified as a handle.

Use raspi to create this connection.

Example: mypi

pinNumber — GPIO pin numberpin number

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

direction — Pin directioninput | output

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

Example: 'input'

Data Types: char

See Also

| | | |

Was this topic helpful?