Python Forum
Raspberry + RS485 shield | pySerial
Thread Rating:
  • 3 Vote(s) - 2.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Raspberry + RS485 shield | pySerial

I am using a RS485 shield for Raspberry v3 together with the pySerial class provided by Python to communicate with a device through the serial port.
The device I am communicating with, uses the S-Bus protocol and has a physical output with D+/D- and ground.
The device has a proprietary software that displays, in hex, what is broadcast and received on the device and on any other supplementary devices attached to it.
So, regarding topology, I went from the device's S-Bus port into the RS485 shield attached to the Raspberry.
At first, I was not sure that I will receive anything while listening to the port since I wasn't sure of the compatibility. Had to try it tough..

After I did the setup and made a little code in python using the pySerial class I was able to receive the same messages that are shown in the proprietary software of the device.
As a mention, in python, I had to encode the message received, to hex to have an exact match with what the proprietary software was displaying.

On the proprietary software I can give commands to the device and this device can trigger, from example, a relay.
While giving such a command and while monitoring the communication between the Raspberry and the device I "recorded" all the messages, in hex, that were transmitted on the S-bus protocol, including the code sent from the proprietary software to the device to trigger the relay.

My goal is to send the same command (as hex code) that triggers the relay from Raspberry and not from the proprietary software; and to work of course :D.
My logic (faulty or not ) was that sending the same hex code as the proprietary software sent to the device to trigger the relay should have the same effect. This seems like Captain Obvious.

Unfortunately, it didn't happen.
The message leaves the Raspberry (the led on the RS485 shield confirms it) but the relay isn't triggered and nothing is shown on the proprietary software display.
As a mention, I managed to command the relay with commands from the Raspberry to the device on the RS485 port also present on the device.
I am trying to make the commands work through the S-Bus port since it will benefit more.

Any ideas, hints of what could cause that ? Things to try ?

Serial Novice :D
Some things come to mind.
Check the protocol on your serial port, you are mainly interested in number of databits
This only matters if the command that triggers the relay uses bit 7 (numbered 0-7)
for any purpose. It is possible to set databits to 7 or 8, with or without parity.

This is only important if the 7th bit is used, in whichcase, set data bits to 8, no parity.

Also, for your edification, hex is just the representstion used.

0101 0101 binary
is the same as 0x55 hex
is the same as 85 decimal.
is the same as 125 octal
Many thanks for the insight.

Data bits were set to 8 with no parity. No luck.
I will continue trying playing with the connection, see if I get anywhere.
Does the baud rate match on both ends of the connection?
That's the transfer speed and if it doesn't match you'll just see garbage on the receiving end
(if anything at all)

Also, the fact that the led comes on only indicates data at the source, and nothing about it's format.

I would suggest using putty (available on line free) on the receiving end. that way you can play with the baud rate parity, etc
without changing the software (until after you know what you're dealing with). In addition, since you indicate that only the data
lines are being used, I expect something like full duplex may be used for hand shaking, which may or may not be the case.
Sorry for the awol. I've been meddling with other stuff. Thanks for the additional insight.

About the baud rate I'm pretty sure it is the same at both ends of the connection. I have some basic information, a document, about the serial communication used by the device, including the baud rate and I am using that for my python serial port configuration.
Unfortunately, I don't have any tools to measure it.

Regarding the integrity of the message I send from my RPI to the device, I tried to see what actually reaches the equipment by doing the following setup ( I think you will need to click on the image to enlarge it)
[Image: l6JKU4R.png]
I sent my message from the RPI to Device 1 and with the sniffer on PC (that was connected through serial with Device2 | Device 2 was connected to Device 1 | No link from RPI to PC) I saw on the PC the exact message sent without any noticeable distortion.
That made me believe, that a theoretically correct code, reaches Device 1.
That's the best I could do for now and with the tools I had.

More tests are coming with different settings. Will post any worthy failures and/or breakthroughs.

Thanks again !
In addition to Lars60+'s mention of baud rate, data bits and stop bits, many times you also need to set the flow control (or handshaking).  This can either be software or hardware controlled.  Software being Xon (ascii character 17) and Xoff (ascii character 19). Hardware makes use of pins on the chip, CTS (Clear to Send), DTR (Data Terminal Ready) and RTS (Ready To Send).

They make inline testers for RS232, RS422 and RS485 running from relatively cheap to outrageously expensive, depending on your needs and pocketbook.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Don't forget there are software testers as well:

For example:
and more

Possibly Related Threads…
Thread Author Replies Views Last Post
Photo Raspberry PI writing to RS485 driver, DIR pin not holding state zazas321 2 568 Oct-30-2020, 06:23 AM
Last Post: zazas321
  Lib PySerial Pelathaon 2 776 Jul-07-2020, 12:41 PM
Last Post: DashOrion
  pySerial why do i need \r Mad_Max 1 773 May-26-2020, 01:29 AM
Last Post: Larz60+
  help with code for USB-RS485 korenron 2 1,537 May-12-2019, 02:40 PM
Last Post: korenron
  PySerial Soichiro 1 3,722 Jun-09-2017, 03:56 PM
Last Post: DeaD_EyE
  I need help with pySerial oz1sej 9 18,582 Apr-13-2017, 06:12 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020