RS 485 Wind sensor ?

Hello everyone, I would like to write here hoping to find help. I am currently working on a meteorology project and I am blocked by 2 sensors which are both for the wind. I cannot read the data (speed and management). In the serial Monitor I always get an E2 error and I really don't understand why? I don't have a good level in this subject and that's why I'm appealing to the population. I tried to give you an idea of ​​my connection, I hope you enjoy it :), Thank you to everyone who will help me finish this project.

#include <SoftwareSerial.h>
#include <ModbusMaster.h>

// Définir les broches de SoftwareSerial
SoftwareSerial RS485Serial(9, 10); // RX, TX

// Définir les instances pour deux modules RS485
ModbusMaster node1;  // Vitesse du vent
ModbusMaster node2;  // Direction du vent

// Définir les broches de contrôle DE/RE pour chaque module
const int DE_RE1 = 8;  // Contrôle du Module RS485 1
const int DE_RE2 = 13; // Contrôle du Module RS485 2

void setup() {
  Serial.begin(115200);

  // Initialiser la communication RS485
  RS485Serial.begin(4800); // Assure-toi que cela correspond à la configuration du capteur

  // Initialiser les instances Modbus avec SoftwareSerial
  node1.begin(1, RS485Serial); // Capteur de vitesse du vent (adresse 0x01)
  node2.begin(1, RS485Serial); // Capteur de direction du vent (adresse 0x01)

  // Configurer les broches de contrôle comme sorties
  pinMode(DE_RE1, OUTPUT);
  pinMode(DE_RE2, OUTPUT);

  // Commencer en mode réception pour les deux modules
  digitalWrite(DE_RE1, LOW);
  digitalWrite(DE_RE2, LOW);
}

void enableTransmit(int module) {
  if (module == 1) {
    digitalWrite(DE_RE1, HIGH);
  } else if (module == 2) {
    digitalWrite(DE_RE2, HIGH);
  }
}

void enableReceive(int module) {
  if (module == 1) {
    digitalWrite(DE_RE1, LOW);
  } else if (module == 2) {
    digitalWrite(DE_RE2, LOW);
  }
}

void loop() {
  uint8_t result;
  uint16_t data[2];

  // Lire les données du capteur de vitesse du vent
  enableTransmit(1);
  result = node1.readHoldingRegisters(0x0000, 1); // Registre 40001
  enableReceive(1);

  if (result == node1.ku8MBSuccess) {
    Serial.print("Vitesse du vent : ");
    Serial.print(data[0] / 10.0); // La valeur retournée est 10x la vitesse réelle
    Serial.println(" m/s");
  } else {
    Serial.print("Erreur Module 1: ");
    Serial.println(result, HEX);
  }

  delay(2000);

  // Lire les données du capteur de direction du vent
  enableTransmit(2);
  result = node2.readHoldingRegisters(0x0000, 2); // Registres 40001 et 40002
  enableReceive(2);

  if (result == node2.ku8MBSuccess) {
    Serial.print("Direction du vent (0-7) : ");
    Serial.print(data[0]); 
    Serial.print(", (0-360°) : ");
    Serial.print(data[1]);
    Serial.println(" °");
  } else {
    Serial.print("Erreur Module 2: ");
    Serial.println(result, HEX);
  }

  delay(2000);
}

Wind Speed Sensor(RS485).docx.pdf (986,5 Ko)
Wind direction Sensor(8 direction RS485).docx.pdf (1,8 Mo)

According to your schematic you have 2 ( why 2?? ) rs485-to-ttl boards which you connect in parallel ( RO and DI ) to the arduino.

Sorry, you can't connect the 485 boards like that, you don't even need two rs485 boards.
Use only one board, and assign different ids to your sensors, so the first is id=1 and the second is id=2 ( for example ), in this way you can address each sensor individually ( and will not short the DO outputs together, which is not good ), connect both sensors on the same rs485 line ( A and B )

Ah I thought that I couldn't meter the 2 sensors on a single card, and I connected them like this in order to save pins for the other sensors, then in the code I made sure that 1 reads them and that others send data so as not to disturb the data. So I just have to remove an RS 485 then transfer the 2 sensors to one? And these just connect the sensor wires where there is the green thing, I don't know what it's called?

And for the code does it seem correct ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.