1

I want to connect the TX and RX pins together and from the command line echo some text into /dev/ttyAMA0 and tail the result (from somewhere). I ultimately want to communicate with an Arduino but first I want to understand how to configure the Pi serial UART and its capabilities; also I don't have a voltage converter chip like a CD4050 yet.

I'm using a Raspberry Pi Zero with Raspian 4.14 (2019-04-08, Stretch Lite).

I have used raspi-config to disable the login shell from being accessible over serial and left the serial port hardware enabled. I rebooted the device. /boot/config.txt now has the line enable_uart=1.

I have connected a DVM (I don't have an oscilloscope) to TX (pin 8) and when I issue the following commands I can see the voltage drop briefly from 3.3 V. This is consistent with the logic level being pulled low during sending data:

$ sudo su root
$ echo "hello" > /dev/ttyAMA0

I was hoping that if I connect the TX and RX (pin 10) together, then when I issue the following commands it would show hello that was stored in the buffer:

$ cat /dev/ttyAMA0

This doesn't work as it blocks, presumably waiting for data. If I have two terminals open and use:

# terminal 1
$ tail /dev/ttyAMA0

# terminal 2
$ echo "hello" > /dev/ttyAMA0

In terminal 1 no text is received. Additionally the voltage drops to 1.15 V and stays there. Using Ctrl+C in terminal 1 results in the TX-RX voltages to go to 0 volts.

On disconnecting the TX and RX pins from each other, the RX pin returns to high (3.3 V) and the TX pins remains at low (0 V). Keeping the pins separated again and issuing echo "hello" > /dev/ttyAMA0 results in the TX pin voltage increasing to 1.15 V (?!). Issuing the command echo "hello" > /dev/ttyAMA0 again results in it returning to 3.3 V.

I obviously have not yet found the right materials to understand how serial / TTY works / how to configure the raspberry pi.

A lot of the older tutorials say you need to edit /etc/inittab but as this has been removed I have ignored this. Additionally a lot of the older tutorials called for editing /boot/cmdline.txt to replace console=tty1 with console=ttyAMA0,9600 kgdboc=ttyAMA0,9600 console=tty1. This doesn't make much sense to me as I don't want to use the ttyAMA0 for console. I do want to use ttyAMA0 as a file descriptor to write / read from.

  • 1
    Some Pis (the ones with Bluetooth) will default to /dev/ttyS0 for the UART on GPIO 14/15. – joan Jun 14 at 20:17
  • Thanks @joan. I don't see a /dev/ttyS0 device on my Pi. Additionally I know the /dev/ttyAMA0 is doing something on both read and write due to the behaviour of the voltages associated with the TX and RX pins as I issue different commands interacting with the /dev/ttyAMA0. – AJP Jun 14 at 20:20
  • If you want to see activity on the UART you could use my piscope or the command line monitor GPIO. – joan Jun 14 at 20:23
  • Thanks @joan I'll check it out! :) – AJP Jun 14 at 21:20
  • @ AJP - If the final goal of your serial loopback experiments is to connect Arduino to Rpi, then you might be interested to read my answers to a similar question - raspberrypi.stackexchange.com/questions/96184/… you might also like to search in this forum "serial loopback" to find more answers you might find useful. – tlfong01 Jun 15 at 1:37
0

The reason nothing happens is because you are sending to the UART, but not reading.

Try

cat < /dev/serial0

Most of us would use a serial monitor e.g. minicom or miniterm:

python3 -m serial.tools.miniterm /dev/serial0 9600

PS The port /dev/ttyAMA0 may be connected to Bluetooth or serial, It is better practice to use /dev/serial0 which is guaranteed to be the serial port (if enabled),

  • By the way cat /dev/serial0 is the same command as cat </dev/serial0 – joan Jun 15 at 8:38
  • Ah, you're right @joan so when I did cat /dev/ttyAMA0 that was fine and if I then did echo "hello" > /dev/ttyAMA0 it works as intended. Thanks. – AJP Jun 15 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.