Hi,
I'm working on a project that includes two Parallax RFID card readers (28140). These readers are at different locations, one on a construction site and one in a warehouse. The idea is that they 'read' incoming and outgoing assets and send them to a processing sketch that does something with it.
The problem is that i can't get the two separate arduinos unos with their RFID readers to connect to one single processing sketch. The arduinos are connected via serial ports to a laptop on which the processing sketch runs.
How ever i don't know how to get this to work...
This is the arduino code I use, I have a similar one for the other arduino and the reader.
// 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 countYellowC = 0;
int countGreenC = 0;
int countRedC = 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) {
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
}
}
}
this is the processing sketch I use:
import processing.serial.*;
Serial arduino1;
Serial arduino2;
void setup(){
String portName1 = Serial.list()[0];
arduino1 = new Serial(this, portName1, 2400);
String portName2 = Serial.list()[1];
arduino2 = new Serial(this, portName2, 2400);
}
void draw() {
if (arduino1.available() > 0) { // If data is available,
val = arduino1.readString();
}
if (arduino2.available() > 0) { // If data is available,
val1 = arduino2.readString();}
print("arduino 1:",val, " ");
println("arduino 2:",val1);
}