Pages: [1]   Go Down
Author Topic: ARDUINO + MATLAB Real time graph *help asap please  (Read 1449 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am working on a controls project. mech engr dont know much about ece
i have an IR emitter and detector that detects how fast the radiometer is spinning using the arduino uno
the code is here

Code:
int ledPin = 13;
int statusPin = 12;

volatile float time = 0;
volatile float time_last = 0;
volatile int rpm_array[5] = {0,0,0,0,0};
volatile int stat;

void fan_interrupt() {
  time = (micros()-time_last);
  time_last = micros();
  
  if(stat == LOW) {
    stat = HIGH;
  }
    else {
      stat = LOW;
  }
  digitalWrite(statusPin, stat);
  
}

void setup() {
  Serial.begin(9600);
  
  attachInterrupt(0, fan_interrupt, FALLING);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
  pinMode(statusPin, OUTPUT);
  
}

void loop() {
  int rpm = 0;
  
  while(1) {
    delay(1000);
    
    if(time>0) {
      rpm_array[0] = rpm_array[1];
      rpm_array[1] = rpm_array[2];
      rpm_array[2] = rpm_array[3];
      rpm_array[3] = rpm_array[4];
      rpm_array[4] = 60*(1000000/(time*4));
      
      rpm = (rpm_array[0] + rpm_array[1] + rpm_array[2] + rpm_array[3] + rpm_array[4])/5;
    
    Serial.println(rpm,DEC);
    
    }
  }
}


i need help in creating the real time plot on matlab
the graph should show rpm vs time

a=arduino('com4');
Attempting connection .............
Basic I/O Script detected !
Arduino successfully connected !

i got the uno to connect to matlab
just need help on the code
can anyone help me please asap


Moderator edit: [code] [/code] tags added.
« Last Edit: March 05, 2013, 12:49:34 am by Coding Badly » Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 206
Posts: 12896
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Please do not cross-post.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
just need help on the code
Did you get help writing that Arduino code on the MatLab forum?
Logged

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 217
Posts: 13705
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


 1000000  ==> 1000000L  to explicitely make it long, for the rest it should work (you do some average rounds per minute ?)
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: