Pages: [1]   Go Down
Author Topic: Communication Arduino MatLab  (Read 348 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Everyone.
I have an Arduino 2560 Mega R3 , Arduino motorshield R3, stepper and a hall sensor.

I want that the Arduino sends data over the serial interface to MATLAB.
My Matlab code for that:
Code:
clear all;

 %Create serial Port
 arduino=serial('COM5','BaudRate',9600);

 %Open serial Port
 fopen(arduino);

 while 1
    i=fread(arduino);
    fprintf('%d\n', i);
 end

 %Close serial Port
 fclose(arduino);

 %Delete serial Port
 delete(arduino);

My Arduino code for that:
Code:
int sensor;
 void setup()
 {
   Serial.begin(9600);
  }

 void loop()
 {// this should simulate a sensor
   for(sensor=0; sensor < 100; sensor++){
         Serial.print(sensor);
   }
 }

If someone of you can help me pls, i would be glad.  Thanks
Logged

Pages: [1]   Go Up
Jump to: