Raspberry Pi 3 GPIO pins 8 and 10 are UART Tx
and UART Rx
respectively. Is it possible to use those pins to control external peripherals(for example network device which is managed over serial port) over RS-232 port? If not, then is it possible to use unused GPIO pins for that?

- 225
- 3
- 7
2 Answers
Yes. These pins are a serial port. HOWEVER, you have a hurdle or two first. Their polarity is absolutely definitely unequivocally reversed, so when the pins output a logic high, it is actually a logic low which is presented and vice-versa. Further, by comparison to the 12V signals which might be encountered on other types of COM port, these are TTL signals at 5V.
To convert them to a traditional COM port, you'll need an RS232-TTL convertificator (e.g. the tried and tested MAX232 http://www.ti.com/lit/ds/symlink/max232.pdf). As can be seen from teh data sheet, not only does this device convert the 5V logic levels from the Raspberry Pi to the higher voltages levels specified by an RS-232 port, but it also inverts the logic levels for you, such that logic high = logic high.
These can be bought as ready-made modules, even with a 9-pin serial connector already attached.
By default, I think the pins make the RPi shell available to a serial terminal using these pins, so you need disable that feature int eh kernel (use the raspi-config program).
The device you need to read/write was /dev/ttyAMA0.
Find everything you need to know about making it work from Python here: http://pyserial.readthedocs.org/en/latest/pyserial.html

- 708
- 8
- 23
You can use the pins to connect to a serial peripheral provided you ensure that it is 3.3V or employ level converters. You will find many posts on this site with suggestions.
You should NOT connect to a serial port with a DB9 connection. The best way to do this is with one of the serial to RS-232 converters.
NOTE that the Pi3 has some issues with serial. See How-do-i-make-serial-work-on-the-raspberry-pi3 for a discussion and a solution.
-
Thanks! I am aware of level converters. However, what do you mean by "serial to RS-232 converters"? Is this a same as TTL <-> RS-232 converter using MAX232 chip? – Martin Apr 20 '16 at 08:45
-
@Martin There are many and this chip is commonly used. These all safely interface with what are (incorrectly) called RS-232 and convert to lower unipolar voltages. You need to ensure that any such module will interface to 3.3V not just TTL. – Milliways Apr 20 '16 at 09:39
/dev/ttyAMA0
, and this still works on Pi2 and earlier. You should use/dev/serial0
on recent Raspbian. – Milliways Apr 20 '16 at 00:32