I got this error Undefined function 'writeDigitalPin' for input arguments of type 'double'. while using trying to run the code.How do i repair it.I am interfacing arduino and matlab.
    11 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    ROHAN SAPHAL
 el 3 de Mayo de 2016
  
    
    
    
    
    Comentada: Lucas
 el 6 de Nov. de 2023
            % Capture the video frames using the videoinput function
% You have to replace the resolution & your installed adaptor name.
vid=videoinput('winvideo',1,'YUY2_640x480');
% Set the properties of the video object
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorspace', 'rgb')
vid.FrameGrabInterval = 5;
% a=arduino('COM3','mega');
%start the video aquisition here
start(vid)
xr=320;
 yr=240;
% Set a loop that stop after 100 frames of aquisition
while(vid.FramesAcquired<=300)
      % Get the snapshot of the current frame
      data = getsnapshot(vid);
      % Now to track red objects in real time
      % we have to subtract the red component 
      % from the grayscale image to extract the red components in the image.
      diff_im = imsubtract(data(:,:,1), rgb2gray(data));
      %Use a median filter to filter out noise
      diff_im = medfilt2(diff_im, [3 3]);
      % Convert the resulting grayscale image into a binary image.
      diff_im = im2bw(diff_im,0.18);
      % Remove all those pixels less than 300px
      diff_im = bwareaopen(diff_im,300);
      % Label all the connected components in the image.
      bw = bwlabel(diff_im, 8);
      % Here we do the image blob analysis.
      % We get a set of properties for each labeled region.
      stats = regionprops(bw, 'BoundingBox', 'Centroid');
      % Display the image
      imshow(data)
      hold on
      %This is a loop to bound the red objects in a rectangular box.
      for object = 1:length(stats)
          bb = stats(object).BoundingBox;
          bc = stats(object).Centroid;
          rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
          plot(bc(1),bc(2), '-m+')
          a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), '    Y: ', num2str(round(bc(2)))));
          set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
r=[3 4];
l=[5 6];
   x2=bc(1);
  y2=bc(2);
       ex=x2-xr;
       ey=y2-yr;
       if(ex>=25||ex<-25)
           dx=ex;
       else
           dx=0;
       end
       if(ey>=25||ey<-25)
           dy=ey;
       else
           dy=0;
       end
       dx=60;
       dy=-60;
       if((dx*dy)>0)
          if(dx>0)
              writeDigitalPin(a,'D5',0);
              writeDigitalPin(a,'D3',0);
              f2=(5/(dx+dy))*dy;
              writePWMVoltage(a,'D4',255);
             writePWMVoltage(a,'D6',f2);
          else
              writeDigitalPin(a,'D4',0);
              writeDigitalPin(a,'D6',0);
              f2=(5/(dx+dy))*dy;
              writePWMVoltage(a,'D5',255);
              writePWMVoltage(a,'D3',f2);
          end
       elseif((dx*dy)<0)
           if(dx>0)
               writeDigitalPin(a,'D6',0);
               writeaDigitalPin(a,'D4',0);
               f2=(5/(dx-dy))*(-dy);
               writePWMVoltage(a,'D3',255);
               writePWMVoltage(a,'D5',f2);
           else
               writeDigitalPin(a,'D6',0);
               writeDigitalPin(a,'D3',0);
               f2=(5/(dy-dx))*dy;
               writePWMVoltage(a,'D6',255);
               writePWMVoltage(a,'D4',f2);
           end
       end
       xr=x2;
       yr=y2;
      end
      hold off
  end
% Both the loops end here.
% Stop the video aquisition.
stop(vid);
% Flush all the image data stored in the memory buffer.
flushdata(vid);
% Clear all variables
clear all
%sprintf('%s','That was all about Image tracking, Guess that was pretty easy :) ')
0 comentarios
Respuesta aceptada
  Walter Roberson
      
      
 el 3 de Mayo de 2016
        writeDigitalPin was not available on the first version of the arduino support package, which was for R2011a to R2013b; see http://www.mathworks.com/matlabcentral/fileexchange/32374-legacy-matlab-and-simulink-support-for-arduino. That older package used digitalWrite() instead of writeDigitalPin. If you have R2014a or later you should be installing http://www.mathworks.com/matlabcentral/fileexchange/47522-matlab-support-package-for-arduino-hardware
2 comentarios
Más respuestas (1)
  Danilo NASCIMENTO
      
 el 11 de Sept. de 2018
        I use writeDigitalPin(a,'D9',1); in the command line and it works just fine. However when I go to the GUI and set the same command when the button is pushed and receive the message: Undefined function 'writeDigitalPin' for input arguments of type 'double'. I don't think is an issue with the version as I am using R2017 Matlab. What might be then?
3 comentarios
  JT
 el 29 de Mayo de 2019
				Can anyone give an example of what the output of arduino() should be? I am stuck on a similar problem.
Ver también
Categorías
				Más información sobre Image Preview and Device Configuration en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




