I have a setup in which a raspberry pi is going to talk to a bunch of arduinos via RS485. All arduinos have those max485 breakout boards and the Rpi has a usb to 485 module.
I have the communication working for the most part. But still I have some difficulties. I am currently testing on my computer with about ~25cm wire for the bus. I noticed that on 115200BPS I'd get distorted transmissions. I dont know if that is normal I have not deliberately used a 120R on the one Rs485 module. (I dont know atm if they have those by default). On 9600BPS I have no distortions. Not that I can see.
Prior of sending a message I digitalWrite the transmission direction pin high. And I use a short timer to write it back to low. I am aware that this is not the best way to do this.
At first I tried to call this code continously:
if( Serial.availableForWrite() == 0 ) digitalWrite( transmissionLine, LOW ) ;
I thought that this did not entirely work, though ofcourse it may have been something different causing me the problems.
I still believe that it is the right approach and that I did something else wrong. But I am still wondering: Is this the right approach? And if not, what do people usually do with the transmission direction pins of 485 devices?
The data transmissions are only 3 bytes in size each, so I am ok to use the blocking flush() function if that does do the trick. The tasks of the arduinos are not extremely time critical and delays of 3 bytes on 9600BPS is deemed tolerable.