RS485 Serial Communication Between Arduino Mega and Arduino Pro Mini
Refer: Rs485 Serial Communication Between Arduino
In this project, we will discuss about how to use Max485 for serial communication. How to effectively configure RS485 in Receive and Transmit mode. What are advantages of using RS485 protocol for serial communication and finally I will present a working model of RS485 serial communication between Arduino Mega and Arduino Pro Mini.
Rs485 Serial Communication protocol is capable of transmitting data to maximum distance of 4000m or 4km. But normally after 1200km the signal starts dropping off and eventually data starts losing. To achieve 4 km successful data transmission the carrying medium should be smooth and the length of A and B lines should be equidistance in length. External EMF(Electro Motive Force) also affects the lines carrying the data.
Rs485 Transmits two differential signals on A and B lines. Since signals are opposite in polarity(90 Degree out of Phase) they travel a well distance. Since the Signals are opposite in Polarity any external induced signal is easily filtered at the output.
- DI (Data In) Data on DI pin is transmitted on A & B lines when the module is in Transmit mode. To set Module in transmit mode make DE=1 and RE=1. DI pin is connected to Tx pin of Host Microcontroller UART.
- RE (Receive Enable) RE pin is Used to configure the module in Receive Mode.
- DE (Data Enable) DE pin is Used to Configure the module in Transmit Mode
- RO (Receive Out) Data Received on A & B pin is given to RO pin. RO pin is connected to Rx Pin of micro-controller.
- A & B (Differential Input and Output Pins) Data is transmitted and received on A & B lines.
RS485 Communication between Arduino Mega and Arduino Pro Mini
The demo project below explains how to do serial RS485 communication in practical. Serial data is send between Arduino Mega and Arduino Pro Mini, the communication is Full Duplex. Baud Rate for communication is set to 9600. Arduino mega has 4 Serial channels, I am using Serial Channel-1 for my application. Arduino Pro Mini has only one Serial channel so i am using it in my application. Pin# 8 of Arduino Mega and Arduino Pro Mini is used to control the RE(Receive Enable) and DE(Data Enable) pins of MAX485. Circuit Diagram of the Project is below.
RS485 Communication Between Arduino Mega & Arduino ProMini, Leonardo etc
Initially Mega is in Transmit mode and Pro Mini is in Receive Mode. Mega transmits character '9' on Serial Channel and then goes in receive Mode, Pro Mini Receives the character from serial line, check's it if it is '9' if '9' then in turn it sends a string "AcruxTekIsld" back on the Serial line. Mega now in receive mode receives the string and displays it on serial monitor. Pro Mini comes with a pre-mounted led connected to pin no 13. This led is toggling after ever 2 seconds.
Note the function Serial.readString() didn't work in Rs485 Communication because the Serial buffer didn't receive the terminating character. It's because the biasing and terminating resistors they are not calibrated to the impedance of the wire. That's why i have used the statement while(Serial1.available() && getdata!='d'). Which means if data is available in buffer and its not equal to 'd' then read the data. In the while fuction i am reading data one by one character from buffer. Serial.readString() works perfectively in Rs232 communication.
You can also use the code below for Arduino Uno, Arduino Leonardo, Arduino Mega etc. For using the code with Leonardo just change the occurrence of Serial to Serial1.
The Arduino Mega 2560 is a microcontroller board based on the ATmega2560. It has 54 Digital ..
* You will need a Arduino Pro Mini Programmer to program your Pro Mini.
RS485 to TTL Module (supporting EIA-485 standard) is for long range, high data rate err..