I tried using software serial in Arduino Mega using following code to get data from RFID readers.
#include <SoftwareSerial.h>
uint32_t serialNo = 0;
uint32_t serialNo1 = 0;
SoftwareSerial Serial4 (62,63);//A8,A9
SoftwareSerial Serial5 (10,11);
void setup(){
Serial.begin(9600); // start serial to PC
Serial4.begin(9600);
Serial5.begin(9600);
}
void loop(){
if(Serial4.available()>0){
reader1();
}
if(Serial5.available()>0){
reader2();
}
}
void reader1(){
if (Serial4.available() > 3){
serialNo = 0;
for (uint8_t x = 0; x < 4; x++){
serialNo = serialNo << 8;
serialNo = serialNo | Serial4.read();
}
Serial.println(serialNo);
}
}
void reader2(){
if (Serial5.available() > 3){
serialNo1 = 0;
for (uint8_t x = 0; x < 4; x++){
serialNo1 = serialNo1 << 8;
serialNo1 = serialNo1 | Serial5.read();
}
Serial.println(serialNo1);
}
}
when I use both Serial4 and Serial5 to read from two readers only one software serial gives the output(Serial5). When i use them individually both provides outputs. What is the reason. What have i done wrong
}
void reader1(){
if (Serial4.available() > 3){
serialNo = 0;
for (uint8_t x = 0; x < 4; x++){
serialNo = serialNo << 8;
serialNo = serialNo | Serial4.read();
}
Serial.println(serialNo);
}
}
void reader2(){
if (Serial5.available() > 3){
serialNo1 = 0;
for (uint8_t x = 0; x < 4; x++){
serialNo1 = serialNo1 << 8;
serialNo1 = serialNo1 | Serial5.read();
}
Serial.println(serialNo1);
}
}
when I use both Serial4 and Serial5 to read from two readers only one software serial gives the output(Serial5). When i use them individually both provides outputs. What is the reason. What have i done wrong
Hello,
You have already 3 hardware serial, why do you want to use software one?
I reckon you will get much better advice if you give details of the entire project, including what is connected to each of the 6 serial ports. There may be other solutions than having 6 serial ports.
You can get I2C UART modules that would effectively add additional hardware serial ports.