3 serial ports on the arduino

hello. need on my Aduino a three serial ports, with a library I found I can work with the normal port Arduino board and a serial port but I need one more serial communication , someone who can help me.

option 1 = use a MEGA it has 4 HW serial ports => higher speeds & throughput possible

option 2 = use newSoftSerial library => for lower speeds & thoughput this works quite well

The SoftSerial library http://arduino.cc/en/Reference/SoftwareSerial will allow you to use 3 serial ports, albeit with some restrictions. Which Arduino do you have ?

I'm working with the Arduino ethernet, I'm using the library but I have problems with the serial port before and does not recognize the device connected to that port.

I'm working with the Arduino ethernet

Your initial question was only about serial, so what does the ethernet do with the serial?

does not recognize the device connected to that port.

what kind of devices do you connect?
what are the baud rates they use?
how much bandwidth do the need per second?

The more you tell the better answers you get.
Maybe tell about the whole project?

EJTR:
I'm working with the Arduino ethernet, I'm using the library but I have problems with the serial port before and does not recognize the device connected to that port.

What doesn't recognize the device? What device?

option 3 - add a dual UART with SPI/I2C interface
Way less expensive than stepping up to a 2560 processor.
http://www.digikey.com/product-search/en?pv16=13036&FV=fff40027%2Cfff801b5&k=SC16IS752&mnonly=0&newproducts=0&ColumnSort=0&page=1&stock=1&quantity=0&ptm=0&fid=0&pageSize=25

SC16IS752_SC16IS762.pdf (477 KB)

EJTR:
I'm working with the Arduino ethernet,

That's the Arduino Ethernet board, right? (Just to clear up some of the confusion of the posters above...) And you are trying to use it with multiple serial ports as if this is an UNO board ignoring for now the integrated ethernet, right?

I'm using the library but I have problems with the serial port before and does not recognize the device connected to that port.

Not quite sure exactly what you are trying to say. Could you provide your source code that doesn't work, with a description of both what you want to happen and what actually happens. (Try to avoid adjectives and pronouns. It may feel a bit clumsier, but explicitly giving the name/function of each device every time you reference each device should help those of us who haven't been mired in your problem know which device is which. Who knows, some times just the act of writing something out in excruciating detail helps you understand your own error.)

Just to save you some grief, make sure you read the stickies at the top of this forum and use the approved method of posting code, i.e. using the [``code] and [``/code] tags around the source code. Also accessed by clicking the # button above the line of smilies.

That’s the Arduino Ethernet board, right? (Just to clear up some of the confusion of the posters above…) And you are trying to use it with multiple serial ports as if this is an UNO board ignoring for now the integrated ethernet, right?

that is correct.

need to use three serial ports attached the code to have a project reference

#include <SoftwareSerial.h>
/********************/
SoftwareSerial rfidSerial(2,3); // rx-tx 
int RFIDResetPin = 7;
char tag1[13] = "27008B1D9657";
/********************/
SoftwareSerial comSerial(18,19); // rx-tx
/********************/
int llaveout = 6;
int estadollave = 0;
/********************/

void setup()
{
/**********************************/
  pinMode(RFIDResetPin, OUTPUT);
  digitalWrite(RFIDResetPin, HIGH);
/**********************************/
  pinMode(llaveout, OUTPUT);
  digitalWrite(llaveout, LOW);
/**********************************/ 
  Serial.begin(9600);           //conectado a un modulo gsm,se envia comandos AT
  rfidSerial.begin(9600);      // lector rfid ID-20 para autenticacion del personal
  comSerial.begin(9600);     //conectado a la pc de la estacion
/**********************************/ 
}

void loop()
{
  tarjetarfid();
  delay(200);
  leercomSerial();
}

void leercomSerial()
{
  if (comSerial.available())
  {
    char cad = comSerial.read();
    switch ( cad )
    {
      case 'A':
      comSerial.println("MONITOREO DE ESTACION SUR");
      break;
    }
  }
}

void tarjetarfid()
{
  char tagString[13];
  int index = 0;
  boolean reading = false;
  while(rfidSerial.available())
  {
    int readByte = rfidSerial.read(); 
    if(readByte == 2) reading = true; 
    if(readByte == 3) reading = false; 
    if(reading && readByte != 2 && readByte != 10 && readByte != 13)
    {
      tagString[index] = readByte;
      index ++;
    }
  }
  checkTag(tagString); 
  clearTag(tagString); 
  resetReader(); 
}

void checkTag(char tag[])
{
  if(strlen(tag) == 0) return; 
  if(compareTag(tag, tag1)) 
  { 
    sistemaON();
  }
}

boolean compareTag(char one[], char two[])
{
  if(strlen(one) == 0) return false; 
  for(int i = 0; i < 12; i++)
  {
    if(one[i] != two[i]) return false;
  }
  return true; 
}

void sistemaON()
{  
  if ((estadollave = digitalRead(llaveout))==0)
  {
    digitalWrite(llaveout,HIGH);
    estadollave=1;
    delay(1000);
  }
  else
  {
    if ((estadollave = digitalRead(llaveout))==1)
    {
      digitalWrite(llaveout,LOW);
      estadollave=0;
      delay(1000);
    }
  }
}

void clearTag(char one[])
{
  for(int i = 0; i < strlen(one); i++)
  {
    one[i] = 0;
  }
}

void resetReader()
{
  digitalWrite(RFIDResetPin, LOW);
  digitalWrite(RFIDResetPin, HIGH);
  delay(150);
}

if you test two codes in diferents boards you can not work with two serial ports at same time .
the serialuno connect with serialuno and the serialdos connect with serialdos.

borad one

#include <SoftwareSerial.h>
SoftwareSerial mySerialuno(2,3); // RX, TX
SoftwareSerial mySerialdos(6,7); // RX, TX

void setup()  
{
  Serial.begin(9600);
  mySerialuno.begin(9600);
  mySerialdos.begin(9600);
}

void loop() // run over and over
{
  mySerialuno.write('a');
  delay(8000);
  mySerialdos.write('b');
  delay(8000);
}

board two

#include <SoftwareSerial.h>
SoftwareSerial mySerialuno(14,15); // RX, TX
SoftwareSerial mySerialdos(16,17); // RX, TX

void setup()  
{
  Serial.begin(9600);
  mySerialuno.begin(9600);
  mySerialdos.begin(9600);
}

void loop() // run over and over
{
  mySerialuno.listen();
  while(mySerialuno.available()>0)
  {
    Serial.write(mySerialuno.read());
  }
    
  mySerialdos.listen();
  while(mySerialdos.available()>0)
  {
    Serial.write(mySerialdos.read());
  }
}

You have discovered on your own that while you can configure multiple instances of SoftwareSerial, you can only use one at a time. If you look at the included examples for SoftwareSerial you will find an example of how to multiplex two instances of SoftwareSerial. Note that there is only one buffer so any incoming data on one will be ignored when using the other.

You now have some design decisions to make. One workaround might be to add another button (or proximity sensor). Constantly listen to comSerial unless the button or proximity sensor is tripped. Then switch over to listening to rfidSerial for the span of reading one card. Then switch back to listening to comSerial and process the rfid tag number.

Cross posting in multiple languages:
Cruzar la publicación en varios idiomas:
http://forum.arduino.cc/index.php?topic=167326.msg1246759#msg1246759
http://forum.arduino.cc/index.php?topic=167327.msg1247183#msg1247183

Other cross postings:

http://forum.arduino.cc/index.php?topic=168424.0;topicseen
http://forum.arduino.cc/index.php?topic=168427.0
http://forum.arduino.cc/index.php?topic=168426.0