Problem reading data of Power Meter via modbus protocol

Hello everyone,

I have a problem with a project, and I cannot work it out. I want read out data of a Power Meter via modbus communication line (serial), but the received data is incorrect. Therefore I need help.

My system consists of the following:

The MX485 chip is connected between the arduino and power meter, see figure below. TX (arduino pin 0) connected to driver input MX485, RX (arduino pin 1) connected to receiver output MX485. The outputs A and B of MX485 are connected to A and B of the power meter, respectively. In order to switch the modus of the MX485 chip in driver/receiver, arduino pin D3 is used and controlled by software. During programming of the arduino, the pin TX and TX are disconnected from the MX485. After programming, the USB is disconnected and the power supply is turned on. From that moment, the LCD shield will display measurement values of the power meter.

This project is inspired by existing project, where some adjustment in the library was needed. See http://electronics.stackexchange.com/questions/49097/arduino-as-modbus-master-with-max485-doesnt-get-any-response. Pin D3 is actually hardware coded in the library, in order to switch on the right time between driver/receiver modus of the MX485 chip. I did the same than described on that site.

A test program that I have used, to read out a single register of the power meter, is shown below:

#include <ModbusMaster.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
ModbusMaster node(1);

void setup() {
  pinMode(3, OUTPUT);
  digitalWrite(3, LOW);
  node.begin(9600);
  lcd.begin(16, 2);
}

void loop() {
uint16_t m_startAddress=0x07D6;
uint8_t m_length=2;
uint8_t result;

  lcd.clear();

  result = node.readHoldingRegisters(m_startAddress, m_length);
  //result = node.readInputRegisters(m_startAddress, m_length);
  
  if (result == node.ku8MBSuccess) {
    lcd.print("DATA: ");
    for (uint8_t j = 0; j < m_length; j++)
       {
       lcd.print(node.getResponseBuffer(j), HEX);
       }
  }
  else {
    lcd.print("ERR ");
    lcd.print(result, HEX);
  }
  delay(1000);
}

The registers of the power meter are described in the manual (appendix) (see http://www.hobut.co.uk/images/M850%20Comprehensive%20User%20Manual_03%202011a.pdf). The problem is in fact that if I read out registers of the power meter, the received (HEX) data is either 00 (2 times zero) or FFFF FFFF (8 times F), depending of the register address. This last (8 times F) means that the requested register is not applicable, but I used the same registers as described in the manual. It is not a modbus error what is shown, because the request is successful (result=success). If I disconnect a cable (or switch connections A and B) an error E2 is shown in the display (timeout error). Thus it seems to be not a hardware problem.

The measurement data of the power meter can be read out from two different registers, namely:

  • Input registers with address 3X (by power meter) and modbus function code 04
  • Holding register with addres 4X (by power meter) and modbus function code 03
    See the functions readInputRegisters and readHoldingRegisters in the arduino software. I have tried both functions, but without successful measurement data. A brief overview of the results is shown below:

[Register name] [register] [received data]
With function ReadInputRegister (function 04):

  • Voltage V1, 0x0006, FFFF FFFF
  • Voltage V2, 0x0008, FFFF FFFF
  • Voltage V3, 0x000A, 00
  • Frequency, 0x001E, 00
    With function ReadHoldingRegister (function 03):
  • Voltage V1, 0x07D6, FFFF FFFF
  • Voltage V2, 0x07D8, FFFF FFFF
  • Voltage V3, 0x07DA, 00
  • Frequency, 0x07EE, 00

The Hobut power meter is new, and works stand-alone perfectly. It measures 3 phase voltages correctly, and can also measure current, power and energy by using current transformers. For testing purposes, the current measurement (and thus the transformers) are omitted. During testing, the 3 voltage inputs of the power meter are connected to 240 Vac. The power meter shows fluctuating values around 240 Vac, but the received data with the arduino seems not to be fluctuating voltage values. What is the cause of this?? I have tried a lot for days, but I cannot come to a solution. Is it probably a modbus library error? Please help me??

Maybe check that the unit is working properly with the 485 module by downloading their test software form the page that you gave above (http://www.hobut.co.uk/images/HOBUT-MViewV02.zip) and, assuming that it uses the modbus protocol to extract data, verify that the unit is communicating properly.

Also there are two frame formats that modbus devices use; RTU and ASCII. I think the modbus frame used by the library is ASCII so be sure that your meter is using ASCII.

Without hooking up a test rig, there is little more that I can offer. I have been looking at using the modbus library to hook up to a VSD/VFD to control large motors, but have not got around to it yet. I have hooked up using a PC and a modus library for .NET from http://www.sapia-inc.com/ in the past. You can download a free, time limited version which you can use to interrogate the registers on the meter to see what you should be getting. Don’t know if you can put this library into slave mode so that you can link the arduino to it to test your prog.

Hi lemming,

Thank you for your response. :slight_smile:
I was also thinking on your first point, but I don’t have an usb to 485 converter. In fact I think that this is not immediately the solution to my problem. The meter is new, and only used a couple of times for testing purposes. I will consider to buy a converter, to be sure the meter is working properly.

Regarding your second point, how can I make distinction between RTU and ASCII. What uses the modbus library of arduino? In the manual of the power meter is nothing mentioned about RTU and ASCII.

Regards mauriceB

how can I make distinction between RTU and ASCII

The documentation that comes not with the meter but the RS485 add-on module should specify which one it uses. 95% sure that it would be RTU as this is the most common. You can email the manufacturer to be sure. I have checked the Arduino library and it is an RTU implementation of the protocol.

The meter is new, and only used a couple of times for testing purposes

The unit most probably is not at fault however its a matter of removing the variables that could be causing problems.

By using tried-and-tested software you can be fairly sure that problems with communication are not due to bugs in your code/library. Likewise, using a USB to 485 converter removes any doubts about your circuit. After getting comms up with the 3rd party software and converter, you can get a grasp of what values you should be getting from the meter which you can use later on to verify success when using your own code and RS485.

Once you get successful comms, the next step would be to substitute in your Rs485 circuit and try it again. If that works, use your code rather than the 3rd party code, secure in the knowledge that everything else is working OK and any problem can only be in your code.

I recently acquired two meters HOBUT M850 and I'm trying to read the information through the Modbus protocol (for this I have two RS485 modules connected).

The goal is to read the reactive power through the computer and order an arduino to activate different signals to control it. But unlike you, I do not receive anything from the device, always gives me timeout error.

I built two devices to converters RS232-RS485 using integrated MAX232 and MAX485. One activates the read / write data via the RS232 pin RTS and the other active writing only when sending data. Between computers and arduino I get to communicate perfectly but not with the meter.

By the negative result of home hardware, I bought a USB-RS485 converter getting the same result: no response from the device.

The tests I conducted with Multiview and Multilog (Hobut) software and other free web tools.

Could you please show me an error when installing the module? I think there is something that escapes me.

And if I can help (although the post is old and sure you've resolved): MODBUS is the actual address indicated by 3x and 4x registers, for example, v1 is the record 0x07D6 but must address with 004 (Address 4X). If Error try with 1004 and see the tables at the end of the documentation.

PD. Sorry, I'm spanish and my english is......

I forgot! I tried to register on the Hobut support forum but can not find where!! No register button find!!

The link for the modbus power meter you posted about doesn't work. If that doesn't work I found some other Modbus power meters here: http://www.icpdas-usa.com/intelligent_power_meters.html?r=maria

Maria Lemone