Go Down

Topic: Data Transfer between arduino and Sensor using LabView Commands (Read 131 times) previous topic - next topic

suraj_150890


I have programming question.

I want to do two way communication between labview and arduino. For that I am using easy transfer Library which is really helpful. This library work like polling mechanism for eg: if there is any received data then send it.

I am able to communicate arduino with switch and sensor only when I comment the Send_SensorData function in loop. When I am uncommenting it it does not receive anydata. I don't know what is the problem.  Is there any clock issue between arduino and sensor.

Here is the snippet of my code

Code: [Select]


//create two objects
EasyTransfer Msgin, Msgout;

//give a name to the group of data
RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;

static long CycleTime = 10;
static boolean rgb_state = true;
static unsigned long start_time;

void loop() {   

  if (Msgin.receiveData()) {

 // Start only once to start cycle time
    if (rxdata.command == RGB_Sensor_Cycle_Time) {
      CycleTime = rxdata.data;

    }

 Send_SensorData(); //  Uncomment: command will not be received from LV and if commented  reception of command.
}

void Send_SensorData() {

  uint16_t red, green, blue, c;
  unsigned long current_time;
  unsigned long elapsed_time;

  current_time = millis();
  elapsed_time = current_time - start_time;

  if (elapsed_time >= CycleTime && rgb_state == true ) { //&& rgb_state == false

    for (int current_sensor_number = 0 ; current_sensor_number < 1; current_sensor_number++) {

      //Read Data for Sensors 0-7
      tcaselect(current_sensor_number);
      tcs.getRawData(&red, &green, &blue, &c);
      txdata.data1 = map(red, 0, 800, 0, 255),
      txdata.data2 = map(green, 0, 800, 0, 255);
      txdata.data3 = map(blue, 0, 800, 0, 255);
      Msgout.sendData();
    // rgb_state = false;
    }
    start_time = current_time;
  }
}


Go Up