WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Serial Monitor in Matlab (wie in Arduino)

 

Barnabas

Gast


Beiträge: ---
Anmeldedatum: ---
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 01.10.2012, 15:55     Titel: Serial Monitor in Matlab (wie in Arduino)
  Antworten mit Zitat      
Hallo.
Ich habe eine Frage und hoffe, es kennt sich jemand damit aus.
Und zwar soll ich ein Matlab Inferface schreiben, das der "Serial Monitor" Funktion aus dem Programm Arduino entspricht.

Leider kenn ich mich absolut nicht mit Elektronik aus und weiss nicht genau, wie ich das anstellen soll.
Ich hoffe, die Fragen klingen nicht allzu dumm, aber ich weiss wirklich nicht so recht, wie das geht.

Es handelt sich um ein Arduino Diecimila Board und sechs der Pins auf dem Board soll ich im Matlab sichtbar machen. Die Pins sind mit "analogue input" angeschrieben. Dazu soll dann noch die Zeit.

Ich habe ein Programm im Internet gefunden, aber vollständig löst es mein Problem nicht.
Mir ist nicht ganz klar, ob COM3 einem dieser Pins entspricht, und ob ich einfach noch weitere Ports öffnen muss, etc.

Ich stelle hier mal den Code rein und hoffe, es weiss jemand, wie man den modifizieren muss, damit die gewünschten 6 Werte (bzw. 7 mit der Zeit) angezeigt werden.

Code:

function serialMonitor


%run('clean');
clear all;
close all;
 
s = serial('COM3'); %assigns the object s to serial port
 
set(s, 'InputBufferSize', 256); %number of bytes in inout buffer
set(s, 'FlowControl', 'hardware');
set(s, 'BaudRate', 9600);
set(s, 'Parity', 'none');
set(s, 'DataBits', 8);
set(s, 'StopBit', 1);
set(s, 'Timeout',10);
%clc;
 
disp(get(s,'Name'));
prop(1)=(get(s,'BaudRate'));
prop(2)=(get(s,'DataBits'));
prop(3)=(get(s, 'StopBit'));
prop(4)=(get(s, 'InputBufferSize'));
 
disp(['Port Setup Done!!',num2str(prop)]);
 
fopen(s);           %opens the serial port
t=1;
disp('Running');
x=0;
while(t <= 200)  %Runs for 200 cycles - if you cant see the symbol, it is "less than" sign. so while (t less than 200)
 
   a =fread(s); %reads the data from the serial port and stores it to the matrix a
   a=max(a);  % in this particular example, I'm plotting the maximum value of the 256B input buffer
 
   x =[x a];  % Merging the value to an array, this is not very computationaly effective, as the array size is dynamic.
                 %Consider pre allocation the size of the array to avoid this. But beware, You might loose some important
                  %data at the end!
 
   plot(x);
   axis auto;
   grid on;
 
   disp([num2str(t),'th iteration max= ',num2str(a)]);
   hold on;
   t=t+1;
   a=0;  %Clear the buffer
   drawnow;
end
 
fclose(s); %close the serial port


end


 



[img]
http://arduino.cc/en/uploads/Main/ArduinoDiecimilaComponents.jpg
[/img]


Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2025 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.