LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Software Serial with LVIFA

Hi,

I've recently become aware of LVIFA and figured that since I already know some labview it's a great way to bring data onto a PC and start playing with it properly as a start to finish project.

I've got an RFID reader which with an Arduino sketch can push the value of a card across serial and I want to recreate this in Labview reading the value into the program. So starting simple the program would request the card value from the RFID reader and display it (anything after that in Labview is fairly easy). The RFID reader is plugged into the arduino and communicated through software serial.

I have a Duemilanove which only has one hardware serial which is used to send the data back to the PC software serial must be used, the following sketch works:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);

char txrxbuffer[255];

char get_readID[] = { 0xAA , 0x00, 0x03, 0x25, 0x26, 0x00, 0x00, 0xBB };

void setup()

{

  Serial.begin(57600);

  Serial.println("Hit Enter to read the RFID number");

  mySerial.begin(9600);

}

void loop() // run over and over

{

  int counter = 0;

  if (mySerial.available())

    Serial.print(mySerial.read(),HEX);

  if (Serial.available()){

      Serial.read();

      Serial.println(">");

      for (counter =0 ; counter < 8 ; counter++){

        mySerial.write(get_readID[counter]);

      }

  }

}

I can't find a Software Serial feature in the tool kit so I belive I have to add it to the sketch I upload to the Arduino to communicate but I'm not exactly sure how to go about doing that. I suppose I'll also need to write a new "SoftwareSerial" VI too?

Has anyone got an example of this which I can work with or advice on how to go about it?

There are other functions supported by the device so it would be preferable to allow various commands to be sent via this software serial link rather than it being hard programmed in the sketch.

0 Kudos
Message 1 of 6
(6,031 Views)

You would need to create a custom command in the command structure you see in the LIFA firmware.  The first step that I would recommend is to essentially duplicate a labview function and create your own VI for it. 

Then, after you know that it works, you can add your software serial code in there.  You would need to create the software serial object at the begining of the firmware like you do it when not using LIFA.  Then, you would just need to make your custom function send your serial command via software serial and have a while loop waiting for it to respone.  When you get a response, you send it back over the hardware serial back to labview.

FYI, the Arduino Mega 2560 has 4 hardware serial interfaces.

0 Kudos
Message 2 of 6
(3,903 Views)

i know its an old post, but i was wondering the same thing about the serial interfaces, do you have an example of the hardware serials on the Mega2560 ? because i cant seem to get it working ? tried a few combos in the LIFA Base but still no success.

0 Kudos
Message 3 of 6
(3,903 Views)

I've not personally done this as I've not had anything that I've needed it (or able to test with).  Maybe you mistakenly refered to LIFA_Base.ino but I'll clarify that the code implementation needs to be in the command structure of LIFA (as a case in the switch statement in LabVIEWInterface.ino).

If you have done this (added a command into the LIFA command structure) then you should post the code and explain what was the last part that you had working (while testing your implementation of a new function) so we know how far along the process you are currently at.

Message 4 of 6
(3,903 Views)

I see i think i got mistaken on the Base and Interface, i will try it out as soon as i get my new parts. and then ill look back here and post my code and some more information.

0 Kudos
Message 5 of 6
(3,903 Views)

Nathan, can u tell me what the command[] in lvifa does ? and where i can see em ? cause im having a hard time inserting a new case.

For now i got so far and everything is compiling and i got it transfered to the arduino:

//RFID Variables

//-------------------------------------

  byte valRfid = 0;

  byte i = 0;

  byte codeTag[6];

  byte checksum = 0;

  byte tempbyte = 0;

//-------------------------------------

/*********************************************************************************

** NEW COMMAND(RFID)

*********************************************************************************/     

      case 0x35:  // RFID Packet

      if (Serial3.available() > 0) {

        if((valRfid = Serial3.read()) == 2) {        // check for header

          incommingByte = Serial3.read();

          while (incommingByte < 12) {               // read 10 digit code + 2 digit checksum

            if( Serial3.available() > 0) {

          valRfid = Serial3.read();

          if((valRfid == 0x0D)||(valRfid == 0x0A)||(valRfid == 0x03)||(valRfid == 0x02)) { // if header or stop bytes before the 10 digit reading

            break;                                    // stop reading

          }

          // Do Ascii/Hex conversion:

          if ((valRfid >= '0') && (valRfid <= '9')) {

            valRfid = valRfid - '0';

          } else if ((valRfid >= 'A') && (valRfid <= 'F')) {

            valRfid = 10 + valRfid - 'A';

          }

           // Every two hex-digits, add byte to code:

          if (incommingByte & 1 == 1) {

            // make some space for this hex-digit by

            // shifting the previous hex-digit with 4 bits to the left:

            codeTag[incommingByte >> 1] = (valRfid | (tempbyte << 4));

            if (incommingByte >> 1 != 5) {                // If we're at the checksum byte,

              checksum ^= codeTag[incommingByte >> 1];       // Calculate the checksum... (XOR)

            };

          } else {

            tempbyte = valRfid;                           // Store the first hex digit first...

          };

          incommingByte++;                                // ready to read next digit

        }

      }

     // Output to Serial:

      if (incommingByte == 12) {                          // if 12 digit read is complete

        Serial.print("5-byte code: ");

        for (i=0; i<5; i++) {

          if (codeTag < 16) Serial.print("0");

          Serial.print(codeTag, HEX);

          Serial.print(" ");

        }

        Serial.println();

        Serial.print("Checksum: ");

        Serial.print(codeTag[5], HEX);

        Serial.println(codeTag[5] == checksum ? " -- passed." : " -- error.");

        Serial.println();

        }

      incommingByte = 0;

        }

      }

       break;

Right after the IR Case (expanding the case structure)

and i made an edit in syncLV:

void syncLV()

{

  Serial.begin(DEFAULTBAUDRATE);

  Serial3.begin(DEFAULTBAUDRATE);

  i2cReadTimeouts = 0;

  spiBytesSent = 0;

  spiBytesToSend = 0;

  Serial3.flush();

  Serial.flush();

}

Plus in unknown packet

    /*********************************************************************************

    ** Unknown Packet

    *********************************************************************************/

    default:      // Default Case

      Serial.flush();

      Serial3.flush();

      break;    

    }

  }

  else{ 

    // Checksum Failed, Flush Serial Buffer

    Serial.flush();

    Serial3.flush();

  }  

So anything i should consider or anything i can do in my firmware, and what can i do in labview to read it ?

The devices im using is an Arduino Mega 2560 and an ID12/20 RFID Reader. (i want the reader to be on serial3).

i attached my LabVIEWInterface.ino if the you wanna check and see if i did it correctly.

- Thomas R.

0 Kudos
Message 6 of 6
(3,903 Views)