LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Adding custom function on Lifa

Hi all!

I trying to learn how to create my own personal  arduino function (c file) then  invoke them using LIfa. basically i would like to add a custom Vi in the lifa palette. attached is a quick arduine sketch that read contuniously from an analog input then compute a runnig average and print the result. So i will be really greatfull is some could describe to me in step by step how to add a personal function on lifa base on this example, hence in meantine i could add more function base on that. thank very much!!

0 Kudos
Message 1 of 11
(8,037 Views)

To learn how to integrate your own functions within LIFA, you should look through the existing code to see how it's done.  Continuous analog reading is probably one of the more complicated things to add, you can look at the existing implementation of continuous reading (you can't do anything else while it is acquiring).

Message 2 of 11
(4,939 Views)

Thanks Nathan for the reply.  as you suggested i went through the continuous aquisition code on the firmware, based on thati tried to incooporate my code following the same format but i keep having a compilation error.. i am quite sure it's because i'm inserting the code in the wrong place...Please Is there any chance you could modify a simple  existing code or create a new one then   post it here to me , so i will know exactly what i need to change in both arduino code and labview  coze that's where in struggling... any simple example will help me out and from there i should be able to add my smoothing function. Thanks so much

0 Kudos
Message 3 of 11
(4,940 Views)

Helloo Nathan!    

Sorry it's me again. Attached is a custom blink command that enable its user to specify the digital channel onTime, offTime and the numberof Blinking on labview then arduino should return "all doe" when the task is complited. i inserted the code on  a of copy the Lifa base firmware . at the end of the labviewinterface section. But I am still having a compilation error and I build a kind of VI to impliment it Please have look . I badly need some help, since my Suppervisor asked me to write a report on " how too add Custom Command on Lifa"  and the due date is almost reached ahaha.

Thanks Man!

Download All
0 Kudos
Message 4 of 11
(4,940 Views)

Every function implemented in LIFA is an example so me posting one doesn't really add any value to you.  I'm not familiar with the continuous acquisition code (because I've never needed it) so I can't really help you there.

0 Kudos
Message 5 of 11
(4,940 Views)

Regarding the custom blink:

LIFA_Base.ino does not have any modifications in it.  To see if you've done it correctly, I would need the files which were modified (I'm assuming you only modified LabVIEWInterface.ino).  So, if you post this, I can look at it.  However, when you start adding delays into the LIFA architecture, there is potential to break LIFA functionality.  So, how exactly do you want this blinking to work?  If you do it entirely within a LIFA function, it will only turn on and then turn off for every time that you call the function in LabVIEW (i.e. it will not be continuous and will have a delay based on how long the LabVIEW code takes to execute).  To make it a continuous blinking, it will require more involved modifications.

Regarding the LabVIEW-side, It looks like you need to learn some of the LabVIEW basics as well as "how to create a subVI".

0 Kudos
Message 6 of 11
(4,940 Views)

Oh yes  you are right i uploaded the wrong firmware. Attached is my Custom Firmware where i inserted the Blinking Command in the" LabVIEWInterface ", you will need to scroll down to the end to see it.  that's what happen when panic take over... euh what i'm looking forward to with this blinking commandd is  to allow the user to: Blink an LED, by specifying the digital channel, the onTime , the number of blinks during this ontine, the offTime  all of this should correspond to input control on VI,. Such that during the specified ontime the Led will be blinking  then eventually goes off. and finally Arduino will return "All done " when the operation is complete.

Thank you!

0 Kudos
Message 7 of 11
(4,940 Views)

It seems that you haven't taken the time to understand how LIFA works and/or you are not familar with programming in general.  You just added code to the end of the file (and the code seems to just end without being completed).

My best advice when trying to add a new function is to duplicate an existing function (with a new command number) so that you can make sure that you have a working base to start on.  I would, therefore, is to duplicate digital write.  Make sure that you can write to a digital pin with this new function first.  Then, start adding your custom code. 

There are several basic coding mistakes that you have made in the code that you did write.  This is why I generally suggest the above approach and only adding small pieces of code [that will get you closer to where you want to be] at a time with a test immediately after each step.  As for a response coming back to LabVIEW, you simply need to send back a single value like all the other functions do: Serial.write('0').  This is what is used by LIFA to determine if the function has completed execution.

But be warned that your current method has the potential to cause LIFA to timeout but you should be able to account for this by calculating the approximate time your blinking code will take and then adding a little and then using that for your timeout value.  But, remember that during the blinking, no other LabVIEW code, that is dependent on LIFA, will be able to execute.

0 Kudos
Message 8 of 11
(4,940 Views)

Thanks for the reply!! yes indeed i haven't yet fully understand how LIFA works since i only started using it couple weeks ago that's why i was looking for help. Now I think i will just give up on this project coze seems like adding your own command doesn't look to be simple as i though.

0 Kudos
Message 9 of 11
(4,940 Views)

Hey Nathan! i  had  close look through the reply you sent to me and indeed you were right , first i tried to understand how Lifa works as you suggested . then see how the VIs were built. Then i was finally able to add my own command and they work quite easily. Thanks. the only observation i made so far is that regarding some command that i inserted, there were a time delay error in processing them and i had to increase the TIME OUT in the sendreceive Vi if you see what i means. anyway thanks for your help!!

0 Kudos
Message 10 of 11
(4,940 Views)