16pt LV input card to Raspberry pi over RS485

nbeaulieu3

Member
How do I set up this communication to monitor status of some push buttons. Setting baud rates, reading status, even pointing me to a manual would be very helpful
 

alexburcea

Moderator
Staff member
Do you need to communicate between Raspberry and 16LV-Inputs card? If this is the case what type of RS485 adapter do you use?
 

nbeaulieu3

Member
I have a Waveshare RS485 CAN HAT mounted on the GPIO pins. Apparently, the Raspberry serial port name is dev/ttyAMA0, but during the setup procedures I was only ever able to see serial0 and serial1. ttyAMA0 never showed up in the list even though the file is in the directory
 
Last edited:

nbeaulieu3

Member
If I have the following Python code and assuming my Address, Port, Baud Rate and Functioncode are correct what output should I expect (other than Checksum and various other errors)?

import minimalmodbus

MODBUS_ADDRESS = 0x01
RS485_PORT = '/dev/serial0'
BAUDRATE = 38400

modbus_device = minimalmodbus.Instrument(RS485_PORT, MODBUS_ADDRESS)
modbus_device.serial.baudrate = BAUDRATE
modbus_device.serial.parity = minimalmodbus.serial.PARITY_NONE
modbus_device.serial.stopbits = 1
modbus_device.serial.bytesize = 8
modbus_device.serial.timeout = 1

minimalmodbus.debug = True

print(f"Modbus Address: {MODBUS_ADDRESS}")
print(f"RS485 Port: {RS485_PORT}")
print(f"Baud: {BAUDRATE}")

try:
# Attempt to read input registers
response = modbus_device.read_register(0, 0, functioncode=4) # Adjust function code/register as needed
print(f"Response: {response}")
except Exception as e:
print(f"Error: {e}")
 

alexburcea

Moderator
Staff member
Hi,

The port settings are correct concerning the 16-LV-INPUTS, these are the default settings, 38400 8N1 and address 1(if all add dipswitches are OFF).
About the Python code, we use a USB-TO-485 adaptor connected to a PC to test it and QModMaster software to test it. If the Waveshare HAT is connected to the Raspberry serial port you should use "dev/ttyAMA0" because depending on your Raspberry model and os sometimes serial0 does not work (personal experience but not enough research). I assume you enable the Raspberry serial port as instructed by Waveshare documentation.
One more thing is that the cards implement only the "Discrete Inputs" on the Modbus protocol and if you try to read other objects like coils or holding registers, you will get errors. Unfortunately, the document with Modbus addresses is not yet available but I will finish and publish it today.

Alex.
 

alexburcea

Moderator
Staff member
A little update: Assuming you are using the Sixteen LV Digital Inputs version 3.0 because this is the one with Modbus, we are a little behind with the drivers, you will be unable to change the settings for the Modbus and access new features of the card like watchdog, counter reading, frequency reading, etc.
Give us a few days to update the drivers. The card is retro compatible with the old drivers so you can use them until we release new ones or updated versions of these.
 

nbeaulieu3

Member
Hey, thank you for you interest in this matter. I'm not new to computer controls (PLC mainly) but I am more than new to the Raspberry Pi and Python world

with
MODBUS_ADDRESS = 0x01
RS485_PORT = '/dev/ttyAMA0'
BAUDRATE = 38400
The Error Message I get is Write timeout...

With
MODBUS_ADDRESS = 0x01
RS485_PORT = '/dev/serial0'
BAUDRATE = 38400
The Error Message I get is No communication with the instrument (no answer)

Which RS485_PORT setting is getting us closer to reading the Discrete Inputs (which, is all I want out of the Input card - I'll have 10 switches that I want to monitor for state change as quickly as possible)

To what version of the 16 pt LV Digital Input card I have is a mystery to me - How can I check. My Pi unit is Model 4b

Now the loaded question. I'm about to ask a supplier (you) if their product is better than the Waveshare product that I have. I see you have your own RS485 comm card for the Raspberry Pi

Thank you Alex

Norm
 

alexburcea

Moderator
Staff member
The card version is printed on the top side of the PCB. Yes, we have RS485 on our communication HAT's, and almost all our I/O cards have an RS485 transceiver which can be used either with the Raspberry serial port or by the local processor to implement Modbus RTU. I do not think our implementation is any better than Waveshare. I think you have to take one step at a time and test the card with a known working Modbus master software. It is hard for me to help you with the python modbus library since I never use it. I remember I tested the Modbus on one of our cards with Node-RED but never with Python.
 

nbeaulieu3

Member
Aha! I now see on the top side lower left corner V1.0. Are you saying to look around in Node-RED for a working model of the RS485 comms and then try using Python?
 

alexburcea

Moderator
Staff member
If it is 1.0 does not have Modbus interface. Please send me pictures with the top and bottom of the card, if not here over email at support.
 

nbeaulieu3

Member
Thank you for the clarification.
If I use I2C what are the limits if any regarding the length of my comm cable. Also, I have some eight relay output cards VER5.3 for a future project. Will they have the same RS485 limitations
 

alexburcea

Moderator
Staff member
The I2C port is not made to be out of the PCB (inter-integrated circuits communication) but It might work.
The 8-relays, no matter the version, do not have Modbus.
If you need to control relays and read digital inputs over Modbus I recommend you 4-relays-4-inputs or if you have multiple inputs and outputs you can buy the last versions of the 16-LV-inputs and 16-RELAYS (if you need to switch up to 24V)
 

nbeaulieu3

Member
Im afraid you are telling me that I currently have 4 input paper weights and 3 relay output paper weights. I have 3 hobby projects in my near future. Each of them require remote input collection and remote output control. From all I have gathered as I was researching these projects was that the raspberry pi can communicate to these remote cards via some sort of bus be it I2C or RS485. Am I dead in the water or do compatible cards exist. The site has 16 pt LV input cards that say new in Ver 3 that they will work via RS485 Modbus ( the photos of the device are photos of the card I currently have v1.0). I purchased these cards less than 1 year ago. Kinda not very happy
 

alexburcea

Moderator
Staff member
I am sorry for the situation but we did not do a false advertise, we sold 16-LV inputs v1.0 until a few months ago, and we still developing the drivers for the new version. Let's see how we can solve the problem. How big needs to be the distance between Raspberry and the card? If is a hobby project and you keep an eye on it you might try to run the I2C port on a cable.
 

nbeaulieu3

Member
I don't blame you or Sequent. I appreciate your help tremendously. Bad news is one thing but getting it as soon as possible is priceless - as backwards as that sounds they are words I live by. I briefly looked at I2c until my searches said UART might be better. I've just rewired for UART and am about to do some configuration in the pi unit. Is this something you and this thread can assist with.

Further clarification, the new input cards v3.0 can use RS485 with Modbus? Are there Output cards that can also or can I Modbus to the input card and have the Output HAT sit on the Input card GPIO pins
 
Top