Legacy MATLAB and Simulink Support for Arduino

版本 (169.6 KB) 作者: Giampiero Campa
MATLAB class and Simulink blocks for communicating with an Arduino microcontroller board

220.8K 次下载

更新时间 2016/4/19


编者注: Popular File 2012 2013 2014 2015 2016 2017 2018 2019 2020

NOTE: This solution (formerly known as "Arduino IO Package") is no longer supported. It is recommended that you use Arduino support packages that are developed and supported by MathWorks:

- MATLAB Support Package for Arduino Hardware: Read, write, and analyze data from Arduino sensors

- Simulink Support Package for Arduino Hardware: Develop algorithms that run standalone on your Arduino

Use this legacy support only if one of the following is true:
- You are using MATLAB R2013b or earlier (but not earlier than R2011a).
- You need Simulink blocks that enable you to interactively stream input and outputs from your Arduino
- You need functions or blocks that enable you to interactively read or reset encoders
- You are using unsupported Arduino clones which won't work with the official packages (e.g. ChipKit32)

Sample usage:

%-- connect to the board
a = arduino('COM9')

%-- specify pin mode

%-- digital i/o
a.digitalRead(4) % read pin 4
a.digitalWrite(13,0) % write 0 to pin 13

%-- analog i/o
a.analogRead(5) % read analog pin 5
a.analogWrite(9, 155) % write 155 to analog pin 9

%-- serial port
a.serial % get serial port
a.flush; % flushes PC's input buffer
a.roundTrip(42) % sends 42 to the arduino and back

%-- servos
a.servoAttach(9); % attach servo on pin #9
a.servoWrite(9,100); % rotates servo on pin #9 to 100 degrees
val=a.servoRead(9); % reads angle from servo on pin #9
a.servoDetach(9); % detach servo from pin #9

%-- encoders
a.encoderAttach(0,3,2) % attach encoder #0 on pins 3 (pin A) and 2 (pin B)
a.encoderRead(0) % read position
a.encoderReset(0) % reset encoder 0
a.encoderStatus; % get status of all three encoders
a.encoderDebounce(0,12) % sets debounce delay to 12 (~1.2ms)
a.encoderDetach(0); % detach encoder #0

%-- adafruit motor shield (with AFMotor library)
a.motorRun(4, 'forward') % run motor forward
a.stepperStep(1, 'forward', 'double', 100); % move stepper motor

%-- close session

Some slides and examples related to this package can be found here:

Finally, more detailed info about use and troubleshooting can be found in the readme.txt file contained in this submission.


Giampiero Campa (2022). Legacy MATLAB and Simulink Support for Arduino (https://www.mathworks.com/matlabcentral/fileexchange/32374-legacy-matlab-and-simulink-support-for-arduino), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2010a
Windows macOS Linux
 Power Electronics Control 社区中有更多文件

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!