"Connection Timed Out" Error with MKR 485 Shield Reading Energy Meter

First post, so please bear with me! I have some programming experience and have meddled with Arduino now for a year or two. I probably have just enough knowledge to be dangerous. :slight_smile:

I am trying to get my Arduino, an Arduino MKR WiFi 1010 with an Arduino MKR 485 shield, to read voltage, current, power, frequency, etc. from an energy meter with built-in Modbus RTU communication protocol. I have code setup to relay these values to a Home Assistant setup on a Rasberry Pi via MQTT. I have that all working, so I have just pared down my Arduino sketch code to reading voltage and outputting to serial monitor.

My problem is that I cannot seem to get any kind of response or communication link going between my MKR 485 shield and my energy meter. All I ever get is a “Connection timed out” error message no matter what I try.

Here is my code:

//import libraries
#include <ArduinoRS485.h>
#include <ArduinoModbus.h>

unsigned long rate = 60000; // default refresh rate in ms
unsigned long lastMillis = 0;

void setup() {
  Serial.begin(115200);
  // start the Modbus RTU client
  if (!ModbusRTUClient.begin(9600)) {
    Serial.println("Failed to start Modbus RTU Client!");
    while (1);
  }
}

void loop() {
  if (millis() - lastMillis > rate) {
    lastMillis = millis();
    //make all the read calls
    float volt = readVoltage();
    delay(100);
    Serial.println(String(volt,3)+"V");
    delay(100);
  }
}

float readVoltage(){
  float volt = 0.;
  if (!ModbusRTUClient.requestFrom(0x01, HOLDING_REGISTERS, 0x0000, 2)) { //make the call to the register
    Serial.print("failed to read voltage! ");
    Serial.println(ModbusRTUClient.lastError()); //error handler
  }else{
    uint16_t word1 = ModbusRTUClient.read();  //read data from the buffer
    uint16_t word2 = ModbusRTUClient.read();
    uint32_t millivolt = word1 << 16 | word2; //bit math
    volt = millivolt/1000.0;
  }
  return volt;
}

The call to the register always fails.

I have the A on the energy meter hooked up to Y on the shield. I have the B on the energy meter hooked up to the Z on the shield. I have dipswitch #1 [A //\ B] on the shield OFF, dipswitch #2 [FULL/HALF] on the shield OFF/HALF and dipswitch #3 on the shield ON [Y //\ Z]. The energy meter powers up and seems to work properly as displayed by the onboard LCD.

Please see attached pics for my board setup and the type of energy meter I’m using. Any help would be greatly appreciated! Thank you in advance.

Do you try to connect iso gnd ?

Thank you for the reply. I have not connected the ISOGND. This energy meter I'm using does not have a ground to hook up to it. I thought about that, but unless you can suggest how I should hook that up, I'm not sure how to do it. Do you know if that is very important? I've seen other energy meters have a ground pin like the A and B, but this one does not, so I thought it didn't need to be hooked up. Please advise. Thank you!

I figured out my connection problem! I was using the wrong parity in setting up my serial communication with the device. I found the proper info in their manual. very small writing :-)