Want to read two serial ports on demand


i working rfid reader. want read values when card pass on reader. 1 reader works @ 1 time. because other serial port not initialized. use port.listen() function didn't me because time read data , time not. code given below suggest me have do. board uno.

code: [select]
#include <softwareserial.h>
softwareserial rfid(8, 9); // rx , tx
softwareserial rfidd(2, 3); // rx , tx

int data1;
int data2;
int data3;
int ok = -1;
int in = 13;
int out = 12;
int i;
byte byteread;

void setup()
{
  serial.begin(2400);  // start serial pc
  while (!serial) {
    ; // wait serial port connect. needed leonardo only
  }
 
   rfid.begin(2400);
   rfidd.begin(2400);
   // start serial rfid reader

  pinmode(in, output); // status leds
  pinmode(out, output);
}

void readvalues() {
  rfid.listen();
     if (rfid.available()>0)
  {
      delay(400);
   for (int z = 0 ; z < 14 ; z++) // read rest of tag
  {
      data2 = rfid.read();
      serial.print(data2);
   }
      rfid.flush(); // stops multiple reads

     //serial.print(" ");
 
  }
  rfidd.listen();
  if (rfidd.available()>0) {
      delay(400);
    (int z = 0 ; z < 14 ; z++) // read rest of tag
    {
      data1 = rfidd.read();
      serial.print(data1);
    }
      rfidd.flush(); // stops multiple reads

     //serial.print(" ");
 
  }

}

void loop()
{
   
  readvalues();
 
  if (serial.available()) {
  byteread = serial.read();
 
  //listen numbers between 0-9
     if(byteread  == 49){
          //number found
      digitalwrite(in, high);
      delay(1000);
      digitalwrite(in, low);
     
     
    }else if(byteread == 48){
            //number found
      digitalwrite(out, high);
      delay(1000);
      digitalwrite(out, low);
    }
  }
}

quote
serial.begin(2400);  // start serial pc
why slow? bump 115200, better.

quote
but 1 reader works @ 1 time.
of course, arduino cannot multi-thread, can things 1 after other. can give appearance of multi-threading switching between fast, , instead of using loops cycle through , collect data, should use if statements , keep track of individual counts.


Arduino Forum > Using Arduino > Project Guidance > Want to read two serial ports on demand


arduino

Comments

Popular posts from this blog

Authentication error while password reset - Raspberry Pi Forums

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums