"Connection timed out!" Error with MKR 485 Shield mounted on P1AM-100 for read HOLDING REGISTERS from Analog Input Module WP3082ADAM

Hi,
I'm using the Arduino MKR1000 P1AM-100 based CPU from Automation Direct, which allows to mount shields from the MKR family, which in this case is the MKR 485, to be able to read the values from the WP3082ADAM module from WELLPRO using ModbusRTU as communication protocol.

When I made the first tests, everything worked OK, and I could read the values without problems, but after some time I reloaded the same program and there was no more communication. The curious thing is that the problem is not the module, since it does communicate with a USB module - MAX485 without any problem, and after several attempts I thought that either the CPU P1AM-100 or the MKR485 had been damaged, for which I had to buy both again, but the problem persists, and the truth is I am not sure if it is a hardware or software problem. I have tried changing everything, changing the parity, the stop bits, and the baud rate, both in the sketch and in the WP3082ADAM module parameters, since it has an application that allows changing these parameters. In other words, all the parameters match but it still does not work.

The connection between MKR485 and WP3082ADAM is as follows

I have the 485A on the analog input module hooked up to Y on the shield and the 485B on the analog input module hooked up to the Z on the shield.

For the positions of the dip switchs, I have dipswitch #1 [A //\ B] on the shield OFF, dipswitch #2 [FULL/HALF] on the shield OFF and dipswitch #3 [Y //\ Z] on the shield ON.

And I've also tried to connect the AGnd on the WP3082ADAM with ISOGND for the MKR485 shield, but it still doesn't work.

This is the sketch:

#include <P1AM.h>
#include <ArduinoRS485.h> 
#include <ArduinoModbus.h>

//Variables Modulo de corrinete
float I_CH1,I_CH2,I_CH3,I_CH4,I_CH5;
float DATA1,DATA2,DATA3,DATA4,DATA5;
word CH1,CH2,CH3,CH4,CH5;
float presion,nivel_tanque_diario,pres_caldera_40bhp,p1_out;
float pres_caldera_5bhp,p2_out,pres_tanque_diesel,altura_tanque_diesel;
float presion_tanque_aire,presion_tanque_aire_BAR;

//Varibles de conversion de uint_16 a float_32
uint16_t vregs[2];
long int vint;
float vfloat;

//Programa
void setup() {
   Serial.begin(19200);
  while (!Serial);

  Serial.println("Módulo de entradas Análogas WELLPRO WP3082ADAM");
  // start the Modbus RTU client
  if (!ModbusRTUClient.begin(19200,SERIAL_8N1)) {
    Serial.println("Falla al inciar el Cliente Modbus RTU!");
    while (1);
  }

}

void loop() {
  modCorriente();
  delay(1000);
}
void modCorriente(){
  if (!ModbusRTUClient.requestFrom(0x04, HOLDING_REGISTERS, 0x0000,0x0005)) {
    Serial.print("falla al configurar! ");
    Serial.println(ModbusRTUClient.lastError());
  } else{
   
  Serial.println("success");

    while (ModbusRTUClient.available()) {
      CH1=ModbusRTUClient.read();
      CH2=ModbusRTUClient.read();
      CH3=ModbusRTUClient.read();
      CH4=ModbusRTUClient.read();
      CH5=ModbusRTUClient.read();
      DATA1=CH1;
      DATA2=CH2;
      DATA3=CH3;
      DATA4=CH4;
      DATA5=CH5;
      I_CH1=(DATA1*20)/4095;
      p1_out=((200-0)/(20-4))*(I_CH1-4)+0;
      pres_caldera_40bhp=((13.79-0)/(200-0))*(p1_out-0)+0;
      
      I_CH2=(DATA2*20)/4095;
      p2_out=((208-0)/(20-4))*(I_CH2-4)+0;
      pres_caldera_5bhp=((14.34-0)/(208-0))*(p2_out-0)+0;
      
      I_CH3=(DATA3*20)/4095;
      pres_tanque_diesel=((9.079-0)/(20-4))*(I_CH3-4)+0;//kPa
      altura_tanque_diesel=((1.09-0)/(9.079-0))*(pres_tanque_diesel-0)+0;//metros
      
      I_CH4=(DATA4*20)/4095;
      presion_tanque_aire=((300-0)/(20-4))*(I_CH1-4)+0;//PSI
      presion_tanque_aire_BAR=((-0)/(300-0))*(presion_tanque_aire-0)+0;
      
      I_CH5=(DATA5*20)/4095;
      presion=((20.6843-0)/(20-4))*(I_CH1-4)+0;//Bares
      nivel_tanque_diario=((100-0)/(20-4))*(I_CH1-4)+0;//Porcentaje
      Serial.println("CANAL 1:");
      Serial.println(I_CH1,2);
      Serial.println(p1_out,2);
      Serial.println(pres_caldera_40bhp,2);
      Serial.println("CANAL 2:");
      Serial.println(I_CH2,2);
      Serial.println(p2_out,2);
      Serial.println(pres_caldera_5bhp,2);
      Serial.println("CANAL 3:");
      Serial.println(I_CH3,2);
      Serial.println(pres_tanque_diesel,2);
      Serial.println(altura_tanque_diesel,3);
      Serial.println("CANAL 4:");
      Serial.println(I_CH4,2);
      Serial.println(presion_tanque_aire,2);
      Serial.println(presion_tanque_aire_BAR,2);
      Serial.println("CANAL 5:");
      Serial.println(I_CH5,2);
      Serial.println(presion,2);
      Serial.println(nivel_tanque_diario,2);      
    }
  }
  }

Thanks for your help.

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