Change address of a modbus gateway using Arduino

hi all, I have a gateway of digital and analog inputs that communicates by modbus, what I want is a code to change the address it has (which is supposed to be 1) so that it does not conflict with other sensors that I have, according to the gateway manual, this is the frame that must be sent to change the address (00 06 00 64 00 01 08 04) and the gateway has to send the same to confirm that it has changed me, my problem is that I do not know in that my program is failing, if at the time of sending the plot or at the time of receiving it, I am quite a beginner in the subject of modbus in arduino so I would appreciate your help, thank you very much.

#include <SoftwareSerial.h>
#include <Wire.h>

const byte msg[] = {0x00,0x06, 0x00, 0x64, 0x00, 0x0a, 0x08, 0x04};

SoftwareSerial mod(7,8);

byte values[11];

void setup() {
  Serial.begin(9600);
  mod.begin(9600);
  pinMode(2, OUTPUT);

}

void loop() {
  
  byte val1;
  
  
  val1 = r();
  delay(250);


  Serial.print("Respuesta: ");
  Serial.println(val1);


}

byte r(){  
  digitalWrite(2,HIGH);
  delay(10);
  for(byte i=0;i<7;i++){
    Serial.print(msg[i],HEX);
    mod.write(msg[i]);
  }
  Serial.println();
  if(mod.write(msg,sizeof(msg))==8){
    digitalWrite(2,LOW);
    for(byte i=0;i<7;i++){
    //Serial.println();
    //Serial.println("Vamos por aquí");
    //Serial.println();
    //Serial.print(mod.read(),HEX);
    values[i] = mod.read();
    Serial.print(values[i],HEX);
    }
    Serial.println();
  }
}

Hmm. You may want to change the title to be English as well.

1 Like

it's true, sorry, thank you

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