In episode we are going to explore how to use the MAX485 module which allows to reach communication distances over 1000 meters and which constitutes a great building block for creating a communication bus for our projects, based on a robust industry standard.
Our goal is to send serial communication data coming from one arduino to a different one.
The first connection that we will have to make is between our serial output pin, which is going to be D7 on the Arduino and the communication module’s driver input, labeled as DI. Note that we could use any other digital output pin as long as we can use it to send serial data. The purpose of this pin is to change the voltage over time in order to transmit the data. If we would measure the voltage over time at this pin, we would see the data being transmitted as a square wave, where the higher voltage at about 3.3v represents a logical 1 and the lower voltage represents a 0.
First the data will be trasmitted into one of the rs485 modules.
The rs485 communiation module will transmit this data across two cables, labeled as A line and B line. So the A line of this module will connect with the A line of the
other module. And the B line with the B line.
The incomming signal is first modified by the module. First the amplitued is magnified to VCC. Then the same signal is transmitted over A and B lines, but one line is inverted.
This technical term for transmitting an inverted duplicate of the signal is known as differential signaling and is a great noise reduction tecnique. Lets explore how it works.
Lets consider that the signal is affected by surrounding electromagnetic noise. Because the cables are close to each other, the induced disturbance will be similar on each line. So if line A gets affected by noise with the following shape, line B will be affected by a similar noise pattern.
In order to remove the noise, the receiver just needs to subtract both received signals. This way, they noise in line A minus the noise in line B will cancel out as they are very similar. And what happens with the square pulse? Let’s assume that the signal was transmited as 5 volts for high on one line, and -5 volts in the inverted version. The difference, 5 minus minus 5 would be 10, so the difference is just twice the signal.
This noise protetion is one of the reasons why we can achieve communication distances over cable up to 1000 meters with these communication modules, distances which we could not achieve if using serial data directly.
The receiver module finally accomodates back the signal to a voltage that our microcontroller can handle, so we just need to connect the reciever output labeled as RO to a digital voltage input. We will use digital input pin number 6.
So that’s basically it, to make this work we just need to add a few more connections. First, these are generic modules, but if we analyze the process one of them acts as a bus driver, transforming the incoming signal and sending it through the two lines, and the other acts as a receiver, merging the two signals back together and serving the result. These modules come with two configuration pins, labeled as driver enabled DE, or receiver enabled, RE. If they are set to high the module acts as driver, and if set to low the module acts as receiver. So we just need to connect these pins to our microcontrollers to configure the transmisison mode.
We also need to add the cables for the communication to go in the other direction. So we connect digital output pin number 7 to driver input and receiver output to digital input pin number 6 on the other arduino.
We can use an external voltage to power the RS485 modules as long as it shares the same ground. In our example we are going to use the 5V provided by the Arduino. Finally we provide a ground reference to the modules, and that’s it. In the next episode we will explore an example code for using this setup as well as to analyze the signals with a digital voltage analyzer.