LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Import multiple inputs from serial monitor (arduino) to Labview

I need to control the temperature of two controlers (T1 and T2) of an Arduino. They must be controlled using an On-Off control and the user must insert the SetPoint for equipment 1 and equipment 2. I developed the following code on arduino:

 

The user inserts, on the Serial Monitor, setpoint 1 and setpoint 2. My problem is how to import both that data to labview. I tried controlling just T1 (and, so, the user should just insert setpoint 1) and used the following labview code:

 

float t1;
float t2;
float vt1;
float vt2;
float setpoint1;
float setpoint2;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  analogReference(INTERNAL);
  pinMode(9, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
   if (Serial.available() > 0) {
    setpoint1 = Serial.parseFloat();
  }
   if (Serial.available() > 0) {
    setpoint2 = Serial.parseFloat();
  }
 
  vt1 = analogRead(0)*3.3/1023.0;
  t1 = vt1 * 100 - 50;
  Serial.println(t1);
  vt2 = analogRead(2)*3.3/1023.0;
  t2 = vt2 * 100 - 50;
  Serial.println(t2);

 
  if (t1 < setpoint1)
    digitalWrite(3, HIGH);
  else
    digitalWrite(3, LOW);

 if (t2 < setpoint2)
    digitalWrite(5, HIGH);
  else
    digitalWrite(5, LOW);

  if (t1 < setpoint1)
    digitalWrite(9, HIGH);
  else
    digitalWrite(9, LOW);
   
  if (t2 < setpoint2)
    digitalWrite(9, HIGH);
  else
    digitalWrite(9, LOW);

  delay(400);
}
ruimatias_0-1666441652520.png

 

0 Kudos
Message 1 of 2
(1,261 Views)

You've got an Arduino that can read (on command) from two sensors and return values from each sensor.  You need to look at these two values and make a Boolean decision for each of them.

 

Since I "know" LabVIEW, and "not so much" Arduino, I'd divide the Task into two parts:

  • Arduino -- knows how to read two sensors and return a numeric value (unscaled) from each.  It also knows how to use a Boolean to toggle an Output (make a TTL Pulse, open/close a Relay, something like that).  It also can (periodically) send serial data out, and read serial data in.
  • LabVIEW can read serial data, interpret the data, and if it is numeric, do arithmetic to, for example, convert a binary value representing a voltage at a sensor into, say, a "Temperature to be controlled".  It can also "make decisions" in "User-friendly terms", i.e. "The temperature is too high".  It can also write serial data in a format that is "friendly" to the recipient, doing any conversions that need to be made.
  • Someone needs to decide "who keeps track of time".  LabVIEW, being an "Engineering Workbench", is quite good at doing this.

So I'd structure my Arduino code (actually, I'd get an EE student to help me with this -- what do I know about an Arduino?) to start running and "listen" on a Serial Port for the letter "S" (for "Sample").  When the Arduino sees this, it reads its two Sensors, and without altering or otherwise processing the numbers, sends them out on the Serial Port and listens for another command that "does something" (maybe "H1 On", or "H2 Off", if you've got two Heaters to control).

 

The LabVIEW part almost writes itself.  In my simple model, I need to start the Arduino first.  LabVIEW sends (using VISA) an "S", waits for a String from the Arduino (however you decide to package the information from the Sensors, remembering that you can send the numeric data without needing to do arithmetic in the Arduino), LabVIEW converts the numeric data into, say, Temperature(s), compares it with "criteria", then sends a Command to do something (like turning on Heater 1 and turning off Heater 2).  LabVIEW does this in a While Loop with a Wait (ms) clock to govern the speed, and a "Stop" button that sends the "Quit" command to Arduino, then exits LabVIEW.

 

Let LabVIEW do the "heavy lifting".  Let the Arduino read its sensors, send/receive data using its Serial Line, and turn on/off its digital ports.

 

Bob Schor

0 Kudos
Message 2 of 2
(1,230 Views)