IEC 62056-21 Protocol: Reading from Electricity Meter

Hello all,

I'm trying to read from the RS485 port of an Electricity Meter using an Arduino Nano, using a MAX485 chip to convert to RS485 to TTL.

It uses the IEC 62056-21 protocol, and I'm having trouble receiving anything back from it. I'd appreciate any help, insights or pointers you may have.

I've done a lot of digging but most of it involves reading through an optical port, while I'm using RS485.

I'm attaching a wiring diagram; it's pretty straightforward, with the MAX485 connecting to the VCC, GND and 4 digital pins of the arduino.

Here is the code I'm using. Once again, pretty basic. Setting DE and RE to HIGH, sending the "/?!" signal, then setting DE and RE to LOW and waiting for a response.

// Print RS485 data to serial

// Connections:
// DI = 2, DE = 3, RE = 4, R0 = 5

#include <SoftwareSerial.h>
SoftwareSerial SSerial(5, 2);

void setup(void){
  // initialize serial port
  Serial.begin(115200);
  delay(10);
  Serial.print("\nInitializing");
  while (!Serial) { delay(10); Serial.print("."); };       // wait for serial port to connect. Needed for native USB port only
  Serial.println("\nReady");

  // initialize RS485 connection
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  SSerial.begin(300);

  Serial.println("Sending Initial Message");
  digitalWrite(3, HIGH); digitalWrite(4, HIGH);
  SSerial.write("/?1!");
  digitalWrite(3,  LOW); digitalWrite(4,  LOW);
  Serial.println("Waiting for response...");
}

void loop()
{
  while(SSerial.available())
  { Serial.write(SSerial.read()); }
}

I've tried sending different variations of the message, like /?1! or /?1!\r\n.

I've also tried putting a delay after the write, before switching the pins to low.

But no matter what I've tried, I haven't received anything back.

Perhaps I'd have better luck connecting the MAX485 to something like a FT232 (USB to TTL) and try communicating to the device directly with my electric meter using the serial monitor?

(The end goal is to use an ESP8266 instead of an Arduino, but I'd like to actually get it working first before taking that step.)

Any help would be appreciated!

I have realized that the protocol uses 7E1 which creates a multitude of problems with SoftwareSerial. I think it may be best to just eliminate the arduino middle-man and try to establish communications directly using USB to TTL + TTL to RS485. (Or just USB to RS485?)

Can anyone point me to any tutorials or instructions for setting up such a connection?

Not 100% but check that you can do Softserial on those pins.

Also check that nothing else on the same wires is not pulling the lines in any direction and stunting the data.

Check your setup() also.
You open the Serial port and start transmitting data on it while waiting for it to be available.
Just seems a little illogical.! Better not to use the serial while waiting for it to start.

  Serial.begin(115200);
  while (!Serial) {;}
  Serial.print("\nInitializing");

If you have another 485 module then try to communicate with another Arduino setup.

Your suggestion of using a PC to debug the problem, Buy a 485-USB rather than trying to use USB-TTL-485, you wont have those switching pins on FT232. Actually I think the FT232 does have the switching pins on the IC, just not coming out to headers.

Changing from Arduino to ESP should be fairly transparent just need to make sure that any connections to the ESP are 3.3v maximum. So you may need a level shifter on any interconnecting wires if your 485 stuff is running at 5v.

Not sure if this helps but a "similar" project.

https://forum.arduino.cc/index.php?topic=147239.0

Or something not so good.

Thanks for the response.

I don't think the setup was causing any problems but that was probably because the delay(10) was enough to let Serial to initialize. Your version makes a lot more sense though, so I'll switch to that.

I think the best course of action will be to order a 485-USB cable and start troubleshooting that way.

And yeah, switching to ESP will have a few challenges - one being a logic level converter, and another being the lack of debugging capability from the serial port (since that will be used up by the 485 connection). But if I get the communication sorted out using a PC, then I think I could skip the Nano altogether and jump straight to ESP at that point.

I just checked the projects you linked, and it looks like I've already read through all of them before (I did quite a bit of digging before posting here :P). They did help me get started but unfortunately they don't have anything concrete that would help.

But anyway, the 485-USB will hopefully let me start untangling this web of problems.

Thanks again for the help, I'll probably post again when I make some progress on the issue.

100% on all.
If you have a known working connection everything else will be a breeze.

The ESP also supports Softserial so you can have debug as well as 485.
I guess it depends on the ESP module you are developing with.
Grab a NodeMCU 12e or similar that gives you a complete full pinned platform.
You can use a smaller more dedicated ESP once you have things sorted if preferred.

The level convertors are 10 a penny on eBay so it is no obstacle either.

If you are going the ESP route then make sure you scratch up on doing http updates.
It makes developing with them much faster and handy for updating down the road..

Best of luck,

Yep, I already have a bunch of LLC's. I'll look into http updates. I'm actually a web app developer by trade so that part should be easy. It's the electronics part I usually have trouble with!