Communication between arduino and smart energy meter using optical cable

So, I am trying to read smart energy meter data using Raspberry Pi and using a python script I was able to obtain the required output successfully. The python code for the successful implementation is:

import serial
import time

SNRM = "7EA00703619369477E"
ser = serial.Serial('/dev/ttyUSB0')
ser.write(bytes.fromhex(SNRM))
time.sleep(1)
data = ser.read_all().hex()
print(data)

I used USB to RS-232 converter connected interfaced to the smart meter via optical cable to obtain the data directly on the raspberry pi.

Now, I am trying to obtain the data using Arduino UNO. I decide to replace the USB to RS-232 converter with UART/TTL to RS-232 converter in order to interface the arduino with the smart meter via optical cable. And, I wrote the following code for it:

#include <SoftwareSerial.h>

SoftwareSerial sensorPort(2, 3); // RX, TX

void setup() {
  Serial.begin(9600);
  Serial.println("Hello!");
  
  sensorPort.begin(9600);
}

void loop() {
  byte snrm[] = { 0x7E, 0xA0, 0x07, 0x03, 0x61, 0x93, 0x69, 0x47, 0x7E };
  sensorPort.write(snrm, sizeof(snrm));
  
  delay(1000);
  
  byte data[32] = { 0 };
  int bytesAvailable = sensorPort.available();
  int bytesRead = sensorPort.readBytes(data, bytesAvailable);

  String out{"0x"};
  
  for (int i = 0; i < bytesRead; i++) {
    String hexStr{data[i], HEX};
    if (hexStr.length() < 2) {
      out += "0";
    }
    out += hexStr;
  }

  Serial.println(out);
}

But, I am not able to receive any data from the port and I am unable to understand where I may be going wrong (software or hardware) although everything seems to be connected and working as they should.
UART/TTL to RS-232 converter: https://www.amazon.in/dp/B07VHZQM5C/ref=cm_sw_r_wa_apa_fabc_1Z7CQXBYYY756WH9VXNT
An image of my setup: Imgur: The magic of the Internet
A description of the smart meter ca be found here: https://5.imimg.com/data5/EV/SV/MY-7408343/indus-series-single-phase-smart-meters.pdf

I will try to come up with a schematic if the above picture doesn’t make any sense.

i don't see a description of the interface to the meter? is it rs-232? baud-rate and data format

You have defined the software serial port as pins 2 and 3, but as far as I can tell from the photos you have connected to pins 0 and 1.

I don't understand your code. I have test code that takes input from one serial port and sends it to the serial monitor, when I get back to my PC I will share it with you.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.