configurePin
Set Arduino pin mode
Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.
Description
Examples
Display Current Pin Mode
a = arduino('COM4','Uno'); configurePin(a,'A2')
ans = 'Unset'
Configure Analog Pin to I2C Mode
a = arduino('COM4','Uno'); configurePin(a,'A4','I2C');
Display current pin mode.
pinMode = configurePin(a,'A4')
pinMode = 'I2C'
Configure Digital Pin to Pullup Mode
a = arduino('COM4','Uno'); configurePin(a,'D3','pullup');
Display current pin mode.
pinmode = configurePin(a,'D3')
pinmode = 'Pullup'
Clear Pin Mode
Display current pin mode and reset it to 'Unset'.
a = arduino('COM4','Uno'); configurePin(a,'D3','pullup'); pinMode = configurePin(a,'D3')
pinMode = 'Pullup'
Change mode to 'Unset' and display the current mode.
configurePin(a,'D3','Unset'); pinMode = configurePin(a,'D3')
pinMode = 'Unset'
Input Arguments
a
— Arduino hardware connection
object
Arduino hardware connection created using arduino
,
specified as an object.
Example: a = arduino;
pin
— Pin number
character vector
Pin number on the physical hardware, specified as a character vector.
Example: D3
or A1
.
Note
If you connect to ESP32 board and the pin's mode
is set to AnalogInput
, the pin number must always
correspond to a digital pin. For details, see Pin-mapping for ESP32 Boards.
mode
— Pin mode
'unset'
(default) | character vector
Pin mode specified as a character vector. Valid pin modes are:
AnalogInput
: acquire analog signals from pinDigitalInput
: acquire digital signals from pinDigitalOutput
: generate digital signals from pinI2C
: specify a pin to use with I2C protocolInterrupt
: specify pin in interrupt mode to be used in rotaryEncoderPullup
: specify pin to use a pullup switchPWM
: specify pin to use a pulse width modulatorCAN
: specify pin to use a Controller Area Network busServo
: specify pin to use a servoSPI
: specify a pin to use with SPI protocolTone
: specify pin to use for playToneUltrasonic
: specify pin to use with ultrasonic sensorCAN
: specify pin to use with CAN shieldUnset
: clears pin designation. The pin is no longer reserved and can be automatically set at the next operation.
Pins are configured on first usage. You can reset the pin mode to change
the mode. If you want to use a pullup, you must set the mode to
'pullup'
.
Output Arguments
pinMode
— Current mode of Arduino pin
character vector
Current mode of pin, returned as a character vector.
More About
Pin-mapping for ESP32 Boards
If you connect to an ESP32 board, use the following table to map the analog pin
number to the corresponding digital pin number, which must be entered as the
pin
's value.
Analog pin on ESP32-DevKitV1 and ESP32-DevKitC | Digital pin number to be useda |
---|---|
A0 | D36 |
A3 | D39 |
A4 | D32 |
A5 | D33 |
A6 | D34 |
A7 | D35 |
A10 | D4 |
A12 | D2 |
A13 | D15 |
A14 | D13 |
A15 | D12 |
A16 | D14 |
A17 | D27 |
A18 | D25 |
A19 | D26 |
a If you connect to ESP32 board over WiFi from the MATLAB PC, transferring data through the following pins may not work properly: D2, D12, D13, D14, D15, D25, D26, and D27. For communication over WiFi, it is recommended that you use the other pins listed in this table. |
Code Generation Using MATLAB Function Block
Use
configurePin
in a MATLAB® Function block with the Simulink® Support Package for Arduino Hardware to generate code that can be deployed on Arduino Hardware.Configure the Arduino peripherals using
configurePin
before using it in the MATLAB Function block.The function does not return any output during code generation.
The following modes are currently supported for code generation :
AnalogInput
,DigitalInput
,DigitalOutput
,Pullup
,PWM
, andUnset
.
Version History
Introduced in R2015b
See Also
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 (한국어)