multiple 28140 rfid readers problem with reading

Hi,

I'm working on a program that uses multiple rfid readers at different locations to read rfid tags. I'm running into the problem that i can't get the two readers to work on one arduino mega or on two separate arduino unos. On the mega they work separately but as soon as i put in the 'enable' of the other reader it stops the reading for both of them. Here's my code for the mega, I would really appreciate your help :)

Greetings

Comments

  • 5 Comments sorted by Date Added Votes
  • int  val = 0;
    char code[10];
    int bytesread = 0;
    int i = 0;
    int myNum[10];
    unsigned long int multArray[] = {1, 1, 268435456, 16777216, 1048576,
                                     65536, 4096, 256, 16, 1
                                    };
    unsigned long int trueTag = 0;
    int countYellowW = 0;
    int countGreenW = 0;
    int countRedW = 0;
    int countYellowC = 0;
    int countGreenC = 0;
    int countRedC = 0;
    
    
    void setup() {
      // initialize both serial ports:
      Serial.begin(2400);
      Serial1.begin(2400);
    
      pinMode(2, OUTPUT);                          // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
      digitalWrite(2, LOW);                        // Activate the RFID reader
      pinMode(3, OUTPUT);                          // Set digital pin 3 as OUTPUT to connect it to the RFID /ENABLE pin
      digitalWrite(3, LOW);                        // Activate the RFID
    }
    
    void loop() {
      if (Serial.available() > 0) {                // if data available from reader
        if ((val = Serial.read()) == 10) {         // check for header
          bytesread = 0;
          while (bytesread < 10) {                 // read 10 digit code
            if ( Serial.available() > 0) {
              val = Serial.read();
              if ((val == 10) || (val == 13)) {    // if header or stop bytes before the 10 digit reading
                break;                             // stop reading
              }
              code[bytesread] = val;               // add the digit
              bytesread++;                         // ready to read next digit
            }
          }
          if (bytesread == 10) {                   // if 10 digit read is complete
            code[0] = 48;                          //Zero out the first two elements of the code array
            code[1] = 48;
            //Cycle through the code array and create int elements in myNum
            for (i = 0; i < 10; i++)
            {
              if (code[i] == '0')                  //I am not a programmer, but this is the only way I could
                myNum[i] = 0;
              else if (code[i] == '1')             //find to convert elements of a char array to ints...
                myNum[i] = 1;
              else if (code[i] == '2')
                myNum[i] = 2;
              else if (code[i] == '3')
                myNum[i] = 3;
              else if (code[i] == '4')
                myNum[i] = 4;
              else if (code[i] == '5')
                myNum[i] = 5;
              else if (code[i] == '6')
                myNum[i] = 6;
              else if (code[i] == '7')
                myNum[i] = 7;
              else if (code[i] == '8')
                myNum[i] = 8;
              else if (code[i] == '9')
                myNum[i] = 9;
              else if (code[i] == 'A')
                myNum[i] = 10;
              else if (code[i] == 'B')
                myNum[i] = 11;
              else if (code[i] == 'C')
                myNum[i] = 12;
              else if (code[i] == 'D')
                myNum[i] = 13;
              else if (code[i] == 'E')
                myNum[i] = 14;
              else if (code[i] == 'F')
                myNum[i] = 15;
              else
                myNum[i] = 9999;                       //Oops! an error
            }
            //With trueTag initialized to 0, create the true tag number by summing trueTag with each element of the
            //integer myNum array multiplied by the corresponding element of the multArray.
            for (i = 0; i < 10; i++)
            {
              trueTag = trueTag + (myNum[i] * multArray[i]);
            }
            if (trueTag == 3372093) {
    
              countYellowC++;
              if (countYellowC % 2 == 0) {
                Serial.print(3);
              }
              else {
                Serial.print(2);
              }
            }
            else if (trueTag == 3375172) {
    
              countGreenC++;
              if (countGreenC % 2 == 0) {
                Serial.print(9);
              }
              else {
                Serial.print(8);
              }
            }
            else if (trueTag == 3369475) {
    
              countRedC++;
              if (countRedC % 2 == 0) {
                Serial.print(6);
              }
              else {
                Serial.print(5);
              }
            }
          }
          bytesread = 0;
          trueTag = 0;                                 //Zero out trueTag for next iteration of the loop
          digitalWrite(2, HIGH);                       //deactivate the RFID reader for a moment so it will not flood
          delay(2500);                                 //wait for a bit
          digitalWrite(2, LOW);                        //Activate the RFID reader
        }
      } else if (Serial1.available() > 0) {
        if ((val = Serial1.read()) == 10) {         // check for header
          bytesread = 0;
          while (bytesread < 10) {                 // read 10 digit code
            if ( Serial1.available() > 0) {
              val = Serial1.read();
              if ((val == 10) || (val == 13)) {    // if header or stop bytes before the 10 digit reading
                break;                             // stop reading
              }
              code[bytesread] = val;               // add the digit
              bytesread++;                         // ready to read next digit
            }
          }
          if (bytesread == 10) {                   // if 10 digit read is complete
            code[0] = 48;                          //Zero out the first two elements of the code array
            code[1] = 48;
            //Cycle through the code array and create int elements in myNum
            for (i = 0; i < 10; i++)
            {
              if (code[i] == '0')                  //I am not a programmer, but this is the only way I could
                myNum[i] = 0;
              else if (code[i] == '1')             //find to convert elements of a char array to ints...
                myNum[i] = 1;
              else if (code[i] == '2')
                myNum[i] = 2;
              else if (code[i] == '3')
                myNum[i] = 3;
              else if (code[i] == '4')
                myNum[i] = 4;
              else if (code[i] == '5')
                myNum[i] = 5;
              else if (code[i] == '6')
                myNum[i] = 6;
              else if (code[i] == '7')
                myNum[i] = 7;
              else if (code[i] == '8')
                myNum[i] = 8;
              else if (code[i] == '9')
                myNum[i] = 9;
              else if (code[i] == 'A')
                myNum[i] = 10;
              else if (code[i] == 'B')
                myNum[i] = 11;
              else if (code[i] == 'C')
                myNum[i] = 12;
              else if (code[i] == 'D')
                myNum[i] = 13;
              else if (code[i] == 'E')
                myNum[i] = 14;
              else if (code[i] == 'F')
                myNum[i] = 15;
              else
                myNum[i] = 9999;                       //Oops! an error
            }
            //With trueTag initialized to 0, create the true tag number by summing trueTag with each element of the
            //integer myNum array multiplied by the corresponding element of the multArray.
            for (i = 0; i < 10; i++)
            {
              trueTag = trueTag + (myNum[i] * multArray[i]);
            }
            if (trueTag == 3372093) {
    
              countYellowW++;
              if (countYellowW % 2 == 0) {
                Serial.print(2);
              }
              else {
                Serial.print(1);
              }
            }
            else if (trueTag == 3375172) {
    
              countGreenW++;
              if (countGreenW % 2 == 0) {
                Serial.print(8);
              }
              else {
                Serial.print(7);
              }
            }
            else if (trueTag == 3369475) {
    
              countRedW++;
              if (countRedW % 2 == 0) {
                Serial.print(4);
              }
              else {
                Serial.print(6);
              }
            }
          }
          bytesread = 0;
          trueTag = 0;                                 //Zero out trueTag for next iteration of the loop
          digitalWrite(3, HIGH);                       //deactivate the RFID reader for a moment so it will not flood
          delay(2500);                                 //wait for a bit
          digitalWrite(3, LOW);                        //Activate the RFID reader
        }
      }
    }
    
  • (You might try asking your question on an Arduino forum...)
  • yeah, tried that, but didn't help much yet
  • In the ELSE clause, should you be using

    Serial1.print

    ?
  • i think so, yes, since i want the two rfid readers to send different digits when the same tag is read
Sign In or Register to comment.