LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Arduino I2C, 5003 error

First of all, thanks in advance to everyone who reads this.

I'm currently trying to use LIFA to communicate to an optical mouse sensor (ADNS2620) which I am using to measure displacement (by reading the delta X registers on the sensor).

I got the sensor working when the code was purely in Arduino, but I tried to replicate the code using LIFA and I immediately encountered a problem. I attached a simplified version of the code (not bothering to look at the data from the I2C Read function, just looking at the error)and using highlight error I could see that I was getting a 5003 error from the read function. Looking through the Read function it's clear that it's timing out in the Send/Receive portion of the code, but I can't figure out why.

I tried changing the baud rate  to 9600 (which was the rate I used in my Arduino code, which is based on the Sparkfun example code for my sensor), and still nothing. I even tried using the Send/Receive function directly instead of the Read function, increasing the the timeout to 1000, all to no avail. I know it doesn't help that I'm quite new to Arduino and Labview, and I'm sorry if this is too simple a question.

Thanks again in advance,

Steven.

PS:I also attached the arduino code

Download All
0 Kudos
Message 1 of 13
(11,378 Views)

comsicomics,

First I want to make sure that you are using the LIFA firmware when you are using LabVIEW to communicate with the Arduino.  You can find the setup procedure here.  

When you call mouse.begin and mouse.read on the Arduino there is a lot going on behind the scene.  You can open the adns2620.h and adns2620.c file to see what is actually happeing when you call mouse.read.

When using I2C there is one master (The Arduino) and one or more slaves (the mouse sensor).  The master initiates all communication.  No slave can 'talk' without the master telling it to.  For this reason you cannot just 'read' the register with the master.  You first have to send a request for some data to the slave you want to read from.  You can do this in LabVIEW using the I2C write command.  The exact command you send will depend on the data the sensors expects.  Typically you would find this information in the sensors data sheet, but you can also look through the adns2620.c file and reverse engineer what they do in C and cretae the necissary LabVIEW code.  Once you have sent the command to the sensor then you can call the I2C Read VI in LabVIEW to read the response from the slave device.

This is a super simplified explination of an I2C read but it should point you in the right direction.  This website contains some good info on I2C.

Let us know if you have any questions and please post your code when you get it working.

-Sam

LIFA Developer

0 Kudos
Message 2 of 13
(3,700 Views)

Double check to make sure the addressing is correct.  Assuming you got your board from SparkFun.com... they do some weird stuff to their I2C addresses. 

On their schematic, the address for my 6 degrees of Freedom Gyro was supposed to be 0xD0 for write and 0xD1 for read.

Well, in the schematic, it says the address is 0b1101000, which is 0x68... not even close...  Now, shifting the bits to the left to insert the read/write bit gives me 0xD0 for write, and and 0xD1 for read.  You may want to toss the lowest bit and shift to the right to get the correct addressing.

0 Kudos
Message 3 of 13
(3,700 Views)

Im getting a 5003 error that seems to be due to a "delay(ms);" line in my code below. It is placed in the Loop as per instructions. If my delay is short, say 50ms, the analogpinread vi (from examples) works fine. If my delay is longer I get the error. Most of my codes have such delays. Does this mean I can never write code with such delays and still read the analog pins on my arduino? 

checkForCommand();

  // Place your custom loop code here (this may slow down communication with LabVIEW)

delay(5000);

0 Kudos
Message 4 of 13
(3,700 Views)

Hello,

Why are you introducing the delay in the arduino environment? This essentially causes the program to only check for a command every 5 seconds. So if you call the analogpinread VI, but the command does not reach the Arduino for another 5 seconds, this is likely causing the timeout. The default timeout on Arduino read functions is 100 ms. This explains why a delay of 50ms works.

You can modify this by going into the Analog Read Pin VI and modifying the timeout input on the Send Receive VI, or you can try implementing a delay in your LabVIEW program using a Wait or similar timing function.

- Julianne

Julianne K
Systems Engineer, Embedded Systems
Certified LabVIEW Architect, Certified LabVIEW Embedded Systems Developer
National Instruments
0 Kudos
Message 5 of 13
(3,700 Views)

JulianneK, thanks for the response. Im new to this so bear with me. There is actually a lot more code than just the delay. The delay() alone is enough to time out. But a long 'while' or 'for' loop will cause same problem. My code is already written and I dont want to rebuild in labview language. In addition, this will have to run without labview in the future when it is disconnected from computer. As I understand it, Labiew cannot load onto the arduino. So what Id like to do is keep my code (on the arduino) and use labview to monitor the pins (analog in this case) to gather the data and graph it. This would be extremely valuable. Is this possible?

0 Kudos
Message 6 of 13
(3,700 Views)

In order to use the LIFA framework the way it is set up you need to make it so that your code does not use long while loops or long delays (or basically any function that keeps the rest of the framework from executing). What is it that this other code is doing? I think you will probably want to make some architecture changes to do what you want but in suggesting those it would be helpful to have an idea of the big picture.

Kevin Fort
Principal Software Engineer
NI
0 Kudos
Message 7 of 13
(3,700 Views)

Kevin, thanks for the help.

What Id like is a way to use labview to monitor my arduino analog pins-Collect and graph that data in real time-without disposing of my non-labview code. You see, that same arduino will be disconnected from Labview environment and run on its own with the arduino/C language Ive written for it.

So Im wondering if I have to generate two versions of the code? C AND labview  = lots of work on my part and probably not worth the effort.

Or, can I just send Labview the data every 100ms or so from my inside my loops via a Serial.write statement or something? Isn't there a way to get the serial data to the labview environment much like I write to the arduino serial monitor?

A hardware alternative would be to dedicate a "LIFA arduino" and wire it directly to the arduino under test. But that seems redundant and labor intensive.

Best,

0 Kudos
Message 8 of 13
(3,700 Views)

Hey,

For your use case I would actually recommend not using LIFA. What I would do is write the data from inside your current loops (like you said every 100ms or so). Then in LabVIEW just make a loop which monitors the serial port and whenever bytes are available reads, parses and plots them to a chart. It will be a lot easier and less work to do it this way if you have a lot of code you want to run concurrently with LIFA.  Post back if you have any questions on this.

Kevin Fort
Principal Software Engineer
NI
0 Kudos
Message 9 of 13
(3,700 Views)

Great, thanks Kevin. Ill give that a shot.

0 Kudos
Message 10 of 13
(3,700 Views)