Skip to main content

RS485

This section introduces how to use the RS485 interface functions on the Raspberry Pi, laying the foundation for subsequent project development.

Enabling Interface Configuration

  • Enable the RS485 interface (disabled by default)

  • Edit the config.txt file

    sudo nano /boot/firmware/config.txt
  • To use RS485, add the following lines (these correspond to the 4 communication interfaces):

    # Corresponds to CH0 -> GPIO14/15 -> ttyAMA0
    # Semi-automatic control pin TXDEN: GPIO10 (hardware default is fully automatic, no need to control this pin by default)
    dtoverlay=uart0-pi5
    # Corresponds to CH1 -> GPIO4/5 -> ttyAMA2
    # Semi-automatic control pin TXDEN: GPIO27 (hardware default is fully automatic, no need to control this pin by default)
    dtoverlay=uart2-pi5
    # Corresponds to CH2 -> GPIO8/9 -> ttyAMA3
    # Semi-automatic control pin TXDEN: GPIO7 (hardware default is fully automatic, no need to control this pin by default)
    dtoverlay=uart3-pi5
    # Corresponds to CH3 -> GPIO12/13 -> ttyAMA4
    # Semi-automatic control pin TXDEN: GPIO21 (hardware default is fully automatic, no need to control this pin by default)
    dtoverlay=uart4-pi5
  • To enable all 4 RS485 channels simultaneously:

    # Enable CH0 ~ CH3 RS485 channels at the same time
    dtoverlay=uart0-pi5
    dtoverlay=uart2-pi5
    dtoverlay=uart3-pi5
    dtoverlay=uart4-pi5
  • After modification, reboot the Raspberry Pi, then the program can drive RS485 normally

    sudo reboot