Issue with Receiving Data from Raspberry Pi Pico via RS485

Hello Forum Members,

I’m working on a serial communication project where I’m facing a few challenges. In the project, I’m trying to establish communication using the RS485 protocol between a Raspberry Pi 4 and a Raspberry Pi Pico.

Here are the basic code structures I’m using:

Raspberry Pi 4:

python code

import serial

ser = serial.Serial('/dev/serial0', baudrate=9600, timeout=1)  # Serial port settings

def read_data_from_slave():
    data =  # The first byte contains the slave address
    slave_address = int.from_bytes(data, byteorder='big')  # Get the slave address
    data =  # Get the remaining data
    return slave_address, data

    slave_address, data = read_data_from_slave()  # Receive data from the slave device

    print(f"Slave Address: {slave_address}")
    print(f"Received Data: {data.decode()}")
except KeyboardInterrupt:
    ser.close()  # Close the serial port when the program is terminated

Raspberry Pi Pico:

python code

import uos
import uos, machine
import ustruct as struct
from machine import Pin
import time

uart_tx = machine.Pin(4)  # TX pin: GPIO 0
uart_rx = machine.Pin(5)  # RX pin: GPIO 1

# Create a UART object
UART = machine.UART(1, baudrate=9600, tx=uart_tx, rx=uart_rx)

def send_data(data):

slave_address = 7  # Set the slave address as 2

def send_data_to_master():
    send_data(struct.pack('b', slave_address))  # Send the slave address
    send_data(data)  # Send the data

while True:

Currently, I’m facing an issue in the project: I’m unable to receive data from the Raspberry Pi 4 device. The serial communication codes seem to be working correctly, but the data receiving function is not yielding the expected results. Does anyone have any insights on this?

Thank you!

Hi there,Ridvan_Carti
So RS-485 hardware is balanced with a +/- for both transmit and receive Check your polarity , afaik
it will appear to work but the data will be inverted. Also is it full duplex(4-wire) or Half duplex(2-wire) connection, any flow control? Do you mean RS-232 ? are you using converters?
maybe a picture of the setup on the bench/desk?

GL :slight_smile:

really good link for Arduino RS-485 Using Arduino to talk via RS485

Are you using the 2-Channel RS485 Module for Raspberry Pi Pico, SP3485 Transceiver, UART To RS485?