I have Raspberry 2B with Raspbian Jessie. I want my Raspberry Pi can communicate with some sensors via RS-485 interface. I tried to use three types of adapters:
- USB-RS-485 adapter;
- USB-RS-232 adapter with RS-232 to RS-485 converter;
- MAX485.
At first I tried to communicate with the sensors from my PC (Windows) and everything works just fine, serial ports and adapters work perfectly. Next I tried to repeat this on my Raspberry Pi.
A have done all preparations on the Raspberry Pi to communicate via serial port and RS-485 (using this article and others in the Internet). Then I wrote a communication script with Python (and Mono + C#, and C++ but there was the same problem). There is Python code for serial port connection, sender and receiver:
import serial
import time
# Such parameters are required for the sensors so I use them
receiver = serial.Serial(
port='/dev/ttyUSB0',
baudrate = 9600,
parity=serial.PARITY_EVEN,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.SEVENBITS,
timeout=1
)
while 1:
x = receiver.readline()
print x
# -----------------------------------
sender = serial.Serial(
port='/dev/ttyUSB1',
baudrate = 9600,
parity=serial.PARITY_EVEN,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.SEVENBITS,
timeout=1
)
while 1:
sender.write('Test message')
time.sleep(1)
When I connect both adapters to the Raspberry (to make an echo) this script works fine, I can send and receive messages in both directions. It's OK!
THE PROBLEM: when I try to connect the Raspberry with the sensors or with the PC with same Python script the Raspberry can only receive messages from the outside but it can't send messages outside (with different parameters, program languages, etc.). They are just lost. There are no any exceptions, error codes or something else.
Does anyone know what could be the problem? Help me please! Googling does not help. Maybe the problem is in permissions? Maybe I forgot about some settings of serial ports? Or do I use wrong devices (but they work with my PC)?