16 LV input card v3.0 connected via RS485 Modbus

nbeaulieu3

Member
I'm having trouble trying to configure this setup to read status of my switch inputs. From documentation I cant seem to get it configured properly - specifically the instructions for the input card are all showing the input card v1.0
 

nbeaulieu3

Member
The photo files were large. I sent them to "support@sequentmicrosystems.com" in an email. As you might see in the photos, I have a very short test scenario set up. Im trying to use RS485 Modbus as my end layout will be about 5 meters distant. What should the DIP switches be set at and which RS485 terminals must I use. Also I seem to be getting some form of reply when I try to read the input status. I only need the switch statuses what form and arguments does the read instruction need to read the inputs?
 

alexburcea

Moderator
Staff member
Hi,

I recommend using the GND for the RS485 connection and enabling the termination resistors. At the 16-LV-inputs card, the only switch that needs to be turned ON is the terminator one. For the two serial ports you need to place a jumper on the J2 header to enable the termination resistor. Since the drivers for the 16-LV-inputs card that let you change the Modbus settings are under development, you can use the Modbus with the following settings 38400/8/N/1, and slave address 1. The card implements only discrete inputs mapped on Modbus addresses 0x00 to 0x0f (register addresses 10001 to 10016). New drivers and documentation will be available soon.
 

nbeaulieu3

Member
this is some test code that I would expect to return a response of something / anything

from pymodbus.client.sync import ModbusSerialClient as ModbusClient

# Configure Modbus client
client = ModbusClient(
method='rtu',
#port='/dev/serial0', # Replace with your serial port
port='/dev/ttyAMA0', # Replace with your serial port
baudrate=38400, # Match the card's baud rate
parity='N',
stopbits=1,
bytesize=8,
timeout=1
)
if client.connect():
print("Connected to Modbus device.")
slave_id = 1 # Update to match your device
input_register = 1 # Starting register

try:
response = client.read_input_registers(input_register, 1, unit=slave_id)
if response.isError():
print(f"Error reading registers: {response}")
else:
print(f"Register values: {response.registers}")
except Exception as e:
print(f"An error occurred: {e}")
finally:
client.close()
else:
print("Failed to connect to Modbus device.")

This is what I get:-

Connected to Modbus device.
Error reading registers: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 2 bytes (0 received)
 

alexburcea

Moderator
Staff member
I never used the python library but as I understand you read an input register and the card implements only discrete inputs (in the current firmware version). Try to read discrete inputs. We used QModMaster with a USB to 485 converter on a Windows PC to test the firmware.
We are working at the drivers to be able to change the port settings and Modbus address and we will test your setup in the process.
 

nbeaulieu3

Member
First off, I don't know when you sleep or rest, but I appreciate your help in this matter.

I have tried many things many different ways and am getting more lost as I go. I cant find any manual or direction as to what command instructions and the relevant arguments are required to read the card. I might be using the wrong commands or even wrong code as I have mixed and jumbled things as I have experimented. Like I said I think i'm just getting more lost

I have a small program that tries to read only the discrete inputs but I get the same type of errors.

This is what gets returned when I run the following program:
Connected to Modbus device.
Error reading inputs: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 2 bytes (0 received)

Here is the python code:-

from pymodbus.client.sync import ModbusSerialClient as ModbusClient

# Configure Modbus client
client = ModbusClient(
method='rtu',
port='/dev/ttyAMA0', # Replace with your serial port
baudrate=38400, # Match the card's baud rate
parity='N',
stopbits=1,
bytesize=8,
timeout=1
)

# Connect to the device
if client.connect():
print("Connected to Modbus device.")

# Replace `slave_id` and `input_register` with the specific addresses
slave_id = 1 # Modbus ID of your input card
input_register = 1 # Starting register of the inputs

try:
# Read 16 discrete inputs
response = client.read_discrete_inputs(input_register, 16, unit=slave_id)
if response.isError():
print(f"Error reading inputs: {response}")
else:
print(f"Input states: {response.bits}")
except Exception as e:
print(f"An error occurred: {e}")
finally:
client.close()
else:
print("Failed to connect to Modbus device.")
 

alexburcea

Moderator
Staff member
Hi,
It is 1:00 PM here so is ok.
Give me a few hours maybe a day to test your setup and I come back with the results.
 

alexburcea

Moderator
Staff member
Hi,

I just finished testing your setup with success. Software, I just modified the port name to "/dev/ttyS0" and the "input_register = 0" and then used it as you shared it. The output reflects the input states and looks like this: Modbus output.jpg

Hardware: I use the 2 serials RS485 port connected with 3 wires (one to one, G A B) with 3pin 16-LV-Input port.
 

nbeaulieu3

Member
OK! Turns out I was dealing with a Two Serial Port HAT that is bad. I have 4 of your units they all work except that one. I have some Waveshare RS485 units ( we had this discussion during the first week of December) that also work now that I have v3.0 input card.

ttyS0 didn't work but ttyAMA0 did! Next question is how do I get all 16 inputs to display. The current output is:
Connected to Modbus device.
Input states: [True, False, False, False, False, False, False, False]

Also, I didn't have to use the 3 pin plug - the 2 pin A and B along with GND and +5v on the other side of the card also work.

Future business. I will be in the market for some relay output cards that can communicate with RS485 Modbus. Which products do you recommend?

Thank you so much!! As frustrating as it has been - YOU ARE A MACHINE!
 

alexburcea

Moderator
Staff member
Try to make two readings, one from address 0 and one from address 8. I am guessing the the modbus library does not support reading of more than 8 discrete inputs.
Could you send me pictures with the Two Serials card that is not working?

Depending on the voltage and current ratings you need, you can choose between 3- Relays, 4-relays, or 16-relays.
 

nbeaulieu3

Member
Try to make two readings, one from address 0 and one from address 8. I am guessing the the modbus library does not support reading of more than 8 discrete inputs.
Could you send me pictures with the Two Serials card that is not working?

Depending on the voltage and current ratings you need, you can choose between 3- Relays, 4-relays, or 16-relays.
ive been trying the second reading but havent any success yet. It is only one card that is not working I'll send you photos
 

nbeaulieu3

Member
I've tried many different ways to get the inputs 8 thru 16 read but to no avail. It would be helpful to know what the Modbus interface is setup for. As in where the data and what ever else is transferred is located. The guessing game is starting to wear me out
 

alexburcea

Moderator
Staff member
It looks like we have a firmware bug because I tested with the qModeMaster and was unable to get correct readings from inputs 9 to 16.
Let me dig into it and get back to you.
 

nbeaulieu3

Member
While you're in the firmware check out why the input indicator LEDs are reversed for all input pairs 1 and 2, 3 and 4, 5 and 6, etc indicators are swapped
 

nbeaulieu3

Member
First off thanks for all you have done

This is what I have tried. Both times I get the same error. I downloaded the git stuff first and the card is plugged into the pi unit 2x20 pins and at Address 0 ie all switches in off position:-

pi@raspberrypi:~/16inpind-rpi/update $ ./update 0
You are ready to update the firmware on your board.
Your Raspberry Pi must be connected to the internet.
We strongly recommend to disconnect all outputs from the board since they can change state unpredictably.
Type "yes" (without quotes) to continue or anything else to quit:
yes
Failed to open the bus.No board detected!
pi@raspberrypi:~/16inpind-rpi/update $ ./update 1
You are ready to update the firmware on your board.
Your Raspberry Pi must be connected to the internet.
We strongly recommend to disconnect all outputs from the board since they can change state unpredictably.
Type "yes" (without quotes) to continue or anything else to quit:
yes
Failed to open the bus.No board detected!
 
Top