Hi,
I am trying to get 2 software serial inputs to work. One inputs tag data from an rfid reader and the other outputs this data to a serial LCD. I cant use the hardware serial port as this will be used for a uart SD card. For now it used to display tag data for testing.
I realize that i have to close one software serial port before i open another by using the .end() method however this does not seem to be working .
The code i am using is below. It looks like when the LCD port is opened the rfid port does not accept any data from the tag reader. The first reference to the LCD works fine and displays "testing" as it should but the second reference to the LCD displays nothing. If i take out any references to the LCD it works fine although a bit slow when the .end() is used which is a bit odd.
Can anybody see what i have done wrong here.
Any help is much appreciated.
Cheers.
#include <SoftwareSerial.h>
SoftwareSerial rfid = SoftwareSerial(5, 6,true);
SoftwareSerial lcd = SoftwareSerial(2,3);
String tagString = ""; // string to hold input
void setup(){
// setup the software serial pins
pinMode(5, INPUT);
pinMode(2, INPUT);
pinMode(6, OUTPUT);
pinMode(3, OUTPUT);
Serial.begin(9600); // Hardware serial for Monitor 9600bps
Serial.println("Tag reader");
lcd.begin(9600); //open lcd port
lcd.write(12);
lcd.print("testing");
lcd.end(); //close the port
delay(1000);
}
void loop() {
rfid.begin(38400); //open the reader port at 38400 baud
while (rfid.available() > 0) {
char inByte = rfid.read();
if (inByte == 'L') {
while(true) {
inByte = rfid.read();
tagString += inByte;
if (inByte == '\n') {
rfid.flush(); //flush the input buffer
rfid.end(); //close the reader port
lcd.begin(9600); //open lcd port again to display the tag string
lcd.write(12); //cls
lcd.print(tagString);
lcd.end(); //close teh port
rfid.begin(38400); //open the rfid port
tagString = "";
break;
}
}
}
}
rfid.end();
}