Pages: [1]   Go Down
Author Topic: Sending multiple variables from Arduino to Labview with serial.write()  (Read 4165 times)
0 Members and 2 Guests are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello.

I would like to send multiple variables from Arduino to Labview to plot them in real time. Serial.print command is insufficient (laggy), so I've done some searching and found this example: http://www.stefanocottafavi.com/?p=412&page=2. With this VI and code I can now send one float variable without any lag. I don't know how to send more of them though smiley

Here's the Arduino code:

Code:
{
  // 5-byte packet
  Serial.write((byte)0x69); // header
  serialWriteFloat(var/*bmp.readAltitude(103500)*/);

  delay(100);
  
}

void serialWriteFloat(float arg) {
  byte * data = (byte *) &arg;
  Serial.write (data, sizeof (arg));
}

and here's VI:



Is it about adding cases in Labview with different headers and respectively serial.write commands with their names and variable names in Arduino code?

I would be grateful for some help or pointing me in right direction.

Cheers
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


The trick is to make packets of data, a packet starts with a start byte, then an identifier then the value and then a stop byte, optionally there is a crc code for error detection.

think of it as < P = B B B B >

So sending the altitude becomes :

Code:
void writeAltitude(float val)
{
  writeField('A', val);
}

void writeTemperature(float val)
{
  writeField('T', val);
}

void writeField(char ID, float val)
{
  Serial.print('<'); // start byte
  Serial.print(ID); ID
  Serial.write (&val, sizeof (val));
  Serial.print(">");   // stop byte
}

On the receiving site you must unpack the data again of course

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

Thanks for response!

If anybody wondered - yes, adding different cases for given headers along with corresponding commands in Arduino does the trick smiley-wink
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@adamblodz
Can you please post your final code (optionally minimized to the essence) so it can be used for future reference?
Thank you,
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: