Enable UART + serial communication on Raspberry Pi

Since I had the opportunity to use serial communication with Raspberry Pi, I will post a memorandum on how to communicate.

environment

Raspberry Pi setup

By default, the Raspberry Pi has the serial port disabled, so change the setting. Open LXTerminal and enter the command.

pi@raspberrypi:~ $ sudo raspi-config

The following screen will be displayed. Select "5 Interfacing Options". image.png Then select P6 Serial. image.png Select No. image.png Select "Yes". image.png Then you will see a screen like this with the serial port enabled. If you exit raspi-config as it is, you will be asked to choose whether to restart, so restart it. image.png After rebooting, enter the following command to display the enabled serial port ttyS0 under / dev /.

pi@raspberrypi:~ $ ls -l /dev/ttyS*

Wiring for Raspberry Pi

Since the 8th pin (GPIO14) and 10th pin (GPIO15) of Raspberry Pi are UART pins, Short with a wire jumper. image.png

Implementation

Check communication using the pyserial library.

serialTest.py


import serial

#Communication establishment
ser = serial.Serial('/dev/ttyS0', '9600', timeout=0.1)
#Data transmission / reception
ser.write('Hello, World!')
print(repr(ser.readline()))
ser.close()

After saving the file, move to the directory where the file is saved in LXTerminal and execute it. If successful, the message you sent will be displayed.

pi@raspberrypi:~/work $ python setialTest.py
Hello World!

Summary

I haven't touched the Raspberry Pi so much, so I didn't know that serial communication was turned off by default. I would like to use it for various purposes such as connecting to a sensor or Arduino.

Recommended Posts

Enable UART + serial communication on Raspberry Pi
Testing uart communication on Raspberry Pi
Serial communication with Raspberry Pi + PySerial
pigpio on Raspberry pi
Cython on Raspberry Pi
Serial communication between Raspberry pi --Arduino Uno (Python)
Introduced pyenv on Raspberry Pi
Use NeoPixel on Raspberry Pi
Install OpenCV4 on Raspberry Pi 3
Install TensorFlow 1.15.0 on Raspberry Pi
MQTT on Raspberry Pi and Mac
raspberry pi 4 centos7 install on docker
Install ghoto2 on Raspberry Pi (memo)
Try using ArUco on Raspberry Pi
OpenCV installation procedure on Raspberry Pi
Power on / off Raspberry pi on Arduino
Detect switch status on Raspberry Pi 3
Install OpenMedia Vault 5 on Raspberry Pi 4
L Chika on Raspberry Pi C #
Build wxPython on Ubuntu 20.04 on raspberry pi 4
"Honwaka Notification Lamp" on Raspberry Pi Part 2
Detect "brightness" using python on Raspberry Pi 3!
USB boot on Raspberry Pi 4 Model B
Adafruit Python BluefruitLE works on Raspberry Pi.
Accelerate Deep Learning on Raspberry Pi 4 CPU
Set swap space on Ubuntu on Raspberry Pi
Programming normally with Node-RED programming on Raspberry Pi 3
Use the Grove sensor on the Raspberry Pi
Install 64-bit OS (bate) on Raspberry Pi
Install docker-compose on 64-bit Raspberry Pi OS
Run servomotor on Raspberry Pi 3 using python
"Honwaka Notification Lamp" on Raspberry Pi Part 3
Working with sensors on Mathematica on Raspberry Pi
Build OpenCV-Python environment on Raspberry Pi B +
Detect temperature using python on Raspberry Pi 3!
Mount Windows shared folder on Raspberry Pi
Matrix multiplication on Raspberry Pi GPU (Part 2)
How to install NumPy on Raspberry Pi
I installed OpenCV-Python on my Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
Why detectMultiScale () is slow on Raspberry Pi B +
Detect slide switches using python on Raspberry Pi 3!
Try using a QR code on a Raspberry Pi
Detect magnet switches using python on Raspberry Pi 3!
Raspberry Pi backup
Enjoy electronic work with GPIO on Raspberry Pi
Power on / off your PC with raspberry pi
Use Grove-Temperature & Humidity Sensor (DHT11) on Raspberry Pi
Make DHT11 available on Raspberry Pi + python (memo)
Beginning cross-compilation for Raspberry Pi Zero on Ubuntu
Sound the buzzer using python on Raspberry Pi 3!
Play with your Ubuntu desktop on your Raspberry Pi 4
Display CPU temperature every 5 seconds on Raspberry Pi 4
Introduced Ceph on Kubernetes on Raspberry Pi 4B (ARM64)
Connect to MySQL with Python on Raspberry Pi
Build a Python development environment on Raspberry Pi
Build an Arch Linux environment on Raspberry Pi
Record temperature and humidity with systemd on Raspberry Pi
Build an OpenCV4 environment on Raspberry Pi using Poetry
Run LEDmatrix interactively with Raspberry Pi 3B + on Slackbot
Try debugging Python on Raspberry Pi with Visual Studio.