Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Interfacing Energy Meter having MODBUS RTU protocol with Arduino Uno
#1

#include <LiquidCrystal.h>

#include <ModbusMaster.h>

#define METERSLAVEID 11

#define LEDPIN 13

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// Create a software interface for meter (create a ModBusMaster node)

ModbusMaster node(METERSLAVEID);

void setup() {

// Initialising communication with meter

node.begin(9600);



// Setting up led

pinMode(LEDPIN, OUTPUT);



// set up the LCD's number of columns and rows:

lcd.begin(16, 2);



// Print a message to the LCD.

lcd.print("hello, world!");

//set data output enable pin to output mode



}

void loop() {

// Reading data from meter

// 1. Request data using readHoldingRegisters() (i think we need to enable the outputs before this)

// 2. Check whether data is available using node.ku8MBSuccess flag

// 3. If valid read data from buffer using node.getResponseBuffer()

uint16_t data[ 2]; //We are using array of two 16 bit because we are reading two registers of 16 bit from meter

uint8_t flag; //8 bit flag is required for error checking because we get 8 bit status

int final; //final result

//see comment 1





flag = node.readInputRegisters(30001, 2);

lcd.setCursor(0, 1);

// print the number of seconds since reset:

switch(flag)

{

case 0x01:

lcd.print("Illegal Function");

break;

case 0x02:

lcd.print("Illegal DataAddress");

break;

case 0x03:

lcd.print("Illegal DataValue");

break;

case 0x04:

lcd.print("Slave device Failure");

break;

case 0x00:

lcd.print("Success");

break;

case 0xE0:

lcd.print("Invalud Slave");

break;

case 0xE1:

lcd.print("Invalid Function");

break;

case 0xE2:

lcd.print("Time Out");

break;

case 0xE3:

lcd.print("Invalid CRC");

break;

}

if(flag == node.ku8MBSuccess){

//glow a led

digitalWrite(LEDPIN, HIGH);

//read data

data[0] = node.getResponseBuffer(0);

data[1] = node.getResponseBuffer(1);

final = data[0];

if(data[1] == 0xFF) //sign check

{

final = ( data[0]) + 1;

final = final * (-1);

}

}

else{

//unglow a led

digitalWrite(LEDPIN, LOW);

}

delay(1000);

}
Reply
#2
Please help me to interface rishabh energy meter EM 1340 with Arduino Uno. I have tried using ModbusMaster Library and SimpleModbus Library for coding in arduino. I have build RS485 to TTL converter using MAX485 IC and circuit which is given in SimpleModbus Library . I can share the code with you . My problem is that i am always getting Timeout Error . I checked on DSO the query at the converter end is not what is accepted , I mean when arduino sends query the message in form of square wave but at converter end their is loading . Please tell me what to do?

I am ready to share all information which , you just ask anything and please help me. Thank YOU Smile

The interface definition for meter is available online. I am not allowed to post page link here sorry just google search Rishabh Interface Definition and click on page link havin EM13XX and EM23XX
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: modbus implementation flowchart pdf, avr modbus implementation, arm processor lpc2148 modbus address, macular edema detection thesis having matlab codes, adaptive blind noise suppression in some speech processing applications report pdf of rtu, modbus implementation in c, lex program to find that a string is having three consecutive a,

Forum Jump:


Users browsing this thread: 1 Guest(s)