Hi to everyone,
What I want to do, in the simplest way is as ,
I have multiple arduinos mega joined with MAX485 module in serial.
I have joined Arduino + MAX485 + other parts needed on a single pcb.
On every arduino there is a led connected to pin 12 .
I am sending via serial port “002R011H” or “002R011L” data using RS485 protocol from my computer.
When the Max485 module connected to Arduino mega 2560 receives data, if it is “002R011H” , the led connected to pin 12 turns on.
If the data received is “002R011L“ the led connected to pin 12 turns off.
This works fine with the following sketch.
#include <SoftwareSerial.h> // Using software serial library
#define SerialRX 10 // Serial Receive pin (RO) (A1 10 55) Is working only on 10 or 11 pins .
// But I want to use it on A1 and don't work
#define SerialTX A0 // Serial Transmit pin (DI) (A0 or 11 or 54)
#define SerialTxControl A2 // RS485 Direction control //(DE & RE) pin to pin A2 or 9 or 56
#define RS485Transmit HIGH // to open direction of MAX485 module
#define RS485Receive LOW // to close direction of MAX485 module
SoftwareSerial RS485Serial(SerialRX, SerialTX); // RS485 connection parameters
// Starting Declaration of Leds names and pins
const int ledR011 = 12 ; // the number of the LED pin
// Finish Declaration of Leds pins
void setup()
{
pinMode(SerialTxControl, OUTPUT); // SSerialTxControl as output
pinMode(SerialRX,INPUT) ; // SerialRX as input
// Starting PinMode state
pinMode(ledR011, OUTPUT); // ledR011 as output
}
void loop()
{
digitalWrite(SerialTxControl, RS485Receive); // RS485 SerialTxControl is in receive mode
RS485Serial.begin(9600); // RS485Serial start in 9600 baudrate
Serial.begin(9600); // Serial start in 9600 baudrate
String x = ""; // String x is the incoming data and is reseted to begin
if (RS485Serial.available()) // Controlling if RS485Serial is available
{
x = RS485Serial.readString(); //incoming data is equal to string x
RS485Serial.flush(); //waiting to receive all incoming data
RS485Serial.setTimeout(25); // waiting a while before going to next step
}
if ( x == "002R011H" ) // If incoming data is equal to 002R011H
{
digitalWrite(ledR011 , HIGH); // ledR011 is on
}
if ( x == "002R011L" ) // If incoming data is equal to 002R011H
{
digitalWrite(ledR011 , LOW); // ledR011 is off
}
}
However, if I try to use the SerialRX (RO) connection with a pin other than pins 10 or 11, is not working.
Normally I can use pins 10 or 11, but using pin A1 is more suitable for my pcb design.
Am I missing something for use the pin A1, or should I use pins 10 or 11 to use the MAX485 module ?
Thanks in advance.