LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Returning Float Number from Arduino to LabVIEW

I'm interested in using LabVIEW to monitor sensor data from an autonomous robot in real time.

I've been able to create a sub-vi which allows me to send a 0-255 integer to the arduino from my LabVIEW console.    The arduino can then execute a set of instructions based on the received integer.

The second step is a little harder. Say for example I have a PING ultrasonic sensor.  The code is readily available to run the PING sensor on the arduino.  What I would like to do is return a float (decimal) number back to LabVIEW.  How might one attack this problem?

0 Kudos
Message 1 of 2
(4,303 Views)

e-Jmo,

If you are passing data via RS-232 the data is sent 1 byte at a time.  If you want to send a data type with more than 8 bits you just need to break in up in arduino code and rebuild it in LabVIEW.

For example to pass an arduino double (32 bit number) you can do the following:

double myNumber = 1337.1234;

Serial.print( ((myNumber >> 24) & 0xFF), BYTE);

Serial.print( ((myNumber >> 16) & 0xFF), BYTE);

Serial.print( ((myNumber >> 😎 & 0xFF), BYTE);

Serial.print( ((myNumber >> 0) & 0xFF), BYTE);

This breaks up the 32 bit number into 8 bit chunks by right shifting it and bitwise anding with 0xFF (0b11111111) and sends them via RS232 with the most significant byte first.

Then in LabVIEW we just build these back together.  You can do a VISA read with the byte count set to 4.  This will give you a string of 4 bytes which you can then put back together into a numeric single (32 bit number).  Remeber the first byte in the VISA read is the MSB of the number.

Let us know if you get it working or need more details on any of this.

-Sam K

LIFA Developer

0 Kudos
Message 2 of 2
(3,144 Views)