Show Posts
Pages: [1]
1  Using Arduino / Interfacing w/ Software on the Computer / Serial Monitor (programming in Matlab) on: October 05, 2012, 07:51:02 am
Hey there

I hope some of you guys have some Matlab experience or maybe can still help me.
I want to write an Interface for Matlab that works just like the Serial Monitor in Arduino.
But unfortunately, I do not have much experience with electronics, so I hope my questions do not sound too stupid. ^^'

So it is an Arduino Diecimila Board board I am using and there are six pins on it which I should make visible in Matlab. They are the Analog Input pins.

So I have a little function, with which I can get some output for one port.
But as I said, I understand some programming but little electronics and not much about ports. So I don't really know, how to open the additional ports and what port corresponds to what pin on the board (which is my biggest question, e.g. to which pin  does "COM3" correspond?).

Does anybody know, what I have to enter, in order to get numbers like in the Serial Monitor for those six analog inputs?

The Matlab code looks like this:

function serialMonitor

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);
prop(3)=(get(s, 'StopBit'));
prop(4)=(get(s, 'InputBufferSize'));
disp(['Port Setup Done!!',num2str(prop)]);
fopen(s);           %opens the serial port
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!
   axis auto;
   grid on;
   disp([num2str(t),'th iteration max= ',num2str(a)]);
   hold on;
   a=0;  %Clear the buffer
fclose(s); %close the serial port

Pages: [1]