Go Down

Topic: Arduino and matlab (Read 382 times) previous topic - next topic

aromanillos

Hello, I am trying to read my voltage output of arduino due with Matlab (serial port). However, I need to read the pin at least at 120 Hz. By reading directly i only could read at 10 Hz, so I have increased bps to the maximum. I am able to read 120 per second, but the samples are asynchonous, that is, the time spacing between samples are not the same. I guess it could be because the serial comunication is sending information so reading procedure is disturbed.

Does anybody knows a reliable for of reading arduino pins at that frequency? I am using the progremable port, but there is also a native USB port. May I use tha tport instead? I could I read the information from that port?


This is the arduino code I am using right know. Bps have been changed


int val = 0;

void setup()
{
  Serial.begin(57600);


  Serial.println('a');
  char a = 'b';
  while (a != 'a')
  {
    a = Serial.read();
  }
}

void loop()
{
  while (Serial.available() == 0)
  {
  }
 
  if (Serial.available() > 0)
  {
   val = Serial.read();
   if (val == 'R')
   {
      int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
      float voltage = sensorValue *(3.3/ 1023.0);
       Serial.println(voltage);
   }

 }
}

Go Up