10-21-2018 06:28 PM
Hello,
I am sending and receiving data through LoRa technology, that I have stacked a LoRa shield on an Arduino UNO.
Recently, I am trying to create an interface with Labview, to enable me to control the Arduino with LabView.
The problem is that I do not know how can I create a Labview code to enable the Arduino-LoRa device to communicate through Labview interface.
I have added the Arduino code as if it might help to figure out what is happening.
Thanks
/* LoRa Simple Arduino Server : Support Devices: * LoRa Mini * LoRa Shield + Arduino; * LoRa GPS Shield + Arduino. Example sketch showing how to create a simple messageing server, with the RH_RF95 class. RH_RF95 class does not provide for addressing or reliability, so you should only use RH_RF95 if you do not need the higher level messaging abilities. It is designed to work with the other example LoRa Simple Client modified 16 11 2016 by Edwin Chen <support@dragino.com> Dragino Technology Co., Limited */ #include <SPI.h> #include <RH_RF95.h> # include <Wire.h> #include <LiquidCrystal_I2C.h> # include <LCD.h> LiquidCrystal_I2C lcd (0x27,2,1,0,4,5,6,7,3,POSITIVE); // Singleton instance of the radio driver RH_RF95 rf95; int led = 7; int button=3; int buttonstate=1; float frequency = 930.0; void setup() { Serial.begin(9600); while (!Serial) ; // Wait for serial port to be available Serial.println("Start Sketch"); if (!rf95.init()) Serial.println("init failed"); // Setup ISM frequency rf95.setFrequency(frequency); // Setup Power,dBm rf95.setTxPower(13); // Defaults BW Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on Serial.print("Listening on frequency: "); Serial.println(frequency); pinMode (button, INPUT_PULLUP); pinMode(led, OUTPUT); lcd.begin (24,4); // LCD starting words lcd.setCursor (0,0); lcd.print(" Hello "); lcd.setCursor (1,1); lcd.print("This is Server "); delay (5000); // Working Channel lcd.clear (); lcd.setCursor (0,0); lcd.print(" Operating code "); lcd.setCursor (1,1); lcd.print("channel: 2"); delay (5000); // LCD setup \\ lcd.clear (); lcd.setCursor (0,0); lcd.print(" Waiting for "); lcd.setCursor (0,1); lcd.print(" the client "); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Loop %%%%%%%%%%%%%%%%%%%%%%%%%%%% void loop() { int buttonstate=1; if (rf95.available()) { Serial.print("rf "); // Should be a message for us now uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]; uint8_t len = sizeof(buf); if (rf95.recv(buf, &len)) { RH_RF95::printBuffer("request: ", buf, len); Serial.print("got request: "); Serial.println((char*)buf); Serial.print("RSSI: "); Serial.println(rf95.lastRssi(), DEC); lcd.clear (); lcd.setCursor (0,0); lcd.print ("Red LED is on"); lcd.setCursor (0,1); lcd.print ("Push the butoon"); //while (digitalRead (button)==HIGH){ // buttonstate=digitalRead (button); //} lcd.clear (); // Send a reply uint8_t data[] = "And hello back to you"; rf95.send(data, sizeof(data)); rf95.waitPacketSent(); Serial.println("Sent a reply"); digitalWrite(led, LOW); lcd.clear (); lcd.setCursor (0,0); lcd.print ("Blue LED is on"); lcd.setCursor (0,1); lcd.print ("Reply is sent"); } else { Serial.println("recv failed"); } } }
10-22-2018 07:02 PM
Hi Saeed1994,
I've seen LINX be used to communicate with Arduino. I would give that toolkit a try. Here is an article about controlling an Arduino from LabVIEW.
David F.
Applications Engineering
National Instruments
10-23-2018 12:22 PM - edited 10-23-2018 12:28 PM
Well I don't think there is any LINX vi's that directly control LoRa shields... But you can add a custom command to LINX
That being said, I think it would be easier to just write your Arduino Sketch in native Arduino code using the LoRa libraries that are available and also program the Arduino to respond to commands sent over the serial port to turn the LoRa on and off.
Using LabVIEW to control an Arduino like this is no different than controlling any other instrument on a serial port. In fact is is easier because since you are programming the Arduino you get to decide how the LoRa on/off command and Arduino response is formatted.
Forget about LabVIEW and get it working through the Arduino serial monitor first.
Then write a LabVIEW program that does what you were doing through the serial monitor by pressing a button or something instead of typing a command into the serial monitor