Raspberry Pi is a small factor fully-featured computer. It can be used for multiple purposes such as a controller.
In most of applications it is necessary to use some kind of communication interface. Raspberry Pi delivers, among others, UART, SPI and I2c. However, UART (serial port) is most commonly used if you just want to send some data between RPi and other devices. While using SPI or I2c in i.e. python script is rather straightforward, using serial port, or making it to work, isn’t so easy as it might seem.
First of all, you have to add user to two groups: tty and dialout by typing in terminal:
sudo usermod -a -G tty pi sudo usermod -a -G dialout pi
After that you need to disable system service that is using the serial port with following command
sudo systemctl disable [email protected]
When you successfully complete above steps you have to remove any ttyAMA0 (serial port device in /dev) related entry in /boot/cmdline.txt. This will prevent RPi from using the serial port as a debug serial port. The debug serial port is a simply a terminal available on GPIO pins. If something goes wrong with your RPi or you do not have LCD screen with HDMI connector you can always use serial adapter to communicate with your mini computer by using those means.
To apply all the changes and ensure yourself that everything is working fine you have to reboot with
sudo reboot
When the system is running once again you can test if the serial port is available and ready to use. For this you can install minicom — a small application to communicate over serial port.
sudo apt-get install minicom
You can try it out with:
minicom -b 115200 -o -D /dev/ttyAMA0
Now you are ready to write some python scripts.
Good Job Wojtek!