PZEM-017 Issue

Hello,

I am trying to read data using Arduino Mega from PZEM-017. DC 0-300V , 0-300A.

PZEM Meter

It uses MODBUS RTU Protocol to communicate
Baud rate 9600, 8 data bits, 2 stop bits, no parity

It is working fine with its software (Picture attached) on Windows using USB to RS485 converter supplied along with meter

I have connected the meter to Arduino Mega using TTL-RS485 Converter

Wiring Sequence as Follows

Arduino Pin 14 Txd to Pin DI on Converter
Arduino Pin 15 Rxd to Pin RO on Converter
Arduino Pin 48 to Pin DE on Converter
Arduino Pin 49 to Pin RE on Converter

Converter Pin A to PZEM Pin A
Converter Pin B to PZEM Pin B

Arduino, TTL-RS485 Converter , PZEM Meter 5V and Ground is common

Code as below

#define MAX485_DE      48
#define MAX485_RE_NEG  49
int readdata[]={0xF8,0x04,0x00,0x00,0x00,0x08,0xE5,0xA5}; 
int response[21]; 
int i;
void preTransmission()
{
  digitalWrite(MAX485_RE_NEG, 1);
  digitalWrite(MAX485_DE, 1);
}

void postTransmission()
{
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);
}

void setup()
{
  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);
  Serial.begin(9600);
  Serial3.begin(9600,SERIAL_8N2);
  preTransmission();

}

void loop()
{
{
preTransmission();
for (i=0;i<8;i++) Serial1.write(readdata[i]);
delay(50);
postTransmission();
   if (Serial3.available())     
   { 
   for (i=0 ; i<21;i++)
   {
   while(!Serial3.available());
   response[i]=Serial3.read();
   }
   }
  
  for (i=0;i<21;i++) {Serial.print(response[i],HEX); Serial.print(' '); }
  Serial.println(' ');
  delay(2000);
 
}}

The result is attached

I used Advanced Serial Port Monitor to check communication between Software on PC and PZEM meter
The snapshots are attached
It is working with other Softwares as well like Modbus Poll

But I can’t seem to get anything in reply from meter through Arduino. I tried adding removing delays but nothing works

TTL-RS485.png

I think that you got the DE and RE signals wrong. Please check with the data sheet.

Can you clarify ? Help would be appreciated RE DE Signals should be HIGH before transmission and should be LOW before receiving right ?

for (i=0;i<8;i++) Serial1.write(readdata[i]);

Should this be Serial3 and not Serial1?

Instead of delay(50); after transmitting you could use Serial3.flush() that blocks until last byte is transmitted.
That way you would be less likely to miss RX data.

Hi, Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

I have given you a Karma for formatting your code in code tags.

Thanks.. Tom.. :)

usahmed90:
Hello,

I am trying to read data using Arduino Mega from PZEM-017. DC 0-300V , 0-300A.

PZEM Meter

It uses MODBUS RTU Protocol to communicate
Baud rate 9600, 8 data bits, 2 stop bits, no parity

It is working fine with its software (Picture attached) on Windows using USB to RS485 converter supplied along with meter

I have connected the meter to Arduino Mega using TTL-RS485 Converter

Wiring Sequence as Follows

Arduino Pin 14 Txd to Pin DI on Converter
Arduino Pin 15 Rxd to Pin RO on Converter
Arduino Pin 48 to Pin DE on Converter
Arduino Pin 49 to Pin RE on Converter

Converter Pin A to PZEM Pin A
Converter Pin B to PZEM Pin B

Arduino, TTL-RS485 Converter , PZEM Meter 5V and Ground is common

Code as below

#define MAX485_DE      48

#define MAX485_RE_NEG  49
int readdata={0xF8,0x04,0x00,0x00,0x00,0x08,0xE5,0xA5};
int response[21];
int i;
void preTransmission()
{
  digitalWrite(MAX485_RE_NEG, 1);
  digitalWrite(MAX485_DE, 1);
}

void postTransmission()
{
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);
}

void setup()
{
  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);
  Serial.begin(9600);
  Serial3.begin(9600,SERIAL_8N2);
  preTransmission();

}

void loop()
{
{
preTransmission();
for (i=0;i<8;i++) Serial1.write(readdata[i]);
delay(50);
postTransmission();
  if (Serial3.available())   
  {
  for (i=0 ; i<21;i++)
  {
  while(!Serial3.available());
  response[i]=Serial3.read();
  }
  }
 
  for (i=0;i<21;i++) {Serial.print(response[i],HEX); Serial.print(’ ‘); }
  Serial.println(’ ');
  delay(2000);

}}




The result is attached 

I used Advanced Serial Port Monitor to check communication between Software on PC and PZEM meter 
The snapshots are attached
It is working with other Softwares as well like Modbus Poll

But I can't seem to get anything in reply from meter through Arduino. I tried adding removing delays but nothing works

Hi,
did you managed to read it in arduino?