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
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=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.