User Guide
Table Of Contents
180
In Raspbian, the Pi’s serial port is /dev/ttyAMA0. This device is
usually configured for console input and output, and so if you
want to control the port from your own programs then you need
to change two configuration files:
1. On the Application Launcher, click LXTerminal.
2. Type the following command and then press Enter:
sudo nano /etc/inittab
3. On the line that reads TO: 23: respawn: /sbin/getty
–L ttyAMA0 115200 vt100, add a # symbol at the
start of the line. This makes the line into a comment
so that Raspbian ignores it.
4. Press Ctrl + O, and then press Enter.
5. Press Ctrl + X.
6. Type the following command and then press Enter:
sudo nano /boot/cmdline.txt
7. Remove all references to /dev/ttyAMA0 so that the
line reads:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/
mmcblk0p2 rootfstype=ext4 elevator=deadline
rootwait
8. Press Ctrl + O, and then press Enter.
9. Press Ctrl + X.
10. Type the following command and then press Enter:
sudo shutdown -r now
Making Serial Communications from Python 3
To send and receive data from the serial port in Python, you can
use the pySerial module:
1. At the top of your script, include the following line:
import serial
The Pi’s serial port uses 3.3 V logic levels. You need logic level
converters to connect the Pi to the 5 V ports used by most USB
serial port adapters.