RFID scanners to processing HELP

Hello,

Im trying to make a RFID scanner with two scanners. (Paralax RFID reader 28140). Unfortunatly it is not working. Im having the problem that processing isn't receiving both serials if I use two separate arduinos. I read somewhere that it is not possible to read from two different serials the values in processing.

Because of that, I tried the arduino MEGA 2560. This board should be capable of having to RFID scanners connected to it. The only problem we have is that I can't write a proper sketch. I will post the sketch in the attachments

Please can you tell me what is wrong?

Processing_sketch.pde (574 Bytes)

rfid_reader.ino.ino.ino (4.75 KB)

You have another post here. Posting in more than one forum is "cross posting" and cross posting is discouraged.

my apologies, i wasn't sure which topic to use... :confused:

If you post and decide that the post is in the wrong place, you can ask the Moderator to move it.

How are the 2 Arduino ports connected to the PC? Does each have a TTL to USB converter connected to separate PC USB ports?

Okay next time I will ask a moderator :slight_smile:
The two arduinos are connected to separate ports with a USB Cable..

Greetings

"If you post and decide that the post is in the wrong place, you can ask the Moderator to move it.

How are the 2 Arduino ports connected to the PC? Does each have a TTL to USB converter connected to separate PC USB ports?"

I don't know why you couldn't have 2 Arduinos talking to 2 different serial instances in Processing. I'll try it and see. Be back in a bit.

I have 2 Unos connected to my PC with a Processing sketch watching 2 serial ports. I created 2 serial ports in Processing and each Uno talks to its port. Works just fine printing to the console. So two (or more?) ports are possible.

Same code on each Uno with alternate print lines commented.

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  //Serial.println("arduino 111"); // uncomment for first arduino
  Serial.println("arduino 222222"); // comment for first arduino
  delay(1000);
}

Processing code

import processing.serial.*;

Serial ard1;  
String val1;      

Serial ard2;  
String val2;  

void setup() 
{
  size(200, 200);
// I specify the ports cause I don't like list[] and 
// I know what ports the arduino are connected
  ard1 = new Serial(this, "COM5", 115200);
  ard2 = new Serial(this, "COM8", 115200);
}

void draw()
{
  if ( ard1.available() > 0) 
  {  
    val1 = ard1.readString(); 
    print(val1);
  }
  
   if ( ard2.available() > 0) 
  {  
    val2 = ard2.readString(); 
    print(val2);
  }
}

Hi,

First of all, I really appreciate your help.
I tested your codes and indeed, you are right. Processing can read it from both USB ports. However, when I plug in the arduino unos with the RFID codes, processing is not able to read anything anymore. When I unplug one of the arduinos it starts working again. Processing doesn't give me an error or what so ever. I will include the RFID code I used. This is the same on both of the arduinos.

Greetings.

// RFID reader for Arduino
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// Modified for Arduino by djmatic
// Modified 1-12-2015 to produce the correct tag number by M. Robertson

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;

void setup() {
  Serial.begin(2400);                          // RFID reader SOUT pin connected to Serial RX pin at 2400bps
  pinMode(2, OUTPUT);                          // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
  digitalWrite(2, LOW);                        // Activate the RFID reader
}

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) {

          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(5);
          }
          else {
            Serial.print(6);
          }
        }
      }
      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
    }
  }
}

On each of the Unos, in the tools, ports menu, are they for sure running different serial ports? Are the ports assigned by different instance of the IDE (both IDEs opened on their own, not through File, New)?

Yes they are on two different ports ( in my case 11 and 12), but they are both running almost the same file. Still not working. Might it something be with interference?

greetings

Hey,

I am also thinking about using arduino Mega, what code should I use then?
I was thinking about a code like this.. but then I am getting an error on:

pinMode(3,OUTPUT);
digitalWrite(3,LOW);

when I have these lines not commented the code doesn't work. Here is the same problem, I can't get two of them active at the same time..

/*
  

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
    }
  }
}

Can someone have a look at it?

Greetings