Saturday, 25 January 2014

ARDUINO AND MATLAB SERIAL COMMUNICATION

1/25/2014 08:42:00 am


                                                       I think gesture recognition would be more exciting if you could control things in real world with your gestures... So here's how to do it using Arduino. Since it just uses serial communication, this can also be done with some usb to serial adapters.... 



                                                       This simulation actually shows how to control of an led (to get started with) with some clicking over the screen with fingers in the air..... 

Click here to download matlab source...

Here's a Demo video....



And here's the arduino code...

//Initializing variables...
int incomingByte = 0;
int led = 12;
int blnk = 0;
int del = 500;
void setup() {                
  pinMode(led, OUTPUT);     
  Serial.begin(9600);
}

void loop() {
//Main loop...  
  if (Serial.available() > 0) {
 incomingByte = Serial.read();    
    switch (incomingByte) {
    //ASCII value for 'A'
      case 65:
 digitalWrite(led,HIGH);
 blnk = 0;
      break;
    case 66:
 digitalWrite(led,LOW) ;
 blnk = 0;
      break;
      case 67:
 blnk = 1;
      break;   
  }
        }
        if (blnk==1){
         digitalWrite(led,HIGH);
         delay(del);
         digitalWrite(led,LOW);
         delay(del);
        }
}

You can also check the following link where you can find library over this....

Written by

21 comments:

  1. hi man, thanks for the tutorial.
    the matlab source code lacks of some other function...
    Undefined function 'getCameraInfo' for input arguments of type 'struct.

    Would you please upload them too

    ReplyDelete
  2. Hey Taro!! Sorry for that...Use this code as getCameraInfo.m function file

    function [camera_name, camera_id, resolution] = getCameraInfo(a)
    camera_name = char(a.InstalledAdaptors(end));
    camera_info = imaqhwinfo(camera_name);
    camera_id = camera_info.DeviceInfo.DeviceID(end);
    resolution = char(camera_info.DeviceInfo.SupportedFormats(end));

    ReplyDelete
  3. your project was really superb.....

    ReplyDelete
  4. hi, i'm getting these errors.......:

    Error in getCameraInfo (line 2)
    camera_name = char(a.InstalledAdaptors(end));

    Error in MatlabArduino (line 17)
    [camera_name, camera_id, format] = getCameraInfo(a);

    ReplyDelete
    Replies
    1. camera_name = char(a.InstalledAdaptors(end));

      a.InstalledAdaptors returns the installed camera adapters on your pc.
      Check what is returned when you give that command.

      Delete
  5. Thanks for the reply, i'm using matlab 2015a version.Startech 1.3mp webcam how to check my device adopters.... sir, pls help me out.

    ReplyDelete
  6. C:\Program Files\MATLAB\MATLAB Production Server\R2015a\toolbox\imaq\imaqadaptors\kit\test

    is this the folder contains data regarding my adopters

    ReplyDelete
  7. when i run the .M file in the follwoing location it shows C:\MATLAB\SupportPackages\R2015a\usbwebcams\toolbox\matlab\webcam\supportpackages

    webcam with properties:

    Name: 'STARTEC 1.3MP Webcam'
    Resolution: '640x480'
    AvailableResolutions: {1x16 cell}
    BacklightCompensation: 1
    Contrast: 57
    Sharpness: 10
    Gamma: 3
    Brightness: 30
    Saturation: 2

    ReplyDelete
  8. Try running these two commands in matlab command window..

    a = imaqhwinfo;
    a.InstalledAdaptors

    you should get something like this..

    a.InstalledAdaptors

    ans =

    'xxxx' 'xxx'

    ReplyDelete
  9. >> a = imaqhwinfo;
    a.InstalledAdaptors

    ans =

    'dcam'



    is that ok, should i need anything more to install

    ReplyDelete
  10. I think dcam alone is enough...
    Since, u have only one adaptor installed, used this as getCAmeraInfo function file..

    function [camera_name, camera_id, resolution] = getCameraInfo(a)
    camera_name = char(a.InstalledAdaptors(1));
    camera_info = imaqhwinfo(camera_name);
    camera_id = camera_info.DeviceInfo.DeviceID(1);
    resolution = char(camera_info.DeviceInfo.SupportedFormats(1));

    %note that I have just changed end by 1.

    ReplyDelete
  11. still getting the same error....


    Warning: No Image Acquisition adaptors found. Image acquisition adaptors may be available as
    downloadable support packages. Open Support Package Installer to install additional vendors.
    Subscript indices must either be real positive integers or logicals.

    Error in getCameraInfo (line 2)
    camera_name = char(a.InstalledAdaptors(end));

    Error in MatlabArduino (line 18)
    [camera_name, camera_id, format] = getCameraInfo(a);

    ReplyDelete
  12. sir, i got finally my thing work.... by installing "win video" drivers..... thanks for your help.... thanks alot....

    ReplyDelete
  13. Glad you solved it.. I was going to send you this link http://in.mathworks.com/help/imaq/installing-the-support-packages-for-image-acquisition-toolbox-adaptors.html

    ReplyDelete
  14. some how.... i managed to get webcam to run on matlab.... some times i'g getting error like
    Index exceeds matrix dimensions.

    Error in MatlabArduino (line 80)
    bb = round(stats(1).BoundingBox);

    ReplyDelete
  15. The program has its limitations.. The threshold value needs to be adjusted for different environments (lighting). When there is nothing detected after thresholding, size of the stats becomes zero. Hence accesing stats(1) will exceed dimensions.

    ReplyDelete
  16. what changes had to be made if i want to add more devices, like fan tv ac etc.....as a buttons like led and blink

    ReplyDelete
  17. sir, finally, i've done similar to your project... this is the video link

    https://www.youtube.com/watch?v=f5n8XYpAOww

    ReplyDelete
    Replies
    1. Congrats.. That was great.. :) and don't call me sir.. I have just completed my engineering.. I have also seen your other projects on YouTube.. That were awesome.. Keep making things.. And thanks for sharing :)

      Delete
  18. thanks for your complements... i'm looking to build a mind controlled home automation system...will take some time to make this thing work.

    ReplyDelete

 

© 2013 The Repository. All rights resevered. Designed by Templateism

Back To Top