I am working on a project that requires reading from six ID-12LA RFID readers simultaneously.
I’ve tried setting up readings from six channels through the Sparkfun Analog/Digital MUX Breakout board (CD74HC4067), but without luck. I don’t know if it is capable of serial communication, even though I read that on Bildr.org.
However, I am now trying to emulate reading from multiple serial ports through the SoftwareSerial library. I have read that it is not capable of reading simultaneously, but maybe a loop can simulate simultaneous listening. I have tried to do so by listening to the the first serial, then initializing readTag()
, and then after that function has finished, begin listening to the second serial and then initialize the second function.
The readTag()
function is capable of reading on its own, when only on RFID reader is connected, so that is not the problem.
Below is the code.
What would be the correct way to go about and simulate simultaneous reading through the loop function?
void setup() {
Serial.begin(9600);
ourSerial1.begin(9600);
ourSerial2.begin(9600);
pinMode(RFIDResetPin, OUTPUT);
digitalWrite(RFIDResetPin, HIGH);
}
void loop() {
ourSerial1.listen();
readTag1();
ourSerial2.listen();
readTag2(); // Only this function works right now, because it is the last serial that was initiated in setup.
}
void readTag1() {
char tagString[13];
int index = 0;
boolean reading = false;
while (ourSerial1.available()) {
int readByte = ourSerial1.read();
if (readByte == 2) reading = true; // Beginning of tag
if (readByte == 3) reading = false; // End of tag
if (reading && readByte != 2 && readByte != 10 && readByte != 13) {
//store the tag
tagString[index] = readByte;
index ++;
}
}
checkTag(tagString); // Check if it is a match
clearTag(tagString); // Clear the char of all value
resetReader(); // Reset the RFID reader
}
void readTag2() {
char tagString[13];
int index = 0;
boolean reading = false;
while (ourSerial2.available()) {
int readByte = ourSerial2.read();
if (readByte == 2) reading = true; // Beginning of tag
if (readByte == 3) reading = false; // End of tag
if (reading && readByte != 2 && readByte != 10 && readByte != 13) {
//store the tag
tagString[index] = readByte;
index ++;
}
}
checkTag2(tagString); // Check if it is a match
clearTag(tagString); // Clear the char of all value
resetReader(); // Reset the RFID reader
}