03-12-2014 11:20 PM
Hi
I am developing a project and its works perfectly when i use the IDE arduino(discarding problems with the electrical conexion or something like that) but i need to control some variables from labview,
I control 3 relay,pressure and temperature sensors and when I run the program without the charge of the relay it work perfectly (i have transistors to control the relays because the inductance problems in the relays in the arduino) but, when i put the charge to the relay( relays controls 120 AC and 24 DC ) its work a little time(some time seconds and some time hours) and suddenly the arduino stops reciving datas (RX leds stays on and TX continue blinking) and I have tried everything that i know and it doesn't work, I have to rebot labview disconnect and reconect arduino and try again but its the same all time.
i think it would be a communication problem, i have LIFA_base and labview 2011 and arduino mega 2560.
i put the code in the message
if someone could help me, i would be very grateful
03-13-2014 08:00 AM
Just a quick look, couple of points:
1- You may want to simplify your code by creating few sub vis
2-your issue most likely has to do with where you have placed 'close port'
Note that you open two different ports in your true or false case.
Take the open port and close port to very outside of the outer while loop (do you need two loops)
It is hard to say, but what I think is happening is that you get an error inside your main code and you exit the code and close the seial port inside the inner loop an but the oter loop does not open the port fast enough.
03-13-2014 11:18 AM
hello barddya
i tested all your suggestion I put all in SubVi and put the open and close port outside of all and it dosen't work, i continue with the same problem, i've heard that the problem would be the baud rate, in this foro i saw that the baud rate for arduino MEGA 2560 is 9600 but i dont know what its the true value
03-13-2014 11:40 AM
The default baudrate for the Mega 2560 is 9600.
If that doesn't fix your issue, then could you please tell us what error you are receiving and what other issues you are experiencing?
In addition to using subVIs, it is highly recommended that you avoid local variables as much as possible. For example, P1, P2, and Vent can simply be wired to directly. Also, the values for the two nivel values should be wired from the case structure straighg to the Digital Write VIs.
03-13-2014 03:21 PM
This is what I would do
1- create SUb VIs to simplify the main code
2- remove the false case opning and vlosing serial pory is not nuing you any value
3-locate the general area of the faile (after cmverting part os vi to subvi
03-13-2014 04:03 PM
ok, im following your instructions
put all that i can in subVIs
eliminate all local variables
remove the false-true case at the beginning
i turn on the highligh execution and i see that the problem is when the program its doing the sequence ( time after start runinng the program) suddenly it stop in one of the digital write Vi and some time after put in the error line "error 5003" and the program stop because i put a "unbundle by name" to know when start the error.
In another test i going inside the "digital write" Vi and inside " send recive" Vi and inside the "wait for bytes" Vi and i saw that when the error start the property node in the "waits for bytes" vi in the bytes at port label stop to receive "1" and show "0" and the program wait in this loop until finish the time out and the 5003 error appears.
look my new VI im going to update my first Vi
03-13-2014 06:44 PM
Try this version.
with your version, you are still opening and closing the port inside the loop.
03-13-2014 11:11 PM
Pyrata,
You are on the right track with your latest version. It is much better and easier to read. However, your baudrate is still wrong. It must be 9600 for the Arduino Mega 2560.
However, I'm curious as to what frequency you are using in your program. What you are doing is creating a PWM signal with a duty cycle of 37.3%. If the frequency is too high, it won't work correctly trying to regulate timed signals with LabVIEW. I'm curious what you are using these relays to control.
03-14-2014 11:10 PM
Finally found the solution,
I follow all your instruccion barddya and the code works better than before, but now the arduino stop RX and TX blinking , jaja I fix one problem and another begins.
Before of two days of dedication I found that the problem was a GROUNDs problem, in my sketch GROUND of 24 V and 5 V and arduino was together, When I Run the program without the charge of the relays everything work fine, and when I send the digital signals to switch on the relay and the relay switch on the electrovalves (nathan_B at the end im going to explain my project ) the system work for sometimes 20 seconds some time 1 minute the arduino stop the communication BECAUSE the system was sending currents (i dont know why) to the ground of the arduino and this was the problem, the solution was very simple, i put a resistance of 1 K between the GROUND of the circuit and the GROUND of the arduino and it fixed all. I should clarify that a im study mechanical engineering not electronic engineering and i didn't know about this ground problems
nathan_B I'm doing my degree project in mechanical engineering and its about a testing bench(test machine) of hydraulic cylinders seals, i need to test the fatigue of these seals and i design this machine to work with pressures max of 3500 PSI or 250 bar, and i need to activate a hydraulic cylinder with a electrovalve activated by 24VDC solenoids with a determinated frecuency it would be1 or 2 or 3 Hz, its depende of the configuration of the test, and i sense different variables like pressure and temperature and number of cycles ( its the more important variable to determinate the fatigue of this seals) and all those things works with the arduino-labview configuration
I didnt know that i was creating a PWM signal xD i doing this becouse in the hydraulic cylinders the retracting time its less than the extension time and this time depends on constant called B(beta) that related the anular area with the piston area of the cylinder, well and this time affects the cycle of the cylinder (a cycle is determined for the extension and retraction) and the cycle affects de frecuency of the test.
Now I have to improve some aspects like start the sequence only when I switch on a button and I dont know how to do that i have to read more about labview to learn how to do that
Thank you very much for your help Barddya i fixed the labview problems, all thanks to you.
03-15-2014 12:28 AM
Ok, so Beta of the cylinder would dictate the duty cycle (when converted to PWM terminology). If the method you are using is common nomenclature for hydraulic cylinders, I wouldn't worry about thinking of PWM .
In Barddya's code, you should move the "Set Digital Pin Mode" for loop outside of all loops and remove the local variables for "nivel 1", "nivel 2", "Vent", "P1", "P2", and "Frecuencia".
Also, like I said before, your version was doing much better with regards to making some subVIs. However, it is more common to make subVIs for code that is duplicated in your program. For example, the conversion from voltage to temperature or pressure can be done in a subVI and then you would use that subVI each time you want to convert the voltage to an engineering measurement. In the attached subVIs, I've include the Arduino part of the code also.
Before:
After (one of the orange wires is going behind pin 8 accidentally):
As for creating a specific sequence, you may consider using an architecture called the "state machine". NI has a good document describing this architecture and you can probably find a template project called "Simple State Machine".
Let us know if you have any more questions. You can also get help over in the main NI Discussion forums if your problem doesn't specifcally relate to LIFA.