Arduino Uno and multiple RS485 inputs

Good morning everyone, I have a very simple question to which I can't find the answer. Is it possible to connect two rs485 sensors to urduino uno? if so, which library do you recommend me to use and how many max485 modules should I use? thanks for your reply

The following links may give you some guidelines:

Good morning everyone, I have a very simple question to which I can't find the answer. Is it possible to connect two rs485 sensors to urduino uno? if so, which library do you recommend me to use and how many max485 modules should I use? thanks for your reply

thanks for the quick reply. the links talk about Arduino mega 2560. I would like to understand with Arduino Uno.

Yes

if so, which library do you recommend

That depends on the sensor.

how many max485 modules should I use?

You only need one.

Your two topics on the same subject are merged. Please do not cross post; it wastes people's time.

Yes.

One. Each RS485 sensor must have a unique address. All must use the same baud rate.

An RS485 library. Find one that 'turns around' the RS485 bus using the RE/DE pins of the MAX485 module.

You'll have to use software serial for the RS485 communication if you intend to use the Serial monitor to display your data, otherwise use an LCD for display, and use the Serial pins (TX, RX) to talk to your sensors.
RS-485 Basics Series
AN-1057 Ten Ways to Bulletproof RS-485 Interfaces (Rev. B)
The RS-485 Design Guide (Rev. D)
HTH

I did your googlesearch for you. This might also help:

1 Like

Generally yes, but..
1 if you can set 2 different slave addresses to your 2 sensors
2 and if your sensors support low baudrate and 8N1 configuration, you can use software serial.
3 or if you can live without serial monitor, you can use hardware serial

Thank you very much!

Thanks everyone for the replies

I've done several tests but I still have doubts. I connected, in series, two RS485 sensors to a max485 module but unfortunately when I read the data I only receive random numbers, as if the two sensors were in conflict. However, if the sensors are separate, the data is read correctly. The two sensors have different slaves.

post simple wiring scheme and code

#include <SoftwareSerial.h>

#define RE 6
#define DE 5

const byte pyranometer[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
const byte soilSensorRequest[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x0B};
byte values[8];
byte soilSensorResponse[9];
SoftwareSerial mod(7, 4);
 
void setup()
{
  Serial.begin(9600);
  mod.begin(4800);
  pinMode(RE, OUTPUT);
  pinMode(DE, OUTPUT);
  delay(1000);
}
 
void loop()
{

  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(200);

  mod.write(soilSensorRequest, sizeof(soilSensorRequest));
  
  
  digitalWrite(DE, LOW);
  digitalWrite(RE, LOW);
  delay(200);


  // Wait for the response from the sensor or timeout after 1 second
  unsigned long startTime = millis();
  while (mod.available() < 9 && millis() - startTime < 1000)
  {
    delay(10);
  }

     // Read the response from the sensor
    byte index = 0;
    while (mod.available() && index < 9)
    {
      soilSensorResponse[index] = mod.read();
      index++;
    }

      // Read the response
  byte sens = 0;
  while (mod.available() && sens < 8) 
  {
    values[sens] = mod.read();
    index++;
  }
  
    // Parse and calculate the Moisture value
    int Moisture_Int = int(soilSensorResponse[3] << 8 | soilSensorResponse[4]);
    float Moisture_Percent = Moisture_Int / 10.0;

    // Parse and calculate the Temperature value
    int Temperature_Int = int(soilSensorResponse[5] << 8 | soilSensorResponse[6]);
    float Temperature_Celsius = Temperature_Int / 10.0;

    // Transmit the request to the sensor
  digitalWrite(DE, HIGH);
  digitalWrite(RE, HIGH);
  delay(10);
  
  mod.write(pyranometer, sizeof(pyranometer));
  
  digitalWrite(DE, LOW);
  digitalWrite(RE, LOW);
  delay(10); // Give some time for the sensor to respond
 
  // Wait until we have the expected number of bytes or timeout
  unsigned long startTime1 = millis();
  while (mod.available() < 7 && millis() - startTime1 < 1000) 
  {
    delay(1);
  }
 
  // Read the response
  byte index1 = 0;
  while (mod.available() && index1 < 8) 
  {
    values[index1] = mod.read();
    index1++;
  }

  // Parse the Solar Radiation value
  int Solar_Radiation = int(values[3] << 8 | values[4]);

   
  Serial.println (Temperature_Celsius);
  Serial.println (Moisture_Percent);
  Serial.println (Solar_Radiation);
  Serial.println ("----");
  
  delay (1000);  

  
}

Unfortunately I'm not good at programming

Post your whole setup with exact wiring pin to pin.
In your code you have both on same slave address 0x01
Also I recommend to start with one, when working, add another.

The slave address starts the same but ends different, is this still a problem?
Individually I manage to make them work and they have been giving me the requested data for months. when I merge them they don't work anymore.

My only problem is being able to read the two sensors together.

Can you expand on this as I'm not sure what you are saying.

A lot of RS485 modbus devices seem to have a default device address of 01. You need to check the documentation for each of your sensors to see how to change the default address to 02 for one of your sensors.