Message Boards Message Boards

problem with data acquisition

Posted 9 years ago

Hello everybody, first of all wanted to acknowledge the help received. Now I have the following problem: I am taking data from a sensor and graphic in Mathematica with /.NetLink. Arduino sends the data and Mathematica receives and executes the graph but sometimes it gets slow and observing the accumulated data of Mathematica, are repeated and gives the impression that for this reason works slowly. Here a screenshot:

Screen Shot!!

Arduino Code:

int pin = 8;
// Pin para la lectura analógica
int led1 = 22;
// Led verde
int led2 = 24;
// Led rojo
int sensor = 0;
float voltaje = 0.0;
// Variables asociadas a la medición. La función voltaje debe ser
// una variable float, ya que puede tomar cualquier valor entre
// cero y cinco volts.
int loops = 0;
float tiempo2 = 0.0;

void setup() {
  Serial.begin(115200);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  digitalWrite(led1, LOW);
  digitalWrite(led2, LOW);
  // Iniciamos ambas salidas para los Leds y los apagamos
}

void loop() {
  float tiempo = millis() / 1000.0;
  if (Serial.available() > 0) {
    char letra = Serial.read();
    switch (letra) {
    case 'A':    
      {
        loops = 1;
        tiempo2= millis() / 1000.0;    
        break;  
      };  
    case 'Z':    
      {
        loops = 0;
        digitalWrite(led1, LOW);
        digitalWrite(led2, LOW);
        break;  
      };  
    }
  }
  sensor = analogRead(pin);
  // Tomamos la señal de voltaje
  voltaje = sensor * 5.0 / 1023.0 ;
  // Transformamos la señal analógica tomada en un voltaje
  if (loops == 1) {
    Serial.print("{");
    Serial.print(tiempo - tiempo2);
    Serial.print(",");
    Serial.print(voltaje);
    Serial.println("}");

    // Enviamos al Mathematica el valor del Voltaje
    // A continuación comparamos el valor del voltaje para encender
    // un Led u otro según sea el voltaje
    if (voltaje >= 2.5)
    {
      digitalWrite(led2, HIGH);
    }
    else
    {
      digitalWrite(led2, LOW);
    }

    if (voltaje < 2.5)
    {
      digitalWrite(led1, HIGH);
    }
    else
    {
      digitalWrite(led1, LOW);
    }
  }

  delay(200);
  // Retardo para tomar 5 mediciones por segundo
}

Neither I can use the function "RemoveEventHandler". I wish you could help me.

Thanks!!!!!!

Fernando

Attachments:
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract