Pages: [1]   Go Down
Author Topic: LabView with multiple sensors  (Read 2810 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm graphing my analog sensor data using a serial connection to labView.  My problem is two fold;  I need to be able to output my data so it is distinguishible within labview. (i.e. my data from sensor "a" goes to graph "a", etc).  Also, I need to split this data up within labview so I can then assign it to the graphs.  I'm sure this is an easy question for anyone who has ever done any work with sensors and labview.  Thanks!
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 627
Posts: 34221
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You need a protocol. You can make it up yourself, you bundle data into packets or groups of bytes. You need to, as you say, be able to distinguish between different sensor data.
Normally you have a header or byte of data that is unique in your packet. So if all the data is in ASCII then a header of 0x02 should be unique and that value should not appear in the data. As part of the header you should have a byte or bytes that identify what sensor data the packet contains.
The packets can be fixed length or variable length. If it is a variable length then you need some information in the header to say how long it is or have another unique identifier that marks the end of the packet.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So let me see if I understand this correctly:
Code:
void setup() {
    Serial.begin(9600);
    analogReference(EXTERNAL);
}
void loop() {
int AValue = analogRead(0);
int BValue = analogRead(1);
Serial.println(AValue);
Serial.println(BValue);
delay(100);
}

Needs to be:
Code:
void setup() {
    Serial.begin(9600);
    analogReference(EXTERNAL);
}
void loop() {
int AValue = analogRead(0);
int BValue = analogRead(1);
Serial.println(0x61 + AValue);  //"a" prefix
Serial.println(0x62 + BValue);  //"b" prefix
delay(100);
}


How can I  decipher this in labview on the other end?  (if you have any experience with labview)  I have a steady stream of data currently which I can manipulate but I can't figure out how to split it up into its respective groups. 
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 627
Posts: 34221
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes that sort of thing.
As you use the println version each value gets sent with a carriage return so it will be received in LabView as a separate string. All you need to do is to examine the first byte of the string to see what sensor it it contains. Then remove the first byte from the string and that leaves you with a string containing just the value.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thats where I'm running into problems.  I can't seem to figure out how to interact with the actual bytes coming from the serial port.  Attached is my VI (if you have labview). 

* Sensor Display.vi (20.24 KB - downloaded 36 times.)
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 627
Posts: 34221
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
(if you have labview). 
Sorry I don't have access to it anymore but I did used to teach it in the late 80s and from what I can remember string manipulation can do that sort of thing.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Serial.println(0x61 + AValue);  //"a" prefix
Serial.println(0x62 + BValue);  //"b" prefix
Quote
Yes that sort of thing.
Sorry, no, not that sort of thing.

Code:
Serial.print("a");
Serial.println(AValue);  //"a" prefix
Serial.print("b");
Serial.println(BValue);  //"b" prefix

Adding 'a' and AValue is NOT what you want to do.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That is exactly what I ended up doing:

Code:
#include <Wire.h>
int tmp102Address = 0X48;

void setup() {
 Serial.begin(115200);
 Wire.begin();
 digitalWrite(13,HIGH);
 analogReference(DEFAULT);
 }

void loop() {
  //Interacting with TMP102 Temp Sensor
  Wire.requestFrom(tmp102Address,2);
  byte MSB = Wire.read();
  byte LSB = Wire.read();
  int TemperatureSum = ((MSB << 8) | LSB) >> 4; //it's a 12bit int, using two's compliment for negative
  float celsius = TemperatureSum*0.0625;

//Data to send to LabView:
    int aValue = analogRead(0);
    int bValue = analogRead(1);
    int cValue = analogRead(2);
    int dValue = 400;
    Serial.print("a");
    Serial.println(aValue);
    delay(50);
    Serial.print("b");
    Serial.println(bValue);
    delay(50);
    Serial.print("c");
    Serial.println(cValue);
    delay(50);
    Serial.print("d");
    Serial.println(dValue);
    delay(50);
    Serial.print("T");
    Serial.println(celsius);
    delay(50);
}

I now have 4 analog sensors plus a TMP102 i2c temp sensor.

In Labview, I used the replace substring function to delete the first character of each data set.  This was the "a", "b", "c", "d", or "T".  I read that replaced string to see what the character was and then assign the remaining string data to it's corresponding chart/thermometer.   There is probably an easier way to do this, but this is what I came up with and it works.  Thanks for everyone's help. 

P.S. If you use this VI you'll notice the 4th sensor chart is inverted to correspond with the sensor that I'm using.  This is easily adjusted in the y axis properties. 

* Sensor Display.vi (31.35 KB - downloaded 70 times.)
« Last Edit: December 14, 2011, 04:01:14 pm by Entropy » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I downloaded the sensorDisplay.vi of version 11. But i am using the version 8.6.1, and it is not working.
So please send the same vi in 8.6 version.

Waiting..
Logged

Pages: [1]   Go Up
Jump to: