The RS485 Shield for Arduino Leonardo is an expansion board that enables the Arduino Leonardo microcontroller to communicate using the RS485 protocol. This protocol is widely used in industrial automation, building automation, and other applications that require robust communication over long distances or in electrically noisy environments.
Pin Number | Function | Description |
---|---|---|
1 | RO (Receiver Output) | Connects to the Arduino's RX pin for data reception. |
2 | RE (Receiver Enable) | Enables the receiver when LOW. |
3 | DE (Driver Enable) | Enables the driver when HIGH. |
4 | DI (Driver Input) | Connects to the Arduino's TX pin for data transmission. |
5 | VCC | Power supply for the RS485 transceiver (5V). |
6 | GND | Ground connection. |
7 | A | Non-inverting receiver and driver output. |
8 | B | Inverting receiver and driver output. |
#include <SoftwareSerial.h>
// Configure the RS485 control pins
const int RE_DE = 2; // Example pin for controlling RE and DE
// Initialize the RS485 transceiver state
void setupRS485Transceiver() {
pinMode(RE_DE, OUTPUT);
digitalWrite(RE_DE, LOW); // Enable Receiver by default
}
// Function to send data over RS485
void sendRS485Data(const char *data) {
digitalWrite(RE_DE, HIGH); // Enable Driver
Serial1.write(data); // Send data
Serial1.flush(); // Ensure all data is transmitted
digitalWrite(RE_DE, LOW); // Disable Driver, Enable Receiver
}
// Setup function
void setup() {
Serial1.begin(9600); // Start serial communication at 9600 baud
setupRS485Transceiver();
}
// Main loop
void loop() {
// Example data to send
const char *testData = "Hello RS485";
sendRS485Data(testData);
delay(1000); // Wait for a second
}
Q: Can I use the RS485 Shield with other Arduino boards?
A: While this shield is designed for the Arduino Leonardo, it may be compatible with other Arduino boards that share the same pinout for the key communication pins. However, you may need to adjust the code accordingly.
Q: How many devices can I connect to an RS485 network?
A: The RS485 protocol allows for up to 32 devices on a single bus without repeaters. With repeaters, you can extend this number significantly.
Q: Do I need to use both A and B lines for communication?
A: Yes, RS485 communication requires both A (non-inverting) and B (inverting) lines for differential signaling, which provides noise immunity.