LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

IR Sensor & Digital Read Pin vs. Digital Read Port

Solved!
Go to solution

I do not understand the difference in Digital Read Port.vi and Digital Read Pin.vi. The first outputs a 0 or 1 while the second outputs a False or True. Is one faster?

More importantly, I am trying to re-create the arduino code from this URL:

http://www.ladyada.net/learn/sensors/ir.html

In this tutorial it says "The bad news is that the Arduino's friendly digitalRead()procedure is a tad too slow to reliably read the fast signal as its coming in. Thus we use the hardware pin reading function directly from pin D2, thats what the line IRpin_PIN & (1 « IRpin)does."

How would I accomplish this in LabVIEW?

Thanks

CLD Certified 2014
0 Kudos
Message 1 of 20
(14,605 Views)

AdrexelDragon,

Digital Read Pin reads a single pin.  Digital Read Port reads a port of digital pins (multiple pins at the same time).  The loop rate in LIFA is about 150 Hz when you are using USB which will be much to slow to use digital read VIs to read from the sensor your linked to.  Instead you should add a custom case in the LIFA Firmware to handle reading from the sensor as many times as needed, and then package up the data and send it to LV.

-Sam K

LIFA Developer

0 Kudos
Message 2 of 20
(6,178 Views)

Hi Sam,

Thanks for the response.

Just to be clear on what I need to do:

1. Make an Arduino program that listens for a signal and after it hears it send signal data through USB to LabVIEW

2. Use LabVIEW to call that program to execute

3. Analyze the signal data within LabVIEW

Thanks,

Nick R

CLD Certified 2014
0 Kudos
Message 3 of 20
(6,178 Views)

Nick,

Yes.  If you look at the LIFA Firmware the LabVIEW Interface header file contains a huge case structure.  You can add your own case to this structure with whatever arduino code you need to execute.  Then you can createa  labview VI that calls this case.

Check out the Digital Read VI and Digial Read case in the firmware.  It is a simple example of what the Firmware and VI will need to look like.  If you have any more questions feel free to post them here.

-Sam K

LIFA Developer

Message 4 of 20
(6,178 Views)

Sam,

This is what the arduino uses to read the digital port?

      case 0x06:    // Read Digital Pin

        retVal = digitalRead(command[2]); 

        Serial.print(retVal, DEC);   

        break;

would a add a line called and then insert the code from the tutorial?

case 0x1E: \\ Read IR signal from digital pin

I looked at the DigitalRead.vi and I would need to add an item to the type def for example called "IRdetect" and then I would remove the decimal string to number. I would need a string output; ideally a 2D array string.

Is this correct?

1E would correspond to the index of "IRdetect"?

Thanks,

Nick

CLD Certified 2014
0 Kudos
Message 5 of 20
(6,178 Views)

Nick,

Yes that is the case that coresponds to Digital Read PIN (not port).

Yes, you would want to add a similar case with command value 0x1E.  In this case you can write whatever arduino code you need to execute, but keep in mind the timeout values you specify in LabVIEW.  If the command takes too long to return LAbVIEW will generate a timeout error.  Then update the commands type def and use it in a VI much like the digital read pin VI does.

Sounds like you are on the right track

-Sam K

LIFA Developer

0 Kudos
Message 6 of 20
(6,178 Views)

Sam,

This is the link to the code I am working with:https://github.com/adafruit/Raw-IR-decoder-for-Arduino/blob/master/rawirdecode.pde#L1

I uploaded my edited new firmware but everytime I run the vi, it timesout. I have the timeout at 5 seconds.

The data is not being received by the Send Reveive.vi. Is there any special way to send the data from the Arduino? I just use serial.print("")

Thanks,

Nick

CLD Certified 2014
0 Kudos
Message 7 of 20
(6,178 Views)

Nick,

I didn't have much time to look at your code, but from a quick glance it looks like the case you added counts pulses for a fixed period of time and returns the number of pulses.  the printpulses command prints a lot of garbage that will break LIFA.  My first suggestion would be to rewrite this command or just use a simple Serial.Print like the DIO case to return a fixed number of bytes regarless of the count.  for example send the ditial value in 2 bytes (this will support up to 65535) rather than 2 ascii bytes wich would only support up to 99.

I hope this helps.  If not post back and we can try to look into it a bit more.

-Sam K

LIFA Developer

Message 8 of 20
(6,178 Views)

Sam,

I am going to try and start simple.

Here is a case that I created to learn how to read Arduino serial outputs through LabVIEW.

        case 0x1E:  // Trial

        Serial.print(1234, BYTE);

        break;

How do I call case 1E to run and read "1234" in LabVIEW as a long integer or string?

ScreenHunter_01 Dec. 07 09.05.gif

I tried to manipulate the digital read example but this does not seem to work. It keeps timing out.

Thanks,

Nick

CLD Certified 2014
0 Kudos
Message 9 of 20
(6,178 Views)

Nick,

The serail print command is not doing what you expect due to the BYTE parameter.  Try using

Serial.Print("Hello World");

And set the bytes to read to 11 (Don't forget the space counts as a byte).

Then just use a string indicator to look at the output.

Try making simple sketch that just configures serial and prints in various ways.  Then use the serial monitor in the Arduino IDE to see how changing the serial.print parameters affects the output.  Remember in LV we read bytes and treat them as a string initially.  We can easily change this to any other data format but first we have to know that we are getting the data in the format we expect.

Play around with it and post back.  It will be good to get a basic understanding on how ther serial communication works.  It will help you in the long run.

-Sam K

LIFA Developer

0 Kudos
Message 10 of 20
(6,178 Views)