Verfasst am: 01.10.2012, 15:55
Titel: Serial Monitor in Matlab (wie in Arduino)
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.
fopen(s); %opens the serial port
t=1;
disp('Running');
x=0;
while(t <= 200) %Runs for200 cycles - if you cant see the symbol, it is "less than" sign. sowhile(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!
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
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.