Tangwx

Tangwx

博客网站

Raspberry Pi Environment Configuration

Raspberry Pi Environment Configuration#

Burning the Image#

image-20230217202807072

After burning is complete, power on the device.

Enabling VNC#

Preferences -> Raspberry Pi Configuration
Select Interfaces -> Enable the VNC button

image-20230217203141423

image-20230217203229798

After enabling, use VNC tool to connect to the Raspberry Pi and display the virtual desktop.

image-20230217203058361

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.

image-20230217204854148

image-20230217204928814

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:

image-20230217205312764

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.

image-20230217210932567

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

image-20230218102819936

sudo apt-get install matchbox-keyboard --fix-missing

image-20230218102854604

We can see the successful installation in the following image:

image-20230218103022698

Installing PyQt5 on Raspberry Pi#

  1. Change the software source: sudo nano /etc/apt/sources.list

  2. Change this software source: deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi

  3. Update: sudo apt-get update

  4. Install PyQt5: sudo apt-get install python3-pyqt5 (pay attention to the capitalization, I didn't make a mistake)

    image-20230218105841356

  5. Start python3

  6. Enter import PyQt5 (pay attention to the capitalization, I didn't make a mistake)

    image-20230218105858552

  7. If there are no errors, it means the installation was successful.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.