How to take data from smart energy meter to Arduino Nano using RS485?

Hi,

I have been working on a project. I have to take readings of Ziegler energy meter (http://www.zieglerinstruments.com/Product/Detail/192/Power-Energy-meter) on an Arduino nano using RS485 Modbus.

I have made this code:<pre>
#include<ModbusMaster.h>
#include<SoftwareSerial.h>

SoftwareSerial mySerial(2,1);

uint16_t m_startAddress[3] = {0x30001 , 0x30007 , 0x30013};
uint16_t m_length = 0x0001;
uint8_t result;
uint8_t ret;
int sta =0;

union
{
uint16_t u[2];
float f;
}meterdata;

ModbusMaster node;

void enableTx()
{
delay(2);
digitalWrite(7,HIGH);
}

void disableTx()
{
delay(2);
digitalWrite(7,LOW);
}

void setup()
{
pinMode(7,OUTPUT);
digitalWrite(7,LOW);

node.preTransmission(enableTx);
node.postTransmission(disableTx);
Serial.begin(9600);
node.begin(1,mySerial);
}

void loop()
{
result = node.readInputRegisters(m_startAddress[sta],m_length);
if(result == node.ku8MBSuccess)
{
if(sta==0)
{
meterdata.u[1] = node.getResponseBuffer(0);
meterdata.u[0] = node.getResponseBuffer(1);
Serial.print("Voltage: ");
Serial.print(meterdata.f);
Serial.print("V");
}
else if(sta==1)
{
meterdata.u[1] = node.getResponseBuffer(0);
meterdata.u[0] = node.getResponseBuffer(1);
Serial.print("Current: ");
Serial.print(meterdata.f);
Serial.print("A");
}
else if(sta==2)
{
meterdata.u[1] = node.getResponseBuffer(0);
meterdata.u[0] = node.getResponseBuffer(1);
Serial.print("Power: ");
Serial.print(meterdata.f);
Serial.print("W");
}
}
else{
Serial.print("Error");
Serial.println(result,HEX);
}
sta ++;
if(sta==3) sta=0;
delay(1000);
}</pre>
Can anyone tell me about the errors in this code?

You can go through this manual (http://www.zieglerinstruments.com/Upload/Documents/01 Ziegler/Product Code/MFM/Ziegler-Delat-Energy Manual-E1R0.pdf)

Thanks for the help or advice in advance.
 
J

José Luiz

Good Morning!

I have no experience with Modbus. But with the above mentioned manual, I saw on page 35, table with end hex of the registers for Modbus. Example: the end 30001, for Modbus 0x0000; end 30007> 0x0006; and 30013, 0x000C.
Is this the problem?

<b>Moderator's Note:</b> This reply was originally in Portuguese. I used Google Translate.

Bom dia!
No tenho experiencia com modbus, mas consutando o manual citado, vi na pagina 35, tabela com end hex dos registradores para modbus. Exemplo: o end 30001, para modbus 0x0000; end 30007 > 0x0006; e 30013, 0x000C.
Ser¡ esse o problema ????
 
Top