Second serial port on Arduino Uno?

Is it possible to use pins other than digi 0 & 1 for serial input, on an Arduino Uno?

Since 0 &1 are connected to the USB chip, I don't want to connect another serial input (TTL level) to the Arduino RX line, because the output of the USB chip will be driving it.

The UNO has only one hardware UART. You would have to go to a MEGA to get more hardware serial lines. It is possible, for many types of applications, to use a software serial implementation. See this tutorial for the basics: http://www.arduino.cc/en/Tutorial/SoftwareSerial. There is a much better library, NewSoftSerial (http://arduiniana.org/libraries/newsoftserial) that is the preferable library to use.

cappy2112: Is it possible to use pins other than digi 0 & 1 for serial input, on an Arduino Uno?

Since 0 &1 are connected to the USB chip, I don't want to connect another serial input (TTL level) to the Arduino RX line, because the output of the USB chip will be driving it.

Yes, it is entirely possible to do that. The USB to serial chip is connected to the Arduino pins 0 and 1 via 1K resistors. So you can connect another TTL or 5v CMOS level signal to the Rx pin quite safely, provided that the signal source can source and sink 5mA.

gardner:
The UNO has only one hardware UART. You would have to go to a MEGA to get more hardware serial lines. It is possible, for many types of applications, to use a software serial implementation. See this tutorial for the basics: http://www.arduino.cc/en/Tutorial/SoftwareSerial. There is a much better library, NewSoftSerial (http://arduiniana.org/libraries/newsoftserial) that is the preferable library to use.

Thanks.

This is mostly working well, except when I do .print() or println(), using the object returned from the NewSoftSerial constructor
I don’t see anything on the console
Is console I/O not supported in this library?

#include <NewSoftSerial.h>

#define SP2_RX 2
#define SP2_TX 3

NewSoftSerial Serial2(SP2_RX, SP2_TX); // 2 is RX, 3 is TX

void setup(void)
{
  
  //Serial.begin(115200);
  Serial2.begin(115200);
  
  DDRC = 0x20;  // Port C PIN 5 as output
  PORTC = 0x00; // Port C Pin5 - off
  
  DDRB = 0x20;   //Digi Pin 13 as output- to blink LED
  PORTB = 0x00;  // Pin 13 - off
  
}

void loop(void)
{
  
int serialData;
int numBytes;
int i, x;

  numBytes = Serial2.available();
  if( numBytes >0 ) {
    Serial2.print(numBytes,DEC); Serial2.println(" Bytes avail");
    for(i=0; i<numBytes; i++) {    
      serialData = Serial2.read(); 
      if( serialData != -1 ) {
        Serial2.println(serialData,BYTE);
        
         PORTC = 0x20; // trigger the scope when we see a trigger on the Serial Port
         PORTC = 0x00;  
            
         PORTB = 0x20; // blink the LED so the user can see we got a trigger char
         delay(1);
         PORTB = 0x00;
      }
    }
  }
}

the "console" is connected to the hardware serial pins on 0 and 1, it stands to reason that anything output by the software serial library on pins 2 and 3 won't bee seen by the serial monitor on 0 and 1.

extent:
the “console” is connected to the hardware serial pins on 0 and 1, it stands to reason that anything output by the software serial library on pins 2 and 3 won’t bee seen by the serial monitor on 0 and 1.

Why would the creators of the NewSoftSerial lib provide print & println functions, if they don’t don anything?
The example provided with their library indicates the console I/O should work.

#include <NewSoftSerial.h>

NewSoftSerial mySerial(2, 3);

void setup()  
{
  Serial.begin(57600);
  Serial.println("Goodnight moon!");

  // set the data rate for the NewSoftSerial port
  mySerial.begin(4800);
[color=red]  mySerial.println("Hello, world?");[/color]
}

void loop()                     // run over and over again
{

  if (mySerial.available()) {
      Serial.print((char)mySerial.read());
  }
  if (Serial.available()) {
[color=red]     mySerial.print((char)Serial.read());[/color]
  }
}

It does work, it prints to the pins that you told the softwareSerial port to print to. If you want to see it's output in the serial monitor on your computer you need to setup the softwareSerial port to be on the pins that the computer is listening to, 0 and 1.

But in that case why bother using the software when you could just use the hardware that's already on pins 0 and 1?

As best I can see (and explain)

That example Print's to the HARD serial ( pins 0,1) what it reads from the SOFT serial (pins 2,3)

It also prints to the SOFT serial what it reads from the HARD serial.

If you connected a serial LCD to pins 2 and 3 .. and fed "hello world" into the HARD serial ... it would print "hello world" out onto the LCD Via the SOFT serial.

Did you get that .. because I'm not sure I did :astonished:

extent:
But in that case why bother using the software when you could just use the hardware that’s already on pins 0 and 1?

Because when I connect the external serial line from the device I’m monitoring to the Arduino’s RX, I cannot download sketches.
I have to manually remove it each time.

An ATMega 2560 would come in handy.

if you want to connect the console to the softserial, why don't you get a FTDI usb chip and hook it to the soft serial lines? presto chango, new console? that way you can have console running on one port while you download on the other.

cappy2112:

extent: But in that case why bother using the software when you could just use the hardware that's already on pins 0 and 1?

Because when I connect the external serial line from the device I'm monitoring to the Arduino's RX, I cannot download sketches. I have to manually remove it each time.

An ATMega 2560 would come in handy.

In that case why don't you connect the device you are monitoring to the software serial pins? Then you can use the hardware serial for console output.

cappy2112: An ATMega 2560 would come in handy.

Or a Freetronics USBdroid which is a Uno with a second hardware serial port. http://www.freetronics.com/products/usbdroid

Or an Arduino Leonardo (when it becomes available), which has separate USB and serial ports.

Or a 324/644/1284 based board. Helps if it has 2nd serial port hardware driver like MAX232 or equivalent if going to a PC.

If you expect to be able to write serial data to any serial port and have it all be seen by the serial monitor on your computer you'll be sorely disappointed, that's the point I was trying to get at. A Mega/Leo/Bobduino/anything will behave exactly the same way that your uno does with softSerial.

If you want to send data to your PC, you need to send it to the port that your pc is listening to.

In your code you're hooking your external device up to a 2nd serial port, sending data to your external device, and wondering why your computer is not seeing the data.

Bobuino has RS232 driver on 2nd port, I use a RS22/USB cable on it to 2nd serial monitor program.

absolutely, but having hardware serial ports or RS232 drivers completely misses the crux of his problem. If he hooks up 2 serial ports to his computer, a 3rd to his device and prints serial data to the 3rd port he’s still not going to see anything on either of the monitors on his computer.

Yes, I totally understood the problem - sending data to a port that was not connected to a serial monitor port on the PC.

To solve your problem you just need to read from one Serial and write to the other, making sure the one you are writing to is the one connected your display as mentioned above.

Essentially :

data = Serial1.read();

Serial2.write(data); //Where Serial2 is connected to display

hi guyss...

i'm working with arduino uno...

and my task is to count the number of blinkings of LED on energy meter per day...

so can i connect the LED (positive pin) directly to arduino uno (2nd pin)????

and i need code for that pulse countings...

can anyone help me????