Raspberry Pi Environment Configuration#
Burning the Image#
After burning is complete, power on the device.
Enabling VNC#
Preferences -> Raspberry Pi Configuration
Select Interfaces
-> Enable the VNC button
After enabling, use VNC tool to connect to the Raspberry Pi and display the virtual desktop.
Enabling Raspberry Pi Hardware Serial Port#
Enable the GPIO
serial port function and use the hardware serial port.
Use sudo raspi-config
to enter the graphical interface.
Select the menu Interfacing Options -> 6 Serial
.
Select NO for the first option (would you like a login shell to be accessible over serial?) and YES for the second option (would you like the serial port hardware to be enabled?).
Save and restart. Check the mapping relationship. serial0 is the serial port corresponding to the GPIO pin, and serial1 is the serial port corresponding to Bluetooth, which is not enabled by default. Use ls -l /dev/serial*
to check the current mapping relationship:
There is an additional serial0 GPIO serial port, which uses ttyS0. The GPIO serial port function is already enabled, but it uses a software serial port implemented by the CPU.
If you want to use a stable and reliable hardware serial port, you need to swap the default mapping between the Raspberry Pi 3B+ hardware serial port and the mini serial port (first disable Bluetooth sudo systemctl disable hciuart
).
Add a line of code dtoverlay=disable-bt
to the end of the /boot/config.txt
file, and enter the command line:
sudo systemctl disable hciuart
Save and restart, then check the device mapping relationship again with ls -l /dev/serial*
. It should be successfully swapped. Seeing serial0 -> ttyAMA0 means the configuration is successful.
Serial Port Reception Test#
Receiving data (echo function)
# -*- coding: utf-8 -*
import serial
import time
# Open the serial port
ser = serial.Serial("/dev/ttyAMA0", 9600)
def main():
while True:
# Get the received buffer characters
count = ser.inWaiting()
if count != 0:
# Read the content and echo
recv = ser.read(count)
ser.write(recv)
# Clear the receive buffer
ser.flushInput()
# Necessary software delay
time.sleep(0.1)
if __name__ == '__main__':
# If this file is run as a script
try:
main()
except KeyboardInterrupt:
# Exception handling
if ser != None:
ser.close()
If import serial
throws an error, install the python3-serial
module
sudo apt-get install python3-serial
Serial Port Transmission Test#
import serial
import time
ser = serial.Serial("/dev/ttyAMA0", 9600)
ser.flushInput() # Position 2
ser.write("begin".encode("utf-8")) # Send the string "begin" through the serial port
def main():
while True:
count = ser.inWaiting()
if count != 0:
recv = ser.read(count)
ser.write("Recv some data is : ".encode("utf-8"))
ser.write(recv)
ser.flushInput()
time.sleep(0.1)
if __name__ == '__main__':
main()
Installing the Virtual Keyboard#
sudo apt-get install matchbox-keyboard
sudo apt-get install matchbox-keyboard --fix-missing
We can see the successful installation in the following image:
Installing PyQt5 on Raspberry Pi#
-
Change the software source: sudo nano /etc/apt/sources.list
-
Change this software source: deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi
-
Update: sudo apt-get update
-
Install PyQt5: sudo apt-get install python3-pyqt5 (pay attention to the capitalization, I didn't make a mistake)
-
Start python3
-
Enter import PyQt5 (pay attention to the capitalization, I didn't make a mistake)
-
If there are no errors, it means the installation was successful.