matlab获取arduino支持包,Arduino的MATLAB支持包(ArduinoIO包装)

MATLAB Support Package for Arduino (aka ArduinoIO Package)

Arduino (www.arduino.cc) is a low-cost open-source electronics prototyping platform.

MATLAB Support Package for Arduino (also referred to as "ArduinoIO Package") allows you to communicate with an Arduino Uno or Duemilanove over a serial port. It consists of a MATLAB API on the host computer and a server program that runs on the Arduino. Together, they allow you to access Arduino analog I/O, digital I/O, operate servo motors, read encoders, and even handle dc and stepper motors using the adafruit motor shield, all from the MATLAB command line.

The Support Package also includes Simulink blocks for communicating with the Arduino.

For more information about the Support Package, see:

http://www.mathworks.com/academia/arduino-software/arduino-matlab.html

For Simulink blocks that support code generation, see:

http://www.mathworks.com/academia/arduino-software/arduino-simulink.html

Sample usage:

%-- connect to the board

a = arduino('COM9')

%-- specify pin mode

a.pinMode(4,'input');

a.pinMode(13,'output');

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

delete(a)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值