Using the GPIO built-in serial pins

Standard RS232 signals can range from -15V to +15V, so you must never directly connect any RS232 device to the GPIO serial pins. You must use an RS232 to TTL voltage-level converter (such as a MAX232 chip) or a device that uses TTL-level signals (such as another microcontroller or a TTL serial console cable):

A USB-to-TTL serial console cable (voltage level is 3V)

Raspberry Pi has TTL-level serial pins on the GPIO header that allow the connection of a TTL serial USB cable. The wires will connect to the Raspberry Pi GPIO pins and the USB will plug in to your computer and be detected like a standard RS232-to-USB cable:

Connection of a USB-to-TTL serial console cable to the Raspberry Pi GPIO

It is possible to provide power from the USB port to the 5V pin; however, this will bypass the built-in polyfuse, so it is not recommended for general use (just leave the 5V wire disconnected and power it up as normal using the micro USB).

By default, these pins are set up to allow remote terminal access, allowing you to connect
to the COM port via PuTTY and to create a serial SSH session.

A serial SSH session can be helpful if you want to use Raspberry Pi without a display attached to it.

However, a serial SSH session is limited to text-only Terminal access since it does not support X10 forwarding, as used in the Connecting remotely to Raspberry Pi over the network using SSH (and X11 forwarding) section of Chapter 1, Getting Started with a Raspberry Pi 3 Computer.

In order to use it as a standard serial connection, we have to disable the serial console so it is available for us to use.

First, we need to edit /boot/cmdline.txt to remove the first console and kgboc options (do not remove the other console=tty1 option, which is the default Terminal when you switch on):

sudo nano /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait  

The previous command line becomes the following (ensure that this is still a single
command line):

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait  

We also have to remove the task that runs the getty command (the program that handles the text Terminal for the serial connection) by commenting it out with #. This is set in /etc/inittab as follows:

sudo nano /etc/inittab
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100  

The previous command line becomes the following:

#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100  

To reference the GPIO serial port in our script, we use its name, /dev/ttyAMA0.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.55.18