LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Read Serial Port Connection to Arduino Uno

Solved!
Go to solution

I'm using an Arduino Uno to talk to a 6DOF IMU board (https://www.sparkfun.com/products/10121) and put the data it reads onto the serial connection to my computer, but I can't get the speeds at which the arduino uno puts data on the line to match the rate at which labview reads it, so I end up having this weird scrolling effect on the output string. I have two questions:

1) How can I match these speeds?

2) Once I have the string containing all 6 (don't mind the seventh value, g_T, as I have no idea what it is and can't seem to get rid of it), how can I separate the string into a_x, a_y, a_z, etc and then get the number following each one?

The vi that I used to do this is a slight variation on this one: http://zone.ni.com/devzone/cda/epd/p/id/2669. The arduino code I have says it puts something on the line every 50ms, as does the labview, but clearly something is off. I couldn't figure out how to set up a timer to see how long it takes to execute the while loop I have in the labview code, but I thought that would be a good direction to go to try to line up the timing. You can see that I have it reading 68 bytes per loop, which gives me the slowest "scroll" rate. The string gets shifted by one character about every 6 seconds. As for the string separation, I tried to use the scan string vi but I couldn't figure out how to get the format string so that it looks for the number after a_x:, a_y:, etc (if that's the right way to go about it).

Ultimately I'm going to connect this arduino to an sbRIO-9636 which will act as the onboard controller for a quadrotor. I know it's not the most elegant solution, but I spent 2 months trying (and failing) to implement i2c communication on the RIO and finally came up with this, so my fingers are crossed that it'll work well enough to make this thing easy to fly/control. I'd appreciate any help that you can offer.

Mark

Download All
0 Kudos
Message 1 of 9
(10,312 Views)

Hi, I was checking your code in labview and I can realize that reading and writing serial port for asynchronously perform what, I think that can not be done simultaneously, you must enter a delay for an error that does not originate in VISA, check out this link

http://zone.ni.com/devzone/cda/epd/p/id/2669

0 Kudos
Message 2 of 9
(5,264 Views)

You can also review this issue in the following link

http://forums.ni.com/t5/LabVIEW/arduino-serial-monitor-via-LabView/m-p/2389576#M741227

attached a code example that works with the ADXL335 accelerometer sensor which must filter the data frame on the serial port

Download All
Message 3 of 9
(5,265 Views)

I'm not sure what you mean in your first post, and the link that you have there is what I was using in the first place (cited in the top of the 3rd paragraph of my original post). The second link might help, but the arduino code you posted would be a step backwards because I already have one that reads BOTH the accelerometer and the gyroscope as well as a labview code to determine the roll, pitch, and yaw from these. Also, I've used that code before for an ADXL335, and it's not very reliable.

0 Kudos
Message 4 of 9
(5,265 Views)

hello, I do not propose that the shared code is the salucion to your problem, I see that the second question that you want to know how to filter the plot takes data from serial port

0 Kudos
Message 5 of 9
(5,265 Views)

I got the send/receieve stuff synchronized and everything is working now, so thanks for the help.

0 Kudos
Message 6 of 9
(5,265 Views)

Could you post your solution or how you synchronized the Arduino to LabVIEW?

Now Using LabVIEW 2019SP1 and TestStand 2019
0 Kudos
Message 7 of 9
(5,265 Views)

I was able to implement I2C on an sbRIO-9632 using an example from the robotics module.  I believe ther e is also one on IPnet.  Connecting an Arduino to an sbRIO is quite amusing.  Does this mean you have UART (I think) implemented on the sbRIO?

0 Kudos
Message 8 of 9
(5,265 Views)
Solution
Accepted by topic author M_Johnson

For some reason I can't attach the files in a response and the picture is too large to upload, so I'll do my best to describe what I did.

The way that I got them synchronized was by using the basic serial read/write vi from above to send a command to the arduino, then listen for the arduino's response. The arduino was programmed to not write anything onto the serial connection unless it received the command I specified in labview. For my version, I simply sent "a" and had the arduino listen for "97", which is the corresponding ASCII nubmer. I then used a "scan from string" block to separate the string into DBLs. I knew that six numbers would be sent from the arduino, so the "scan from string" block's format string input was "%f %f %f %f %f %f" (six floats). I had to put in a "wait" block (for 50 ms) as well because the arduino takes some time to do it's reading and write it to the serial port.

The arduino's write sequence is now inside an if statement (see the code that I uploaded in the original post for the rest of it) that reads:

void loop() {

  getAccelerometerData(acc);

  getGyroscopeData(gyro);

  if (Serial.read() == 97) {

    Serial.print(acc[0]);

    Serial.println();

    Serial.print(acc[1]);

    Serial.println();

    Serial.print(acc[2]);

    Serial.println();

    Serial.print(gyro[0]);

    Serial.println();

    Serial.print(gyro[1]);

    Serial.println();

    Serial.print(gyro[2]);

    Serial.println();

  } 

  else  { }

}

If there are any follow-up questions, I'm happy to answer them. Oh and if there's some way to post these files in a response, let me know, because I'm sure that'll be a lot easier to understand.

0 Kudos
Message 9 of 9
(5,265 Views)