LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Mega 2560 - 5002 error

I have a Mega 2560 Arduino board.

Has anyone successfully worked with the Mega2560 and LVIFA driver?

I get a 5002 error (Unable to establish connection with Arduino.  Please ensure that you have selected the correct COM port and that you have flashed the Arduino with the correct firmware.)

It times out before it receives an answer from the Sync Packet that is being sent in the initialization procedure. The Rx LED on the board keeps flashing as the sync packet is sent multiple time. After the default 20 timeouts, it gives up and throws the 5002 error. All this time, the Tx LED is not flashing at all, as if it's never answering.

I've tried it on three systems with the same results. Two running on Win7 x64. One has LabVIEW 2009(32-bit) and LabVIEW 2010(32-bit) installed. The other runs LabVIEW 2010(64-bit). The third system is a WinXP (32-bit) with LV 2009.

I have NI VISA 5.0.3 installed with the latest LVIFA version 1.3.0.23. I also downgraded to 1.2.0.21 on LV2010 systems and got the same thing.

Arduino board works fine when I flash the "Blink" example that comes with the Arduino IDE. I get the above error when I have the LVIFA_Base.pde file uploaded.

Unfortunately, I don't have a Uno board to try and see if I'm doing something wrong.

GCentral ChampionCLA
0 Kudos
Message 1 of 61
(61,461 Views)

Normandinf,

I have successfully used the toolkit on the 2560.  Have you tried wiring a constant into the Init VI's Visa Resource input?  If you are seeing the RX light flash on the MEGA that tells us that data is being recieved by the board.  Are you connected via USB?  Do you have anything plugged into DIO pin 0 or 1?  Did you get any errors when you deploy the firmware to the Arduino?  What does your LV Code look like?  Have you tried one of the examples?

Please let us know and we will get you up and running asap.

-Sam

LIFA Developer

0 Kudos
Message 2 of 61
(7,535 Views)

Thanks for these tips.

I use USB for communication. I don't get any errors with the Arduino deployment. I actually managed to write my own code to communicate with the Mega 2560, and I can read an analog input and control the LED at pin 13 via PWM, and trigger actions by sending serial commands just like your checkForCommand() code. However, using the example supplied with LVIFA, it fails with error 5002. (Read Analog Pin Example). Nothing is connected to DIO 0 and 1, which would interfere with serial comm.

It must be the simplest thing missing, perhaps a serial setting that is wrong. My COM port is set to these parameters: 115200 baud rate, 8 data bits, no parity, 1 stop bit, no flow control, no termination characters. 

I copied and modified your code to insert Serial.write commands here and there, to monitor where it fails for me.

I think it simply doesn't get 15 characters. When I use the terminal window and send 15 characters (all zeros for example), I can have your program print something on the terminal window and go through the checksum test. However, when I'm in LV, it always times out. My guess is that the chain of characters is not 15 or longer, hence the Serial.flush() command is called instead. It doesn't even go to the point where the checksum is verified.

This simple diagram fails. (Init + Close)

http://content.screencast.com/users/normandinf/folders/Jing/media/3a175473-531a-471d-b44a-7c6deaaf96...

GCentral ChampionCLA
0 Kudos
Message 3 of 61
(7,535 Views)

normandinf,

The toolkit will not work if you add serial communication code using the same USART that you use to connect to LabVIEW.  I assume that for your original connection attempt you used the standard LIFA base firmware.  Is this correct?

-Sam

LIFA Developer

0 Kudos
Message 4 of 61
(7,535 Views)

Yes. And for the trials I did on the other two computers, I didn't meddle with the code. Those were fresh installs of the Arduino IDE and LIFA code.

GCentral ChampionCLA
0 Kudos
Message 5 of 61
(7,535 Views)

OK, I tried many things and the toolkit works, except for the Init VI.

To have good behavior, I need to manually initialize the VISA settings. Then, when I feed directly the data bytes to the "Send Receive" VI, I can make it work (receive the "sync" response).

But I'm not sure yet the stone must be thrown at the init VI. I don't get the same behavior if I call "VISA Configure Serial Port (Insrt).vi" in a VI (as shown below) or if I open its front panel and run it manually prior to using the LIFA driver.

There is something going on that I don't understand with the COM port settings. I am at a loss as to why the VISA Configure Serial Port VI doesn't do it's job when called as a subVI... It must be the same thing that happens in Init.vi of the LIFA driver.

What is even more puzzling is how it could happen on three machines with three versions of (Windows) OS.

What is the earliest VISA driver that you know would work? I'll try to downgrade and see if that solves it.

http://content.screencast.com/users/normandinf/folders/Jing/media/8d547d63-53c8-4514-8ed3-089735ad3524/2011-06-16_1015.png 

Temporarily, I've disabled it in the Init.vi of LIFA, and it seems to work correctly.

http://content.screencast.com/users/normandinf/folders/Jing/media/f0ceee50-5b34-4a06-9577-b0d29461ed43/init.png

GCentral ChampionCLA
0 Kudos
Message 6 of 61
(7,535 Views)

I was having the exact same problem.  Every time I ran one of the examples I received the 5002 error for my Arduino Mega 2560 board, until I turned on the highlight execution in the Init.VI and then it worked every time in both the BlinkM and Servo examples.  Further experimentation showed that the error originated in the Send Receive sub VI inside the Init.vi.  I increased the delay in the "USB / Serial" case structure to 10000 (10sec) and the Init.VI and the examples worked every time.

0 Kudos
Message 7 of 61
(7,535 Views)

normandinf,

Have you added any code to the LIFA Firmware?

normandinf and MAELabman,

Are you using a USB 2.0 Port? (My best guess at this point is that this is the cause of the strange behavior.  The slower port may cause timeouts due to slower data transfer).

-Sam

LIFA Developer

0 Kudos
Message 8 of 61
(7,535 Views)

No code added to LIFA firmware.

I've messed with it a little to see if I could get a feel of where it was not responding, but ultimately it was the VISA serial settings that did it for me, so I restored the original code and just changed the Init VI as shown above.

I'm using USB 2.0 port.

GCentral ChampionCLA
0 Kudos
Message 9 of 61
(7,535 Views)

Hello I have de same problem

How can I resolve this prbloem?

0 Kudos
Message 10 of 61
(7,535 Views)