Confused about Arduino Uno Hardware Serial communcation

Hi, I feel like I should be knowing this. Basically I have two USB connections on my Arduino Uno,

  1. via the USB-B port as usual for uploading code at port /dev/ttyACM0, and
  2. through a USB-to-UART converter to my PC again, this time at /dev/ttyUSB0 (this is hopefully explained more clearly in the diagram below).

I also have the following simple code:

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

void loop()
{
    Serial.println("Hello, World!");
    delay(1000);
}

When I runt the program, the serial data from the Uno goes to /dev/ttyACM0. I was wondering why this is the case. I know that the Rx and Tx pins are shorted to the Atmega16U2 chip on the PCB which allows it to transfer data to/from the USB on my PC. BUT in my case, it is also connected to another USB port via the USB-to-UART bridge. How does the board decide to use the /dev/ttyACM0 port?

You should connect the CP2102 to two different pins and establish a SoftwareSerial object to communicate with that USB port.

Serial is not a bus. In fact, in your case the other USB should receive in parallel and none should be able to send anything to your Arduino.

1 Like

Those are redundant. RX and TX on the Uno are common to both channels to the PC, so nothing is gained by the CP2102 USB-serial interface.

1 Like

how do you know that the data was not going to ttyUSB0

1 Like

I had my serial monitor receiving from ttyACMO and when I switched to ttyUSB0, I wasn't getting "hello world" anymore.

The following diagram may answer to your query.

1 Like

You need to use a serial terminal emulator like putty to connect to ttyUSB0

1 Like

And if you keep using pins 0 and 1 for both functions, you have to think about the fact that doing implies you are connecting two outputs together.

Did someone already wonder why you are doing this?

a7

that doing implies you are connecting two outputs together.

Thanks, I was thinking about that but I am not educated enough on digital design to know it honestly. I'll be looking into this.

Did someone already wonder why you are doing

I just ran some code that was meant for the Mega by mistake on the Uno and I got really curious about what was happening. Thanks for all the responses.

I actually wrote some python code to read /dev/ttyUSB0:

from serial import Serial
with Serial("/dev/ttyUSB0", 9600) as arduino:
    print(arduino.readline())

which basically would do what putty would i guess but it kept saying something like device/resource busy. Anyways thanks for the advice.

Close the serial monitor when you try the python code

2 Likes

I'm using windows and IDE 1.8.19

I have an UNO on COM1 and I have FTDI USB-TTL board connected to COM3
I have a putty terminal connected to COM3.
The UNO TX pin is connected to the FTDI RX pin.

The UNO is printing to Serial.print and I see the data in the serial monitor and putty terminal

1 Like

Thanks. So basically the tx and rx pins are driving BOTH the Atmega16U2 and the FDTI converters? That makes sense I suppose.

Not quite. I read this

The UNO TX pin is connected to the FTDI RX pin.

to mean that @jim-p is "listening in" on the UNO TX pin by routing it through the FTDI to a second port on the PC.

Your Python receiver is adequate, but real terminal programs like PuTTY and CoolTerm make all kindsa experiments with serial communications very easier.

ManY times it is fruitful to play with a serially controlled device using just a terminal emulator. Obvsly this is less useful if the serial protocol uses non-printing characters.

You have to appreciate the tradeoff, but I like things like NMEA, all carried out in printable characters so you can see and generate the traffic with just a terminal program.

Naturally the price is paid in the larger number of characters required.

a7

The main question to @ 20nik00 is whether he wants to

  • duplicate the Arduino Serial output (why?), or
  • have two different Serial connections from/to an Arduino Uno
    (This needs different pins on the Arduino and SoftwareSerial)

Combining two sending Serial lines on one Arduino hardware pin (Rx) does not work at all, and might even cause electrical problems.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.