0

I'm working on a project that needs multiple TX/RX pins, but the Raspberry Pi that I have only has 1 of these pins. Can I use the GPIO pins as TX/RX pins? Or is there an adapter available somewhere?

Specifically, I need the TX/RX pins for a SIM module and a GPS module. Perhaps there are SIM and GPS modules that uses GPIO directly instead? Any links would be helpful

aldo
  • 33
  • 1
  • 2
  • 7
  • Related if not dupe: https://raspberrypi.stackexchange.com/q/98393/19949 , https://raspberrypi.stackexchange.com/q/96697/19949 , https://raspberrypi.stackexchange.com/q/83918/19949 , and (if a Pi4): https://raspberrypi.stackexchange.com/q/99954/19949 – Ghanima Oct 07 '19 at 16:58
  • @Ghanima None of the Dupe's mention Software Serial and from my understanding that is what the OP is asking for. – MatsK Oct 07 '19 at 19:01
  • @MatsK fair enough, but I still consider it related and these might very well be applicable. The OP seems to be open minded about the solution (e.g. they consider peripherals that do not use a serial interface at all). – Ghanima Oct 07 '19 at 19:05
  • @Ghanima I agree that it is kind of related. – MatsK Oct 07 '19 at 19:12
  • @aldo, Ah, let me see, you can consider two things: (1) Switch to Rpi4B, which has FIVE hardware uarts: TxD0 to TxD4, RxD0 to RxD4, (2) Use USB to serial adapters/cables. Say, if you have a 9 port USB hub, and 9 USB/TTL cables, you can talk to 9 SIM/GPS modules at the same time. – tlfong01 Oct 08 '19 at 01:47

2 Answers2

3

There is a way that is called "Software serial" or "Soft UART".

The project https://github.com/adrianomarto/soft_uart is doing precisely what you are looking for, you can install the soft_uart and use any GPIO as Rx/Tx.

Software-based serial port module for Raspberry Pi.

This module creates a software-based serial port using a configurable pair of GPIO pins. The serial port will appear as /dev/ttySOFT0.

Features

  • Works exactly as a hardware-based serial port.
  • Works with any application, e.g. cat, echo, minicom.
  • Configurable baud rate.
  • TX buffer of 256 bytes.
  • RX buffer managed by the kernel.
MatsK
  • 2,791
  • 3
  • 16
  • 20
0

You could a USB to serial converter. That would let you connect the USB end to the Pi and the serial TX/RX/Ground end to the serial device.

You can use (my) pigpio to bit bang a serial link on any spare GPIO.

As long as the baud rate is 19k2 or less it should be fine.

For Python the read is straightforward. Writing requires waves and needs more effort.

joan
  • 71,024
  • 5
  • 73
  • 106