Yun and RFID

Hi all.

I am using a Yun board and an RDM6300 with the following code but I don’t get any readings from it. The code works fine in an Uno, but in Yun I can’t get any response when a tag is attached to the reader.
It looks like the rfidReader.available() command in loop() does not execute?
Any suggestions welcome! Thanks a lot

#include <SoftwareSerial.h>
#include <avr/pgmspace.h>
//----
// Tags are stored in program flash memory
// 32k minus sketch size determines the amount of tags that can be stored
// Tags include the two CRC bytes (14 bytes total)
prog_char tag_0[] PROGMEM = "000000000000"; //add your tags here
prog_char tag_1[] PROGMEM = "000000000000";
prog_char tag_2[] PROGMEM = "000000000000";
prog_char tag_3[] PROGMEM = "000000000000";
prog_char tag_4[] PROGMEM = "000000000000";
prog_char tag_5[] PROGMEM = "000000000000";
prog_char tag_6[] PROGMEM = "000000000000";

PROGMEM const char *tag_table[] = {   
  tag_0,
  tag_1,
  tag_2,
  tag_3,
  tag_4,
  tag_5,
  tag_6 };
//----

SoftwareSerial rfidReader(0,1);
String tagString;
char tagNumber[14];
boolean receivedTag;

void setup() {
  Serial.begin(9600);
  while (!Serial) ;
  rfidReader.begin(9600); // the RDM6300 runs at 9600bps
  Serial.println("RFID Reader...ready!");
}

void loop() {
  receivedTag=false;
  while (rfidReader.available()){
    Serial.println("rfid available");
    int BytesRead = rfidReader.readBytesUntil(3, tagNumber, 15);//EOT (3) is the last character in tag 
    receivedTag=true;
  }  
 
  if (receivedTag){
    tagString=tagNumber;
    Serial.println();
    Serial.print("Tag Number: ");
    Serial.println(tagString);
    
    if (checkTag(tagString)){
      Serial.print("Tag Authorized...");
    }
    else{
      Serial.print("Unauthorized Tag: ");
      Serial.println(tagString);
      delay(1500); // a delay of 1500ms and a flush() seems to stop tag repeats
      rfidReader.flush();
    }
    memset(tagNumber,0,sizeof(tagNumber)); //erase tagNumber
  }   
}

// ----
// checkTag function (give it the tag string complete with SOT and EOT)
// compares with tags in tag_table
// and returns true if the tag is in the list

 boolean checkTag(String tag){
   char testTag[14];
   for (int i = 0; i < sizeof(tag_table)/2; i++) {
    strcpy_P(testTag, (char*)pgm_read_word(&(tag_table[i])));
    if(tag.substring(1,13)==testTag){//substring function removes SOT and EOT
      return true;
      break;
    }
  }
   return false;
 }
 //----
SoftwareSerial rfidReader(0,1);

Idiot. You can't do SoftwareSerial on the hardware serial pins at the same time you are doing hardware serial on the hardware serial pins, regardless of what board you are using.

Bullying? Why?

louisbourdon: Bullying? Why?

Who's bullying? What were you thinking when you wrote that code?

What are you thinking people are going to respond with when you are replying with these adjectives? If you are supposed to patronize and terrify people what is the point of you being in a forum where people are asking questions to learn something they don't know of?

Anyway, thanks for the help but I don't think it worths the insult. I'll wait when someone else contributes another response, and if not that's alright. No harm done, right?

So here is my updated code, which works as I changed my RX TX pins to 8 and 9 instead of 0 and 1.

What frustrates me the most is that this kind of behavior does not allow me to understand the problem and accumulate knowledge, instead of just having a bad forum experience! Good job man!

#include <SoftwareSerial.h>
#include <avr/pgmspace.h>

#define RxPin 8 //Pin to read data 
#define TxPin 9 //Pin to write data 

//----
// Tags are stored in program flash memory
// 32k minus sketch size determines the amount of tags that can be stored
// Tags include the two CRC bytes (14 bytes total)
prog_char tag_0[] PROGMEM = "000000000000"; //add your tags here
prog_char tag_1[] PROGMEM = "000000000000";
prog_char tag_2[] PROGMEM = "000000000000";
prog_char tag_3[] PROGMEM = "000000000000";
prog_char tag_4[] PROGMEM = "000000000000";
prog_char tag_5[] PROGMEM = "000000000000";
prog_char tag_6[] PROGMEM = "000000000000";

PROGMEM const char *tag_table[] = {   
  tag_0,
  tag_1,
  tag_2,
  tag_3,
  tag_4,
  tag_5,
  tag_6 };
//----

SoftwareSerial rfidReader(RxPin, TxPin);
String tagString;
char tagNumber[14];
boolean receivedTag;

void setup() {
  Serial.begin(9600);
  while (!Serial) ;
  rfidReader.begin(9600); // the RDM6300 runs at 9600bps
  Serial.println("RFID Reader...ready!");
}

void loop() {
  receivedTag=false;
  while (rfidReader.available()){
    Serial.println("rfid available");
    int BytesRead = rfidReader.readBytesUntil(3, tagNumber, 15);//EOT (3) is the last character in tag 
    receivedTag=true;
  }  
 
  if (receivedTag){
    tagString=tagNumber;
    Serial.println();
    Serial.print("Tag Number: ");
    Serial.println(tagString);
    
    if (checkTag(tagString)){
      Serial.print("Tag Authorized...");
    }
    else{
      Serial.print("Unauthorized Tag: ");
      Serial.println(tagString);
      delay(1500); // a delay of 1500ms and a flush() seems to stop tag repeats
      rfidReader.flush();
    }
    memset(tagNumber,0,sizeof(tagNumber)); //erase tagNumber
  }   
}

// ----
// checkTag function (give it the tag string complete with SOT and EOT)
// compares with tags in tag_table
// and returns true if the tag is in the list

 boolean checkTag(String tag){
   char testTag[14];
   for (int i = 0; i < sizeof(tag_table)/2; i++) {
    strcpy_P(testTag, (char*)pgm_read_word(&(tag_table[i])));
    if(tag.substring(1,13)==testTag){//substring function removes SOT and EOT
      return true;
      break;
    }
  }
   return false;
 }
 //----

... does not allow me to understand the problem and accumulate knowledge, instead of just having a bad forum experience!

Sorry for having a bad experience,

Except for the I-word, PaulS explained correctly that the pins 0 and 1 are used for the Hardware Serial. To use them for Software Serial means you need to disable Hardware Serial which is not trivial (AFAIK). This has to do with interrupts that put received bits in the buffers etc. If two Serial objects both trigger on an arriving bit one gets problems. The solution you implemented to choose other pins is a good one.

Are there other things you want to have explained?

Thank you very much for your reply.
It makes sense for sure!