Rs-485 not working when more than two devices

hi, i'm having trouble using rs-485. It works perfectly fine when I only use 1 slave but as soon as i try to add another one, it only works half of the time. Could someone indicate where is my problem or if there is an easier way to do this ?

rs-485 Master code :

 digitalWrite(Enable, HIGH);

  Serial1.print("I");
  Serial1.print("11"); // slave id
  Serial1.print("L");
  Serial1.print("F");
  Serial1.flush();

  digitalWrite(Enable, LOW);

  delay(15);

  if (Serial1.find("i")) {
    delay(10);
    if (Serial1.read() == '1') {
      th6 = Serial1.parseInt();
      if (Serial1.read() == 'a') {
        tath6 = Serial1.parseFloat();
        if (Serial1.read() == 'p') {
          tpth6 = Serial1.parseFloat();
          if (Serial1.read() == 'f') {
          }
        }
      }
    }
  }

  digitalWrite(Enable, HIGH);

  Serial1.print("I");
  Serial1.print("16"); // slave id
  Serial1.print("L");
  Serial1.print("F");
  Serial1.flush();

  digitalWrite(Enable, LOW);

  delay(15);

  if (Serial1.find("i")) {
    delay(10);
    if (Serial1.read() == '6') {
      th6 = Serial1.parseInt();
      if (Serial1.read() == 'a') {
        tath6 = Serial1.parseFloat();
        if (Serial1.read() == 'p') {
          tpth6 = Serial1.parseFloat();
          if (Serial1.read() == 'f') {
          }
        }
      }
    }
  }

Rs-485 Slave code (both the same exept for the id) :

  if (Serial1.available())
  {
    if (Serial1.read() == 'I')
    {
      int Slave1 = Serial1.parseInt();
      if (Slave1 == Sl1)
      {
        char command = Serial1.read();
        if (command == 'L')
        {
          if (Serial1.read() == 'F')
          {

            digitalWrite(Enable, HIGH);

            Serial1.print("i");
            Serial1.print("6");
            Serial1.print(th1);
            Serial1.print("a");
            Serial1.print(tath);
            Serial1.print("p");
            Serial1.print(tpth);
            Serial1.print("f");
            Serial1.flush();

            digitalWrite(Enable, LOW);
          }
        }
      }
    }
  }

  tath = sensors.getTempC(S1);
  tpth = sensors.getTempC(S2);
  delay(10);
} 

Thanks for any help you can provide :smile:

Welcome to the forum, and thanks for using code tags on your first post (a rare event)!

We need more information: please post ALL the code, not a snippet, and post a wiring diagram showing the details of how you wired the RS485 adapters.

it only works half of the time.

I have no idea what that means. When the program runs, describe what you expected to happen, and what happened instead.

1 Like

it doesn't receive the data. when i only use one of them, it updates each 5 secondes or so but when i use another one, it takes up to 2-3 minutes between each updates. it sometimes doesn't receive it at all.

heres the full code :smile:

Master code :

#include <LiquidCrystal_I2C.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <Wire.h>

LiquidCrystal_I2C lcd(0x27, 20, 4);

#define ONE_WIRE_BUS 4

OneWire oneWire (ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

DeviceAddress RG1 = { 0x28, 0x5D, 0x72, 0x95, 0xF0, 0x01, 0x3C, 0xA0 };
DeviceAddress RG2 = { 0x28, 0x85, 0xF7, 0x95, 0xF0, 0x01, 0x3C, 0xDC };
DeviceAddress RG3 = { 0x28, 0xD0, 0x1D, 0x95, 0xF0, 0x01, 0x3C, 0x7E };
DeviceAddress RD1 = { 0x28, 0xB3, 0xE7, 0x95, 0xF0, 0x01, 0x3C, 0xFF };
DeviceAddress RD2 = { 0x28, 0x02, 0x4A, 0x95, 0xF0, 0x01, 0x3C, 0x10 };
DeviceAddress RD3 = { 0x28, 0xC1, 0x17, 0x95, 0xF0, 0x01, 0x3C, 0xAF };
int flowpin = 3;

unsigned long currentmillis;
unsigned long lastMillisScroll;

unsigned long currentMillis1;
unsigned long currentMillis2;
unsigned long currentMillis3;
unsigned long currentMillis4;

unsigned long lastMillis1;
unsigned long lastMillis2;
unsigned long lastMillis3;
unsigned long lastMillis4;

double flowRate;
volatile int count;

int menu = 1;

boolean th1 = 0; //Chambre mik
float tath1 = 0;//
float tpth1 = 0;//

boolean th2 = 0; //Chambre bibi
float tath2 = 0;//
float tpth2 = 0;//

boolean th3 = 0; //Chambre will
float tath3 = 0;//
float tpth3 = 0;//

boolean th4 = 0; //Chambre Jade
float tath4 = 0;//
float tpth4 = 0;//

boolean th5 = 0; //sal de bain du sous-sol
float tath5 = 0;//
float tpth5 = 0;//

boolean th6 = 0; //Entrée + sal de lavage
float tath6 = 0;//
float tpth6 = 0;//

boolean th7 = 0; //Bureau de cyndie
float tath7 = 0;//
float tpth7 = 0;//

boolean th8 = 0; //Chambre des maitres
float tath8 = 0;//
float tpth8 = 0;//

boolean th9 = 0; //Walking des maitres
float tath9 = 0;//
float tpth9 = 0;//

boolean th10 = 0; //sal de bain des maitres
float tath10 = 0;//
float tpth10 = 0;//

boolean th11 = 0; //Salle de bain
float tath11 = 0;//
float tpth11 = 0;//

boolean th12 = 0; //2eme etage
float tath12 = 0;//
float tpth12 = 0;//

int p1 = 46; //spa
int p2 = 48; //eaux chaudes
int p3 = 50; //sous-sol
int p4 = 52; //2eme etage
int p5 = 28; //rez-de-chausser
int p6 = 29; //garage
int p7 = 30; //vide


int v1 = 35; //Chambres des maitres
int v2 = 37; //Walking des maitres
int v3 = 39; //Salle de bain des maitres
int v4 = 41; //Entrée
int v5 = 43; //Salle d'eau
int v6 = 45; //Bureau de Cyndie
int v7 = 47; //Chambre de Bibi
int v8 = 49; //Chambre de Will
int v9 = 51; //Salle de bain sous-sol + hall
int v10 = 53; //Chambre de Mik
int v11 = 34; //Chambre de Jade
int v12 = 36; //vide
int v13 = 38; //vide
int v14 = 40; //vide
int v15 = 42; //vide
int v16 = 44; //vide

int Enable = 2;


void setup() {

  Serial1.begin(9600);

  pinMode (p1, OUTPUT);
  pinMode (p2, OUTPUT);
  pinMode (p3, OUTPUT);
  pinMode (p4, OUTPUT);
  pinMode (p5, OUTPUT);
  pinMode (p6, OUTPUT);
  pinMode (p7, OUTPUT);

  pinMode (v1, OUTPUT);
  pinMode (v2, OUTPUT);
  pinMode (v3, OUTPUT);
  pinMode (v4, OUTPUT);
  pinMode (v5, OUTPUT);
  pinMode (v6, OUTPUT);
  pinMode (v7, OUTPUT);
  pinMode (v8, OUTPUT);
  pinMode (v9, OUTPUT);
  pinMode (v10, OUTPUT);
  pinMode (v11, OUTPUT);
  pinMode (v12, OUTPUT);
  pinMode (v13, OUTPUT);
  pinMode (v14, OUTPUT);
  pinMode (v15, OUTPUT);
  pinMode (v16, OUTPUT);

  digitalWrite(v1, HIGH);
  digitalWrite(v2, HIGH);
  digitalWrite(v3, HIGH);
  digitalWrite(v4, HIGH);
  digitalWrite(v5, HIGH);
  digitalWrite(v6, HIGH);
  digitalWrite(v7, HIGH);
  digitalWrite(v8, HIGH);
  digitalWrite(v9, HIGH);
  digitalWrite(v10, HIGH);
  digitalWrite(v11, HIGH);
  digitalWrite(v12, HIGH);
  digitalWrite(v13, HIGH);
  digitalWrite(v14, HIGH);
  digitalWrite(v15, HIGH);
  digitalWrite(v16, HIGH);

  digitalWrite(p1, HIGH);
  digitalWrite(p2, HIGH);
  digitalWrite(p3, HIGH);
  digitalWrite(p4, HIGH);
  digitalWrite(p5, HIGH);
  digitalWrite(p6, HIGH);
  digitalWrite(p7, HIGH);

  pinMode (Enable, OUTPUT);

  digitalWrite(Enable, HIGH);
  pinMode(flowpin, INPUT);

  attachInterrupt(1, Flow, RISING);

  sensors.begin();


  lcd.init();
  lcd.backlight();




  lcd.setCursor(0, 0);
  lcd.print("Master Thermostats");
  lcd.setCursor(0, 3);
  lcd.print("Version 1.0");
  delay(2000);
  lcd.clear();
}

void loop() {


  sensors.requestTemperatures();
  currentmillis = millis();

  //------------------menu-------------------//

  lcd.clear();
  switch (menu) {

    case 1:
      lcd.clear();

      lcd.setCursor(0, 0);
      lcd.print("Chambre mik");
      lcd.setCursor(4, 1);
      lcd.print("temperature:");
      lcd.setCursor(0, 2);
      lcd.print("A:");
      lcd.setCursor(2, 2);
      lcd.print(tath1);
      lcd.setCursor(12, 2);
      lcd.print("P:");
      lcd.setCursor(14, 2);
      lcd.print(tpth1);

      if (th1 == 1) {
        lcd.setCursor(9, 3);
        lcd.print("On ");
      } else {
        lcd.setCursor(9, 3);
        lcd.print("Off");
      }

      break;
    case 2:
      lcd.clear();

      lcd.setCursor(0, 0);
      lcd.print("Hall d'Entree");
      lcd.setCursor(4, 1);
      lcd.print("temperature:");
      lcd.setCursor(0, 2);
      lcd.print("A:");
      lcd.setCursor(2, 2);
      lcd.print(tath6);
      lcd.setCursor(12, 2);
      lcd.print("P:");
      lcd.setCursor(14, 2);
      lcd.print(tpth6);

      if (th6 == 1) {
        lcd.setCursor(9, 3);
        lcd.print("On ");
      } else {
        lcd.setCursor(9, 3);
        lcd.print("Off");
      }

      break;
    case 3:
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("reverse1");
      lcd.setCursor(12, 0);
      lcd.print("reserve2");
      lcd.setCursor(12, 1);
      lcd.print(sensors.getTempC(RG1));
      lcd.setCursor(12, 2);
      lcd.print(sensors.getTempC(RG2));
      lcd.setCursor(12, 3);
      lcd.print(sensors.getTempC(RG3));


      lcd.setCursor(0, 1);
      lcd.print(sensors.getTempC(RD1));
      lcd.setCursor(0, 2);
      lcd.print(sensors.getTempC(RD2));
      lcd.setCursor(0, 3);
      lcd.print(sensors.getTempC(RD3));



      break;

  }

  //------------------------Logique-----------------------//

  if (th6 == 1 && sensors.getTempC(RG2) >= 60 && sensors.getTempC(RD2) >= 60){
    digitalWrite(p3, LOW);
    digitalWrite(p4, LOW);
    digitalWrite(p5, LOW);
  } else {
    digitalWrite(p3, HIGH);
    digitalWrite(p4, HIGH);
    digitalWrite(p5, HIGH);
    
  }

  if (sensors.getTempC(RG3) >= 72 && sensors.getTempC(RD3) >= 72) {
    digitalWrite(p6, LOW);
  }
  if (sensors.getTempC(RG3) <= 70 && sensors.getTempC(RD3) <= 70) {
    digitalWrite(p6, HIGH);
  }
  
  //Entrée
  digitalWrite(Enable, HIGH);

  Serial1.print("I");
  Serial1.print("16"); // slave id
  Serial1.print("L");
  Serial1.print("F");
  Serial1.flush();

  digitalWrite(Enable, LOW);

  delay(15);

  if (Serial1.find("i")) {
    delay(10);
    if (Serial1.read() == '6') {
      th6 = Serial1.parseInt();
      if (Serial1.read() == 'a') {
        tath6 = Serial1.parseFloat();
        if (Serial1.read() == 'p') {
          tpth6 = Serial1.parseFloat();
          if (Serial1.read() == 'f') {
          }
        }
      }
    }
  }
  delay(100);


  if (flowRate >= 1) {
    digitalWrite(p2, LOW);
  } else {
    digitalWrite(p2, HIGH);
  }

  count = 0;
  interrupts();
  delay(1000);
  noInterrupts();

  flowRate = (count * 2.25);
  flowRate = flowRate * 60;
  flowRate = flowRate / 1000;


  if (currentmillis - lastMillisScroll >= 2000) {
    lastMillisScroll = currentmillis;
    menu = menu + 1;
  }
  if (menu == 4) {
    menu = 1;
  }


}


//----------------interrupt---------------//

void Flow() {
  count++;
}

Slave code :

int menu = 0;
int parametres = 0;
unsigned long LastTimeButtonPressed;
unsigned long CurrentTime;

const int Enable = 2;
const int Sl1 = 16;

float dAmbiant = 1;
float dPlancher = 2;

float minAmbiant = 15;
float maxAmbiant = 28;
float minPlancher = 15.5;
float maxPlancher = 28;

int LastButtonPressed = 0;

int th1 = 1;

float setTempAmbiant = 19.5;
float setTempPlancher = 25.5;

#include <DallasTemperature.h>
#include <OneWire.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>


#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

#define OLED_RESET 4
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define ONE_WIRE_BUS 3 //Pin sur laquelle est connecter les capteur de temperature

OneWire oneWire (ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

DeviceAddress S1 = { 0x28, 0x4C, 0x0F, 0x95, 0xF0, 0x01, 0x3C, 0x4D };  //AMBIANT
DeviceAddress S2 = { 0x28, 0xEC, 0x64, 0x95, 0xF0, 0x01, 0x3C, 0x70 };  //PLANCHER


float tath = 0;
float tpth = 0;

const uint8_t Maison1  [] PROGMEM = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x06, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x06, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0xc0, 0x00,
  0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x08, 0x00,
  0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x40, 0x00, 0x00, 0x05, 0x80,
  0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00,
  0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00,
  0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00,
  0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00,
  0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00,
  0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00,
  0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00,
  0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00,
  0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00,
  0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x04, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x03, 0xc0, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x30, 0x18, 0x60, 0x00,
  0x00, 0x00, 0x00, 0x10, 0x08, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x20, 0x04, 0x40, 0x08, 0x00,
  0x00, 0x00, 0x00, 0x21, 0x84, 0x43, 0x08, 0x00, 0x00, 0x00, 0x00, 0x22, 0x44, 0x44, 0x88, 0x00,
  0x00, 0x00, 0x00, 0x22, 0x44, 0x44, 0x88, 0x00, 0x00, 0x00, 0x00, 0x22, 0x44, 0x44, 0x88, 0x00,
  0x00, 0x00, 0x00, 0x22, 0x44, 0x44, 0x88, 0x00, 0x00, 0x00, 0x00, 0x22, 0x44, 0x44, 0x88, 0x00,
  0x00, 0x00, 0x00, 0x22, 0x44, 0x44, 0x88, 0x00, 0x00, 0x00, 0x00, 0x22, 0x44, 0x44, 0x88, 0x00,
  0x00, 0x00, 0x00, 0x22, 0x44, 0x44, 0x88, 0x00, 0x00, 0x00, 0x00, 0x22, 0x44, 0x44, 0x88, 0x00,
  0x00, 0x00, 0x00, 0x22, 0x44, 0x44, 0x88, 0x00, 0x00, 0x00, 0x00, 0x22, 0x43, 0x84, 0x88, 0x00,
  0x00, 0x00, 0x00, 0x22, 0x40, 0x04, 0x88, 0x00, 0x00, 0x00, 0x00, 0x22, 0x20, 0x08, 0x88, 0x00,
  0x00, 0x00, 0x00, 0x22, 0x18, 0x30, 0x88, 0x00, 0x00, 0x00, 0x00, 0x14, 0x07, 0xc0, 0x50, 0x00,
  0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const uint8_t Flame2 [] PROGMEM = {
  0x00, 0x00, 0x20, 0x40, 0x40, 0x40, 0x20, 0x10, 0x10, 0x10, 0x20, 0x00, 0x00
};







void setup() {

  Serial1.begin(9600);
  pinMode(Enable, OUTPUT);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);




  digitalWrite(Enable, LOW);
  sensors.begin();

  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial1.println(F("SSD1306 a manquer sa shot"));
    for (;;);
  }
  display.display();
  display.clearDisplay();
}
void loop() {

  if (digitalRead(6) == LOW) {
    LastButtonPressed = 4;
    LastTimeButtonPressed = CurrentTime;
  }

  CurrentTime = millis();

  if ((digitalRead(6) == LOW && menu == 1) && (parametres == 0)) {
    menu = -1;
    LastTimeButtonPressed = CurrentTime;
  }
  if ((digitalRead(6) == LOW && menu != 2) && (parametres == 0)) {
    menu++;
    LastTimeButtonPressed = CurrentTime;
  }
  if (CurrentTime - LastTimeButtonPressed > 10000) {
    menu = 0;
    parametres = 0;
    LastButtonPressed = 0;
  }
  if ((CurrentTime - LastTimeButtonPressed > 3000 && menu == -1) && (parametres <= 7)) {
    LastButtonPressed = 0;
  }


  if ((digitalRead(4) == LOW && menu == 1) && (setTempAmbiant != minAmbiant)) {
    setTempAmbiant = setTempAmbiant - 0.5;
    LastTimeButtonPressed = CurrentTime;
  }
  if ((digitalRead(5) == LOW && menu == 1) && (setTempAmbiant != maxAmbiant)) {
    setTempAmbiant = setTempAmbiant + 0.5;
    LastTimeButtonPressed = CurrentTime;
  }
  if (digitalRead(6) == LOW && menu == 0) {
    menu = 1;
  }

  if ((sensors.getTempC(S1)) <= setTempAmbiant - dAmbiant  && (sensors.getTempC(S2)) <= setTempPlancher - dPlancher) {
    th1 = 1;
  }
  if ((sensors.getTempC(S1)) >= setTempAmbiant || (sensors.getTempC(S2)) >= setTempPlancher) {
    th1 = 0;
  }

  if ((digitalRead(4) == LOW && digitalRead(5) == LOW) && (menu >= 0)) {
    LastTimeButtonPressed = CurrentTime;
    parametres = 1;
    menu = -1;
  }


  if ((digitalRead(5) == LOW && parametres < 7) && (LastButtonPressed != 4 && menu == -1)) {
    parametres++;
    LastTimeButtonPressed = CurrentTime;
    LastButtonPressed = 3;
  }
  if ((digitalRead(4) == LOW && parametres >= 1) && (LastButtonPressed != 4 && menu == -1)) {
    parametres--;
    LastTimeButtonPressed = CurrentTime;
    LastButtonPressed = 2;
  }

  if ((parametres == 1 && LastButtonPressed == 4) && (digitalRead(5) == LOW)) {
    LastTimeButtonPressed = CurrentTime;
    dAmbiant = dAmbiant + 0.5;
  }
  if ((parametres == 1 && LastButtonPressed == 4) && (digitalRead(4) == LOW)) {
    LastTimeButtonPressed = CurrentTime;
    dAmbiant = dAmbiant - 0.5;
  }
  if ((parametres == 2 && LastButtonPressed == 4) && (digitalRead(5) == LOW)) {
    LastTimeButtonPressed = CurrentTime;
    dPlancher = dPlancher + 0.5;
  }
  if ((parametres == 2 && LastButtonPressed == 4) && (digitalRead(4) == LOW)) {
    LastTimeButtonPressed = CurrentTime;
    dPlancher = dPlancher - 0.5;
  }
  if ((parametres == 3 && LastButtonPressed == 4) && (digitalRead(5) == LOW)) {
    LastTimeButtonPressed = CurrentTime;
    minAmbiant = minAmbiant + 0.5;
  }
  if ((parametres == 3 && LastButtonPressed == 4) && (digitalRead(4) == LOW)) {
    LastTimeButtonPressed = CurrentTime;
    minAmbiant = minAmbiant - 0.5;
  }
  if ((parametres == 4 && LastButtonPressed == 4) && (digitalRead(5) == LOW)) {
    LastTimeButtonPressed = CurrentTime;
    maxAmbiant = maxAmbiant + 0.5;
  }
  if ((parametres == 4 && LastButtonPressed == 4) && (digitalRead(4) == LOW)) {
    LastTimeButtonPressed = CurrentTime;
    maxAmbiant = maxAmbiant - 0.5;
  }
  if ((parametres == 5 && LastButtonPressed == 4) && (digitalRead(5) == LOW)) {
    LastTimeButtonPressed = CurrentTime;
    minPlancher = minPlancher + 0.5;
  }
  if ((parametres == 5 && LastButtonPressed == 4) && (digitalRead(4) == LOW)) {
    LastTimeButtonPressed = CurrentTime;
    minPlancher = minPlancher - 0.5;
  }
  if ((parametres == 6 && LastButtonPressed == 4) && (digitalRead(5) == LOW)) {
    LastTimeButtonPressed = CurrentTime;
    maxPlancher = maxPlancher + 0.5;
  }
  if ((parametres == 6 && LastButtonPressed == 4) && (digitalRead(4) == LOW)) {
    LastTimeButtonPressed = CurrentTime;
    maxPlancher = maxPlancher - 0.5;
  }
  if ((parametres == 7 && LastButtonPressed == 4) && (digitalRead(5) == LOW && setTempPlancher != maxPlancher)) {
    LastTimeButtonPressed = CurrentTime;
    setTempPlancher = setTempPlancher + 0.5;
  }
  if ((parametres == 7 && LastButtonPressed == 4) && (digitalRead(4) == LOW && setTempPlancher != minPlancher))  {
    LastTimeButtonPressed = CurrentTime;
    setTempPlancher = setTempPlancher - 0.5;
  }


  sensors.requestTemperatures();

  if (parametres >= 5) {
    display.setCursor(10, 35);
    display.print("Version 1.0");
  }

  switch (menu) {
    case 0:


      display.setTextColor(SSD1306_WHITE);
      display.setCursor(0, 0);
      display.setTextSize(2);
      display.print(sensors.getTempC(S1));
      display.print("C");
      display.print((char)247);
      display.setCursor(0, 20);
      display.setTextSize(1);
      display.print(setTempAmbiant);
      display.print("C");
      display.print((char)247);
      if (th1 == 1) {
        display.print("...");
      }

      display.drawLine(0, 32, 128, 32, SSD1306_WHITE);
      display.drawLine(90, 32, 116, 32, BLACK);
      display.drawBitmap(64, 1, Maison1, 64, 64, WHITE);


      display.setTextColor(SSD1306_WHITE);
      display.setCursor(0, 48);
      display.setTextSize(2);
      display.print(sensors.getTempC(S2));
      display.print("C");
      display.print((char)247);
      display.setCursor(0, 38);
      display.setTextSize(1);
      display.print(setTempPlancher);
      display.print("C");
      display.print((char)247);

      display.display();
      display.clearDisplay();
      break;

    case 1:

      display.setTextColor(WHITE);
      display.setTextSize(2);
      display.setCursor(15, 0);
      display.print("consigne");
      display.drawLine(15, 15, 108, 15, WHITE);

      display.setTextColor(WHITE);
      display.setTextSize(2);
      display.setCursor(20, 30);
      display.print(setTempAmbiant);
      display.print("C");
      display.print((char)247);

      display.display();
      display.clearDisplay();
      break;

    default:

      break;
  }
  switch (parametres) {
    case 1:

      display.setTextColor(WHITE);
      display.setTextSize(2);
      display.setCursor(0, 0);
      display.print("Parametres");

      display.setCursor(0, 20);
      display.setTextSize(1);
      display.print(">");

      display.setCursor(12, 20);
      display.print("D. ambiant:");
      display.setCursor(96, 20);
      display.print(dAmbiant);

      display.setCursor(12, 30);
      display.print("D. plancher:");
      display.setCursor(96, 30);
      display.print(dPlancher);

      display.setCursor(12, 40);
      display.print("Min. ambiant:");
      display.setCursor(96, 40);
      display.print(minAmbiant);

      display.setCursor(12, 50);
      display.print("Max. ambiant:");
      display.setCursor(96, 50);
      display.print(maxAmbiant);


      if (parametres ==  1 && LastButtonPressed == 4) {
        display.setCursor(0, 20);
        display.setTextColor(BLACK, WHITE);
        display.print(">");
      }

      display.display();
      display.clearDisplay();

      break;

    case 2:

      display.setTextColor(WHITE);
      display.setTextSize(2);
      display.setCursor(0, 0);
      display.print("Parametres");

      display.setCursor(0, 30);
      display.setTextSize(1);
      display.print(">");

      display.setCursor(12, 20);
      display.print("D. ambiant:");
      display.setCursor(96, 20);
      display.print(dAmbiant);

      display.setCursor(12, 30);
      display.print("D. plancher:");
      display.setCursor(96, 30);
      display.print(dPlancher);

      display.setCursor(12, 40);
      display.print("Min. ambiant:");
      display.setCursor(96, 40);
      display.print(minAmbiant);

      display.setCursor(12, 50);
      display.print("Max. ambiant:");
      display.setCursor(96, 50);
      display.print(maxAmbiant);

      if (parametres ==  2 && LastButtonPressed == 4) {
        display.setCursor(0, 30);
        display.setTextColor(BLACK, WHITE);
        display.print(">");
      }

      display.display();
      display.clearDisplay();

      break;

    case 3:

      display.setTextColor(WHITE);
      display.setTextSize(2);
      display.setCursor(0, 0);
      display.print("Parametres");

      display.setCursor(0, 40);
      display.setTextSize(1);
      display.print(">");
      display.setCursor(12, 20);

      display.setCursor(12, 20);
      display.print("D. ambiant:");
      display.setCursor(96, 20);
      display.print(dAmbiant);

      display.setCursor(12, 30);
      display.print("D. plancher:");
      display.setCursor(96, 30);
      display.print(dPlancher);

      display.setCursor(12, 40);
      display.print("Min. ambiant:");
      display.setCursor(96, 40);
      display.print(minAmbiant);

      display.setCursor(12, 50);
      display.print("Max. ambiant:");
      display.setCursor(96, 50);
      display.print(maxAmbiant);

      if (parametres ==  3 && LastButtonPressed == 4) {
        display.setCursor(0, 40);
        display.setTextColor(BLACK, WHITE);
        display.print(">");
      }

      display.display();
      display.clearDisplay();
      break;

    case 4:

      display.setTextColor(WHITE);
      display.setTextSize(2);
      display.setCursor(0, 0);
      display.print("Parametres");

      display.setCursor(0, 50);
      display.setTextSize(1);
      display.print(">");

      display.setCursor(12, 20);
      display.print("D. ambiant:");
      display.setCursor(96, 20);
      display.print(dAmbiant);

      display.setCursor(12, 30);
      display.print("D. plancher:");
      display.setCursor(96, 30);
      display.print(dPlancher);

      display.setCursor(12, 40);
      display.print("Min. ambiant:");
      display.setCursor(96, 40);
      display.print(minAmbiant);

      display.setCursor(12, 50);
      display.print("Max. ambiant:");
      display.setCursor(96, 50);
      display.print(maxAmbiant);

      if (parametres ==  4 && LastButtonPressed == 4) {
        display.setCursor(0, 50);
        display.setTextColor(BLACK, WHITE);
        display.print(">");
      }

      display.display();
      display.clearDisplay();

      break;

    case 5:

      display.setTextColor(WHITE);
      display.setTextSize(1);

      display.setCursor(0, 0);
      display.setTextSize(1);
      display.print(">");

      display.setCursor(12, 0);
      display.print("Min. plancher:");
      display.setCursor(96, 0);
      display.print(minPlancher);

      display.setCursor(12, 10);
      display.print("Max. plancher:");
      display.setCursor(96, 10);
      display.print(maxPlancher);

      display.setCursor(12, 20);
      display.print("C. Plancher");
      display.setCursor(96, 20);
      display.print(setTempPlancher);

      if (parametres ==  5 && LastButtonPressed == 4) {
        display.setCursor(0, 0);
        display.setTextColor(BLACK, WHITE);
        display.print(">");
      }

      display.display();
      display.clearDisplay();

      break;

    case 6:

      display.setTextColor(WHITE);
      display.setTextSize(1);

      display.setCursor(0, 10);
      display.setTextSize(1);
      display.print(">");

      display.setCursor(12, 0);
      display.print("Min. plancher:");
      display.setCursor(96, 0);
      display.print(minPlancher);

      display.setCursor(12, 10);
      display.print("Max. plancher:");
      display.setCursor(96, 10);
      display.print(maxPlancher);

      display.setCursor(12, 20);
      display.print("C. Plancher");
      display.setCursor(96, 20);
      display.print(setTempPlancher);

      if (parametres ==  6 && LastButtonPressed == 4) {
        display.setCursor(0, 10);
        display.setTextColor(BLACK, WHITE);
        display.print(">");
      }

      display.display();
      display.clearDisplay();

      break;

    case 7:

      display.setTextColor(WHITE);
      display.setTextSize(1);

      display.setCursor(0, 20);
      display.setTextSize(1);
      display.print(">");

      display.setCursor(12, 0);
      display.print("Min. plancher:");
      display.setCursor(96, 0);
      display.print(minPlancher);

      display.setCursor(12, 10);
      display.print("Max. plancher:");
      display.setCursor(96, 10);
      display.print(maxPlancher);

      display.setCursor(12, 20);
      display.print("C. Plancher");
      display.setCursor(96, 20);
      display.print(setTempPlancher);

      if (parametres ==  7 && LastButtonPressed == 4) {
        display.setCursor(0, 20);
        display.setTextColor(BLACK, WHITE);
        display.print(">");
      }

      display.display();
      display.clearDisplay();

      break;

    default:

      break;
  }
  //----------------------------------------------------------//
  if (Serial1.available())
  {
    if (Serial1.read() == 'I')
    {
      int Slave1 = Serial1.parseInt();
      if (Slave1 == Sl1)
      {
        char command = Serial1.read();
        if (command == 'L')
        {
          if (Serial1.read() == 'F')
          {

            digitalWrite(Enable, HIGH);

            Serial1.print("i");
            Serial1.print("6");
            Serial1.print(th1);
            Serial1.print("a");
            Serial1.print(tath);
            Serial1.print("p");
            Serial1.print(tpth);
            Serial1.print("f");
            Serial1.flush();

            digitalWrite(Enable, LOW);
          }
        }
      }
    }
  }

  tath = sensors.getTempC(S1);
  tpth = sensors.getTempC(S2);
  delay(10);
}

wiring diagram for rs485 :smile:

To debug this problem, start with a MUCH simpler program that just sends a single character to each slave, with a response to the master.

Thanks for the wiring diagram, but that shows only one slave.

Thanks ! i'll try it

sorry for the diagram :frowning_face:

Hello
Did you study the interface requierment specification of a RS485 network?

With RS485 adapters, make sure you pay attention to proper line termination. Post a link to the data sheet for the adapters you are using.

If those are the adapters you are using, you should remove the terminating resistor on the transmitter. It will be a 120R resistor, and on most of those it is R7. Use a digital multimeter to confirm which resistor it should, checking the value and the connection to pin 6 and pin 7 on the Max485 chip.

Have a look at this discussion and my reply #13 with a simple sketch to receive RS485 data via a software serial port on an UNO to control the on-board LED. It supports multiple slaves as well as the ability to broadcast a command to all slaves. That code should work on your Pro Mini.

The message format is start marker, node id, comma, command, end marker. The start marker is '<' and the end marker is '>'. So commands look like <1,0> (device #1 command 0), or <2,1> (device #2 command 1) or <0,3> (all devices command 3).

Actually you should remove the terminating resistor from all units except from the slave furthest away from the master. In case of a multiple direction, it probably shouldn't be there at all.

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