Can the Uno handle two serial port functions ?

irethedo:
The Leonardo might work for me if it has 2 serial ports as you say...

And it might not as the Leonardo can bring its own limitations to the table, and I understand the software serial library Lefty mentions is written with exactly this in mind, for the Uno you already have, and it is free.

The Leonardo might work for me if it has 2 serial ports as you say...

And it might not as the Leonardo can bring its own limitations to the table, and I understand the software serial library Lefty mentions is written with exactly this in mind, for the Uno you already have, and it is free.

What limitations?

If I ever knew, I've forgotten. When I looked at the options it was pretty clear that there are essentially two types of Arduino. There is the Uno, Mega, and those of that ilk in the mainstream, and there is the rest in the peripheral niches. On looking at the options, the niches very peripheral and the mainstreamis unsurprisingly where you find the bang for the buck. Most pointedly, you would need to see something pretty convincing to pass up the Uno you already have if that can be persuaded to do what you want at no cost.

Does anyone know if the Uno or the Leonardo can be used as a Serial to USB adapter?

Does anyone know if the Uno or the Leonardo can be used as a Serial to USB adapter?

The Leonardo can be used as this, the UNO includes an ATmega16U2 for this purpose, so theoretically it can be used too. But I guess you question is too general to be of value for your purpose.

Does anyone know if the Uno or the Leonardo can be used as a Serial to USB adapter?

The Leonardo can be used as this, the UNO includes an ATmega16U2 for this purpose, so theoretically it can be used too.

Thanks,

I will scour the web looking for some example code of using the Leonardo as a Serial to USB converter...

Does anyone know if a Uno be used as a Serial to USB converter with the use of
the SoftwareSerial library or is this only for Leonardo & Mega arduinos?

thanks

Does anyone know if a Uno be used as a Serial to USB converter with the use of
the SoftwareSerial library or is this only for Leonardo & Mega arduinos?

You don't need the SoftwareSerial library just for a Serial2USB converter because the UNO has one onboard. Just connect the USB and put the serial device on pins 0 and 1 and you have a USB2Serial device.

As you have a uno your best option is to try the software serial. It is just downloading the lib and try.
I have used software serial before and the quality is OK.
One of the differences between UNO and leonardo is that the USB on the UNO is serviced by a chip which is actually connected to pin 0 and 1.
On the Leonardo that is not the case. This means that the serial port on pin 0 and 1 is free for other usages. In other words with the Leonardo you have 2 hardware serial ports.

Leonardo does have some drawbacks as well. Basically it is not as mainstream as the UNO so there were/are libraries that do not support the Leonardo. It changes all the time so if you want a project with the leonardo it is better to check at that time whether all shields/libraries needed support the Leonardo.

Adding this all up: try with your uno and the software serial lib http://arduino.cc/en/Reference/SoftwareSerial.
The comment on the code states

 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.

Sounds like what you are looking for.
Best regards
Jantje

You don't need the SoftwareSerial library just for a Serial2USB converter because the UNO has one onboard. Just connect the USB and put the serial device on pins 0 and 1 and you have a USB2Serial device.

As you have a uno your best option is to try the software serial. It is just downloading the lib and try.
I have used software serial before and the quality is OK.
One of the differences between UNO and leonardo is that the USB on the UNO is serviced by a chip which is actually connected to pin 0 and 1.

Thanks for the ideas...

Has anyone successfully made a Serial2USB converter with a Uno with its shared pins 0 & 1?

I will try the SoftwareSerial library which should allow me to use pins (other than 0 & 1) because I am concerned about communication issues if pin 0 & 1 are shared for both my serial device and the USB to the PC unless I can see some example code that works...

I appreciate the help !

I will try the SoftwareSerial library which should allow me to use pins (other than 0 & 1) because I am concerned about communication issues if pin 0 & 1 are shared for both my serial device and the USB to the PC unless I can see some example code that works...

What do you want to do? If you want your UNO to be a USB2Serial device you can just connect it via USB to your PC and connect the TTL serial device to pins 0 and 1. Voilà, you have your USB2Serial. You don't need any software to be run on the UNO, it acts as a USB2Serial converter.
If you need something else than a USB2Serial converter, tell us what you want to achieve!

The SoftwareSerial class works OK for baud rates up to 9600, with some devices even up to 38400. I personally never got beyond that limit.

What do you want to do? If you want your UNO to be a USB2Serial device you can just connect it via USB to your PC and connect the TTL serial device to pins 0 and 1. Voilà, you have your USB2Serial. You don't need any software to be run on the UNO, it acts as a USB2Serial converter.
If you need something else than a USB2Serial converter, tell us what you want to achieve!

Thanks Pylon, sounds simple and yes that is all I want to do is to send data to my serial device
from my PC and to stream TTL serial data from that device to the USB port as I can have my Lab view application parse the data...

Does this require any code on the Uno to set up the pin 0 & 1 lines?
What would the code look like if there is code needed?

(regarding the TTL levels- I am using a Max32222 chip to interface between the ardunio Uno and the serial port of the device.)

Does this require any code on the Uno to set up the pin 0 & 1 lines?

No. If you used the Arduino previously upload a sketch that doesn't use the serial interface (the Blink example is excellent for that), so the main processor doesn't acquire the serial interface and interferes with your usage.

Does this require any code on the Uno to set up the pin 0 & 1 lines?

No. If you used the Arduino previously upload a sketch that doesn't use the serial interface (the Blink example is excellent for that), so the main processor doesn't acquire the serial interface and interferes with your usage.

Thanks- sounds simple...

will I be able to see the data that comes across the USB port in a terminal program?

will I be able to see the data that comes across the USB port in a terminal program?

If you connected everything correctly and configured the program that way: yes.

Because the Rs232 lines are ~12v, I connected a Max 32222 inline with the
txd line from the device to the Arduino Uno.

At first I could only see the ~12v data from the Serial Device txd line on the Max 3222 chip
but the 5v side of this chip (which is connected to D0 - rxd) did not have this same signal so I
set the pinmode of D0 as an input and now I can see the 5v signal on D0
when I press a button on the serial device panel.

I have the USB connected to my PC and am running hyperterminal set to the correct values
of the device (9600 N81) but this data is not seen in the hyper terminal...

I am running out of ideas but it does not appear that the RXD line of the Arduino on D0 is being
echoed up the USB port to my PC...

This is the modified blink program that I am using:

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);   
  pinMode (0, INPUT);  // rxd
  pinMode (1, OUTPUT);  // txd
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

OK, I got it working...

I had to actually set up a simple serial polling routine and have added the code below.

Thank you to everyone that sent some direction for your help in solving this issue!

//  Cpanel- to read the Control Panel Serial data and echo data to USB port...

 
// Pin 13 has an LED connected on most Arduino boards.
int led = 13;

// the setup routine runs once when you press reset:
void setup() 
{   

  // initialize serial:
  Serial.begin(9600);  
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);   
  pinMode (0, INPUT);  // rxd
  pinMode (1, OUTPUT);  // txd
}

// the loop routine runs over and over again forever:
void loop() 
{
 
  while (Serial.available() > 0) 
  {
    char inChar = (char)Serial.read(); 
    Serial.print(inChar);
  }

}

This set up works when reading keys pressed on the control panel as this data is sent down the serial port and echoed to the PC via the USB port when I am running Windows XP version of hyperterminal but I am unable to send data to this device when I type characters into the hyperterminal window.

Am I missing something or should this be seamless?

Or do I need to add some sort of polling code so that data gets echoed back to the serial device also?

int led = 13;

// the setup routine runs once when you press reset:
void setup() 
{   

  // initialize serial:
  Serial.begin(9600);  
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT); 

  pinMode (0, INPUT);  // rxd
  pinMode (1, OUTPUT);  // txd
}

// the loop routine runs over and over again forever:
void loop() 
{
 
  while (Serial.available() > 0) 
  {
    char inChar = (char)Serial.read(); 
    Serial.print(inChar);
  }

}
  pinMode (0, INPUT);  // rxd
  pinMode (1, OUTPUT);  // txd

You must not do that. Once you called Serial.begin() pins 0 and 1 are handled by the hardware you must not call any functions that change the hardware configuration.

Or do I need to add some sort of polling code so that data gets echoed back to the serial device also?

If you want to see the characters you type in the hyperterminal, you must echo them back (or activate local echoing in the program).

Can you describe again, what your problem is? Describe what works and what doesn't as well as what you expected.

Thank you Pylon-

  pinMode (0, INPUT);  // rxd
  pinMode (1, OUTPUT);  // txd

You must not do that. Once you called Serial.begin() pins 0 and 1 are handled by the hardware you must not call any functions that change the hardware configuration.

I have tried this code as shown above and with the pinmode lines commented out
and have not seen a difference in the operation or behavior of either one.

Or do I need to add some sort of polling code so that data gets echoed back to the serial device also?

If you want to see the characters you type in the hyperterminal, you must echo them back (or activate local echoing in the program).

Yes, I have the echo feature set in Hyper terminal and see the characters as I type them into hyper terminal. These lines are now commented out...

Can you describe again, what your problem is? Describe what works and what doesn't as well as what you expected.

OK, as you may recall from my earlier posts(s) that I have a control panel containing
60 plus buttons that is a serial device, I have this connected to my Arduino Uno
and the arduino connected to my PC's USB port. You mentioned earlier that this is a pass through type configuration because the USB and the serial port share the same ines (d0 = rxd, & d1 = txd).

I do have a level shifter between the arduino and the device to set the lines to rs232 levels and I can read data from the control panel when buttons are pressed.
When buttons on the contol panel are pressed, I can see a negative going series of
pulses on both d0 and d1 of the arduino. The d0 line's voltage level is between 0 volts
and ~ 4v while the d1 line's voltage level is between 0 volts and ~ 5v.

When I enter a key from my PC's keyboard,I can see a small negative going pulse that
appears at a voltage level of ~ 4v to a low of about ~3.5v and cannot see a pulse
on the txd line (D1).

In an attempt to isolate this to the ardunio, I have removed the level shifter part and tried this and I still am not able to see a pulse on the txd line (d1).

So the problem appears to be that I can not send data to the serial port control
panel device and the data that should be presented to d1 (from the USB port) is not...

Not sure what else to try at this point.