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)