configurePin - Configure GPIO pin as digital input, digital output, or PWM output - MATLAB (original) (raw)

Configure GPIO pin as digital input, digital output, or PWM output

Syntax

Description

configurePin([mypi](#bvdit9u%5Fsep%5Fshared-mypi),[pinNumber](#bvdit9u%5Fsep%5Fshared-pinNumber),[mode](#mw%5F117fb343-619b-4dd4-bece-f8d05b9f5a2a)) configures the GPIO pinNumber pin of a Raspberry Pi® device mypi as a digital input, digital output, or PWM output, depending on the specified mode.

example

[pinMode](#bvdit9u-mode-dup1) = configurePin([mypi](#bvdit9u%5Fsep%5Fshared-mypi),[pinNumber](#bvdit9u%5Fsep%5Fshared-pinNumber)) returns the current configuration mode of the pin.

Examples

collapse all

Configure a GPIO pin as digital input and read its logical value.

Create a connection from MATLAB® to the Raspberry Pi board.

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.

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.

The logical value of 1 indicates a positive voltage signal on the pin GPIO 4.

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 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.

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.

Input Arguments

collapse all

Connection to the Raspberry Pi hardware board, specified as a raspi object.

Mode used to configure the pin, specified as 'DigitalInput','DigitalOutput', 'PWM','Servo', 'ArduCam', or'Unset'.

Data Types: char

Output Arguments

collapse all

Current configuration mode of pin, returned as 'DigitalInput','DigitalOutput', 'PWM','Servo', 'ArduCam', or'Unset'.

Extended Capabilities

expand all

Version History

Introduced in R2015b