/dev/ttyAMA0 on the raspberry pi 3 maps to the bluetooth and to the standard serial port on the others
Assuming you have used the default raspbian image, you will first need to disable the serial console as detailed here
The Broadcom UART appears as /dev/ttyAMA0 under Linux.
There are several minor things in the way if you want to have dedicated control of the serial port on a Raspberry Pi.
Firstly, the kernel will use the port as controlled by kernel command line contained in
The file will look something like this:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
The console keyword outputs messages during boot, and the kgdboc keyword enables kernel debugging.
You will need to remove all references to ttyAMA0. So, for the example above
/boot/cmdline.txt, should contain:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
You must be root to edit this (e.g. use sudo nano /boot/cmdline.txt). Be careful doing this, as a faulty command line can prevent the system booting.```
Secondly, after booting, a login prompt appears on the serial port. This is controlled by the following lines in
#Spawn a getty on Raspberry Pi serial line
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
You will need to edit this file to comment out the second line, i.e.
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100