RS485 on Sixteen LV Digital Inputs 8-Layer Stackable HAT

wisey

New member
I'm trying to setup the rs485 on the hat and the documentation says to install a jumper but it's not marked on the board clearly?

1690932709974.png


Also how do I determine the comport , I'm looking at using the following python code example for now to try get it talking:


Python:
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
from pymodbus.exceptions import ModbusException

client = ModbusClient(method='rtu', port='COM PORT ??', baudrate=9600, stopbits=1, parity='N', bytesize=8, timeout=1)

try:
    if not client.connect():
        print("Unable to connect to the Modbus server")
        exit()

    slave_address = 1
    register_address = 0

    response = client.read_holding_registers(register_address, 1, unit=slave_address)

    if not response.isError():
        print(response.registers)
    else:
        print("Error reading data: ", response)

except ModbusException as e:
    print("Modbus error: ", str(e))

except Exception as e:
    print("Unexpected error: ", str(e))

finally:
    client.close()
 

alexburcea

Moderator
Staff member
Hi,
It looks like ypur jumper is not installed. You need to make a short circuit between 2 unmarked holes on the pcb.
The serial port is /dev/tty0 or /dev/serial0 but you have to enable the port first. Look for a tutorial of serial port like this and you will figure out.
 

wisey

New member
Ok, I shorted out the 2 unmarked holes on the pcb, enabled the serial interface in raspi-config, checked the /dev/serial0 exists also /dev/serial1.
Tried a loopback test between A and B, but doesn't appear to send Hello.

Any ideas what to look for?

Code:
│ The serial login shell is disabled                       │
│ The serial interface is enabled


Code:
pi@raspberrypi:~$ python test2.py
Received: b''
pi@raspberrypi:~$


Python:
import serial
import time

ser = serial.Serial(
    port='/dev/serial0',
    baudrate=9600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1
)

try:
    ser.write(b"Hello")
    time.sleep(2)
    received_data = ser.read(5)
    print("Received:", received_data)

except Exception as e:
    print("Error:", str(e))

finally:
    ser.close()
 

alexburcea

Moderator
Staff member
Hi,

The RS485 is half duplex type of serial communication so making a short circuit between A and B will not make you to receive what you send because the transceiver can only send or receive but not both in the same time.
Try to buy a USB-to-RS485 adaptor and test with your PC.
 

wisey

New member
Just another one on the 8 HV input hat version 2.0, there is 2x RS485 , one near the SW1 and another near the GPIO pins. are they all the same? Also there is 485-term , 485-rx, and 485-tx on the dip switch, what do each of them do?
 

alexburcea

Moderator
Staff member
The 2 ports are the same, except for one have also a GND pin.
485-rx and 485-tx connects the RS485 transceiver to ta raspberry serial port, must be on if you use the port.
485-term connect a terminator on the network. You need to enable the terminator only if the device is placed at one of the network ends.
 
Top