LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Back to basics...

Hi everybody.

I'm pretty much brand new to the whole lifa/lv scene.

I've just got some basic questions.

What actually gets uploaded to the arduino on the lifa base. ino file? Does the whole folder or just those few with #includes?

What I want to do is make lv work with my sr-04 ultrasonic sensor and there is no vi. There is a really good arduino ino library called newping though that I would love to use. Do I need t add that library to the lifa folder? If I do how do I then use lv to interface with it?  I understand you need a corresponding vi,  but what would that look like?  Would that just be using send recieve.vi or something more specific to new ping?

Therefore I am wondering if lifa base is complete,  and all your further programming only needs labview,  ie just write vi's which use basic read and writes.

Hopefully this makes a little bit of sense. Cheers

0 Kudos
Message 1 of 13
(6,083 Views)

Because the Arduino is so versatile, LIFA does not have all the features of Arduino implemented.  Therefore, there are many things that require modifiying the LIFA firmware and adding corresponding LabVIEW functions.

Regarding the SR04 sensor, IIRC it requires the pulseIn() function on the Arduino which is something that is not implemented in LIFA.

Adding functions to LIFA is not all that hard if you carefully study existing LIFA functions (how the LabVIEW VIs work with the firmware on the Arduino as far as data that is passed).  Also, when adding functions for new sensors that you cannot implement purely in LabVIEW, I recommend getting basic Arduino code to work with the sensor first.  This will help reduce frustration compared to trying to do everything in LIFA first because sometimes it's hard to tell what is causing something to not work (Arduino or LabVIEW).

When adding sensor specific libraries, you need to put the include file in the same folder as LIFA_Base.ino (there might be one other place to put it but I don't know how the IDE handles it's own include files).

If you have specific questions while trying to implement your code, post as many details as possible include your firmware with modifications and your LabVIEW code.

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

I updated the firmware and LabVIEW VI for the SRF05 that I made a while back.  It should work for the SR-04 because the they communicate in the same manner.

https://decibel.ni.com/content/message/38645#38645

You need to use the Arduino code provided in the LIFA_Base folder that comes inside this zip file.  Let me know if you get it working.

Message 3 of 13
(3,690 Views)

wow great reply...huge help.

after lots of digging/reverse attempted programming, i have found within the LIFA_base labVIEWinterface file, all the labview specific commands for the functions built in.

there is one variable in particular "command" which i can find in labview but i cannot edit it to add more commands. how is this array/list populated? it seems id need to add a few of my own like pulseIN to make it work. can anyone explain the manner in which command[] works?

also, it seems that after everything else, sendrecieve is still really the base of the labview interface. i dont actually know what is sent to the arduino, though i gather that the arduino figures out which command[] was sent and processes the message accordingly, then replys to labview. is this correct?

i had a look at the sr-05 zip posted above but it seemed the command list was replaced by an input FE. turns out there is a special case within LABVIEWinterface that processes the data accordingly. within these processes, is a few digital writes where the input is command[2]. can anyone quickly explain what parsing command[2] will actually do?

cheers guys, really helpful so far

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

command[] is just a byte array of the data sent by LabVIEW, that's it.  The zeroth byte is always 0xFF.  The first byte is an eight bit integer that tells the firmware what function it being called (handled by the main switch statement).  Any byte after that is data for the function being called.  In the case of the code that I linked to above, I use two of these extra bytes to know what pins to use for triggering and receiving the signal from the sensor. 

NOTE:  The zeroth byte is automatically added by function within the SendReceive VI.  Never modify the SendReceive VI.

So, if you look at my VI for reading the sensor, you will see that the first thing that I put in the array to be sent is the function reference (command[1]) followed by the other data that I use in my function.  So, if you create your own function, you need to make another case analagous to the 0xFE (with a new number like 0xFD) and then use that as the first array element (where 0xFE is located in my VI).

Message 5 of 13
(3,690 Views)

ok so ive had another stab. the command[] makes sense now. what i really want to do is use the newping library, so ive modified your firmware to instead use a newping function.

ive also changed around the vi's a little.

arduino is sending/recieving but the plot in lv is just a flatline. quite unsure why, though the code is very botched so thats probably the problem.

actually i didnt know how to just send FE to the array within the read.vi, and not 2 following trig/echo ports.very simple im sure though.

cheers guys really nice to slowly learn this stuff

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

I think you just helped me fix my code .  It seems that I I did not account for the fact that the value of the pulse read in by Arduino could be larger than 255 (for 4 meters the return value would be 23,200).  So, sending back two bytes should fix it.

If you could test my code as-is and confirm that it works I would much appreciate it.  If it works, I will post it as an official document.  I updated the zip file in the link above.

0 Kudos
Message 7 of 13
(3,690 Views)

ok does do you think this will fix my stuff as well? as far as i can tell the only thing you added was the extra serial.write(retval << 8). is this correct? ill try it when im home in like 2hrs.

still, your .vi makes some activity on the plot, and mine gives none, so something else is wrong. any ideas?

cheers Nathan

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

ok so i tried your code and it works. i got measures over 3.5 meters. unfortunately, there is lots of spiking and drops back to zero, so i still want to use the newping library. can you tell me how the serial write command works with the processcommand function? also what should retVal look like?

0 Kudos
Message 9 of 13
(3,690 Views)

also could you tell me what these lines do and why we need both?

      Serial.write( (retVal & 0xFF) );

          Serial.write( (retVal >> 😎 );     

cheers

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