I am aware that the RX and TX pins can be used as GPIO when Serial is not in use.
But I was wondering if I can use the RX pin as GPIO when the Arduino is only transmitting data to the PC and not receiving any?
And similarly, can the TX pin be used as GPIO if the Arduino is only receiving data but not sending any?
Or is it a simple answer that as soon as Serial is used, both pins are not usable for anything else?
Even if you use the Serial for both reading and writing, you can use pins 0 and 1 as gpio between Serial sessions if you then call the Serial.begin() method again
Ok I can make some use out of this information. I'd like to use one of the RX or TX pins as a reset signal that will only be toggled once at the beginning of my program.
So I can turn off Serial any time, use the pins as GPIO when I need to, then turn serial on again.
But once Serial is turned on, both RX and TX are not available as GPIO even though only one way comms are happening?
That was my question. I read somewhere that when Serial is used, it has priority.
When it comes to my project, its a game controller so its always sending states to the PC so Serial is always on. I thought I could use those pins in the setup function before it actually starts sending data.
yes but my question still stands - even though the Arduino is only transmitting and never receiving are both the TX and RX pins unusable? or can the RX pin be used regardless?
At least for Uno & Nano this is not the case. Communication with the computer is handled by a separate chip - UART-USB bridge, which stands between the PC and the controller. USB is located on one side of this bridge, mcu pins 0 and 1 on the other and do not participate in this process in any way. Moreover, the controller does not tell the computer anything - neither the port number, nor the baudrate ... it does not even know about its existence.
As for data exchange over the serial port, if data transfer occurs without confirmation, then the second pin is not involved
RX and TX is for serial send get from component , i normally use them for HC-06 because i will not gonna need any library to get send etc getted values goto serial, sended values goto HC-06
You are aware that the RX and TX leds are driven by the usb-to-ttl converter and not by the main processor (328P, 2560)? For boards with native USB (e.g. 32U4), that's not the case but in that case RX and TX are not used for the USB communication.
Hi guys, thanks for the answers so far. I see there is some debate on the topic and I think I should have given more detail about my application.
I am using a 32U4 so it has built in USB interface.
The application is a game controller which has a key matrix circuit driven by a 4017 decade counter. I have all pins occupied except RX and TX, and I am still looking for one pin to use as a reset signal for the decade counter on startup.
Because it's a game controller, is it sending data to the PC all the time but not receiving any back. Hence my assumption that TX pins is busy and unusable but RX is idle so could be used.
When it is plugged in, I understand it first does some handshaking with the PC so it's using both RX and TX. (Can see this on the RX and TX LEDs blinking, but I'm not sure if they are connected to the RX and TX pins directly)
If they are connected, then in those moments the counter would be reset a few times without my control, but that is ok because nothing has started yet.
After that I set the RX high and low quickly to manually send a reset signal to the counter and then the rest of the application runs.
So far it seems to work, but anyway I am wondering about it and if it is good practice, or maybe it is working because of coincidence?
It would have been much easier if you told that from the beginning. In that case RX and TX pins are not used by the connection to the computer and can be freely used for other puposes.
" I have all pins occupied except RX and TX, and I am still looking for one pin to use as a reset signal for the decade counter on startup. "
You can use the reset signal of the Arduino. At start up, a short duration signal ( going from High to Low and Low to High ) reset the Arduino chip. So connect that signal to the counter, has long it had the same need of a High to Low to High signal as the Arduino, it will be fine.