Sunday, February 15, 2015

Ubuntu, Arduino and Matlab

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:
  1. Install Arduino IDE: sudo apt-get install arduino
  2. Download and Install ArduinoIO (for Matlab 2013 and earlier)
    • http://www.mathworks.com/matlabcentral/fileexchange/32374-matlab-support-for-arduino--aka-arduinoio-package-
  3. Open and Upload adio.pde (in ArduinoIO/pde) using Arduino IDE
  4. Make a link from ACM0 to S101
    • sudo ln -s /dev/ttyACM0 /dev/ttyS101
    • sudo chmod 777 /dev/ttyS101
  5. Add the ArduinoIO to matlab path or simply run install_arduino within ArduinoIO directory
  6. Create the test program, I named it ledonoff
    1. In Matlab command window, type 'guide' to create gui, save as led_onoff.fig
    2. Add two push botton, one "ON" and another "OFF" button (double click to change the string name)
    3. 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,
    4. clear a;
      global a;
      a=arduino('/dev/ttyS101');
      a.pinMode(13,'output');
      
    5. Under pushbutton1 function, add the following code to turn on led when clicked
    6. global a;
      a.digitalWrite(13,1);
      
    7. Under pushbutton2 function, add the following code to turn off led when clicked
    8. 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
Related Posts Plugin for WordPress, Blogger...