Arduino is low cost hardware, Ubuntu is free and open source operating system, and Matlab is one of the best engineering software. Integration of those three platform can create a simple yet powerful system.
|
Screenshot of Matlab Gui for simple swictch |
Step-by-step:
- Install Arduino IDE: sudo apt-get install arduino
- Download and Install ArduinoIO (for Matlab 2013 and earlier)
- http://www.mathworks.com/matlabcentral/fileexchange/32374-matlab-support-for-arduino--aka-arduinoio-package-
- Open and Upload adio.pde (in ArduinoIO/pde) using Arduino IDE
- Make a link from ACM0 to S101
- sudo ln -s /dev/ttyACM0 /dev/ttyS101
- sudo chmod 777 /dev/ttyS101
- Add the ArduinoIO to matlab path or simply run install_arduino within ArduinoIO directory
- Create the test program, I named it ledonoff
- In Matlab command window, type 'guide' to create gui, save as led_onoff.fig
- Add two push botton, one "ON" and another "OFF" button (double click to change the string name)
- Right click any button (on or off) and choose editor, it will open m-file of the gui. Add the the following code around line 60, after led_onoffOpeningFcn,
clear a;
global a;
a=arduino('/dev/ttyS101');
a.pinMode(13,'output');
- Under pushbutton1 function, add the following code to turn on led when clicked
global a;
a.digitalWrite(13,1);
- Under pushbutton2 function, add the following code to turn off led when clicked
global a;
a.digitalWrite(13,0);
The first script is to access serial port via USB by using "
arduino" function. When you don't connect the arduino board to usb, change the port (
/dev/ttyS101 or COM12 in windows) to
'demo' (with single quote). We use pin 13 on board as output, and make it ON by using
digitalWrite(13,1) and make it off by using
digitalWrite(13,0).
|
Upload adio.pde so Matlab can access input-output of Arduino board |