10-09-2013 03:32 PM
Hello all!
I'm using an Arduino Mega 2560 to control a garden irrigation system. I have connected the following modules on it:
DHT11 (temperature + humidity sensor) connected to Digital Pin 2
Soil Moisure sensor connected to analog pin A0
2 Relay Module conected to digital pins 8 and 9
HC-SR04 Ultrasonic Sensor (measures distance) connected to digital pins 12 (trigger) and 11 (echo)
I need a simple GUI to show each of these modules reading values. There will be no input from this program to the arduino, everything is controlled by the arduino itself.
For DHT11, Soil sensor and distance sensor, I only need to read from arduino and print the values. For the relays just print whether it is on or off.
So far I configured LabVIEW with arduino tool kit and also added labview libraries to my arduino program. But I'm having a hard time trying to develop my labview project.
Can someone give me a hand?
Thanks in advance!!
10-09-2013 08:09 PM
It sounds like you are trying to do more than one thing on the Arduino simultaneously. You generally can't do this. You would need to either implement everything in LabVIEW with LIFA or you would need to create custom functions in LIFA that read these sensors directly.
The other alternative, since you already have it implemented would be to simply use LabVIEW as a "Serial reader" and display the values when they are available.
Maybe if you post your original code (without LIFA) and then your code with LIFA so that we can see what you are trying to do and what you have done.
10-10-2013 03:54 PM
Hi Nathan, thanks for your prompt response.
I guess your second option is what I'm looking for on this GUI.
This is an irrigation system for a backyard garden, so everything should be controlled by the arduino. I included a Bluetooth module so I can access the arduino information through a computer a few meters away from this garden.
That is why I want a GUI to show me the conditions of the garden irrigation system in a friendly interface.
I will add my code here, but first I need to let you know that I could not make LabView comunicate with my arduino just importing the LIFA library on the IDE 'Import Library..' option. Seems it only works when I open LIFA_Base along with all other files. This way I had to input my code directly on LIFA_Base file. So, I'm pasting here my original code and my Code inserted inside LIFA_Base code.
Original |
---|
#include <dht11.h> NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); void setup() { Serial.begin(57600); void loop() { uS = sonar.ping(); while ((uS / US_ROUNDTRIP_CM) > 10) { valorsensor = analogRead(0); Serial.print("Water level: "); int chk = sensor.read(2); |
With LIFA |
---|
#include <Wire.h> #define TRIGGER_PIN 12
void setup() { Serial.begin(57600);
checkForCommand(); while ((uS / US_ROUNDTRIP_CM) > 10) { valorsensor = analogRead(0); Serial.print("Water level: "); int chk = sensor.read(2); Serial.print("Humidity (%): "); Serial.println("Water level too low!!");
} |
10-10-2013 09:58 PM
Yeah, so, one thing about LIFA is that it is a whole infrastructure. It uses a serial protocol that requires it to know everything that is being sent over the serial line. So, you can't send any communication over serial when using LIFA unless it is integrated into the architecture of LIFA. That is why it will not work by simply pasting the code into LIFA_Base.ino.
10-11-2013 07:30 AM
Hi Nathan,
Yes, that was what I meant, I added my original code in the LIFA_Base and opened it along with all the other files. This way I manage to correctly communicate LabView and Arduino That is how it looks:
Base on that and looking at my original code, do you think it is possible to simple read and print all sensor values on a LabView interface?
Thanks!
Diego
10-11-2013 10:03 AM
Like I said before, if you just want to read and display values with LabVIEW then you can simply build a serial monitor that parses the data.
If you actually want to be able to control things from LabVIEW, you will need to integrate each sensor into the framework of LIFA by adding a custom function for each of the functions/sensors that are not already implemented in LIFA. This involves adding a function to the LIFA firmware and a corresponding VI in LabVIEW to access that function.
10-11-2013 04:49 PM
Huumm.. Got it!!
I will try to build my LabView program as a serial monitor then, since it suffices my needs. I'll search for examples here on the forum. If you have any good example by hand please share with me. I'm still a begginer with LabView so examples help a lot
10-16-2013 07:26 PM
I'm stuck trying to insert my code inside LIFA_Base.
I already put my code inside LIFA_Base and kept all other files as they were, as I pasted before:
Only LIFA_Base was changed. This is the code:
Arduino Code inside LIFA_Base |
---|
/*********************************************************************************
/********************************************************************************* void setup()
checkForCommand(); while ((uS / US_ROUNDTRIP_CM) > 10) { //checa se o valor do nível do tanque é maior que 10cm. Caso esteja acima segue com as demais funções valorsensor = analogRead(0); // lê o valor em A0 e atribui à variável Serial.print("Nivel no tanque: "); int chk = sensor.read(2); //atribui a variável chk o valor lido pelo sensor de temperatura no pino 2 int i = 1; digitalWrite(8, HIGH); //ativa o relay da valvula de fertilização i = 1; digitalWrite(8, LOW); //desativa o relay da valvula de fertilização i = 1; digitalWrite(9, LOW); if(acqMode==1) } |
Now, the problem. Whenever I upload this code I get no errors. But when it starts, the Ultrasonic distance module (HC-SR04) keeps sending 0cm doesnt matter the real distance.
If I upload the same code out of LIFA structure It runs normally and distance is correctly read from the sensor.
I guess I need to change some other file from LIFA structure other than LIFA_Base, but I could not find how to do that.
Can someone help me?
10-16-2013 09:27 PM
When implementing new things into LIFA you cannot start printing in to serial in the loop(). LIFA is based on a framework and anything added to it must also be within that framework. Adding serial prints anywhere outside of this framework prevents LIFA from running correctly.
The first step to adding functions to LIFA is duplicating an existing function like digital read or analog read. So, you duplicate one of these functions first with a new command index and likewise on the LabVIEW side and test it to make sure it works (meaning that you duplicated it correctly).
Then, once that is working, you can modify it to add your functionality. 99% of all the changes I make to LIFA are in LabVIEWInterface.ino which is where you will see the LIFA framework. It's rare to need to modify LIFA_Base.
Moral of the story is that copy pasting code is not possible with LIFA. So, try and duplicate a function and if that works, modify it to add some of your custom code.
10-20-2013 03:32 PM
Nathan,
I tried here, but don't know how to do that. In fact I thought I could include my code inside LIFA_Base or LabVIEWinterface in a way both the custom code and LIFA structure could work in parallel. Since I cannot upload two codes, if I cannot run my code and LIFA together, then there is no way to make this interface using LabView
I'm a bit frustrated about that since I understand that LIFA should interact with arduino without preventing it from running instructions by its own, in other words, I guess several project ideas would need to be able to run controlling instructions and talk to LabView at the same time.
No one ever get success on that?