Author Topic: Arduino Nano Modbus energy meter SDM230  (Read 2692 times)

0 Members and 1 Guest are viewing this topic.

Offline PSR B1257Topic starter

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: de
Arduino Nano Modbus energy meter SDM230
« on: January 25, 2022, 06:26:38 pm »
Hy guys, one's again a Arduino problem.

I am trying to read the Modbus-interface of an SDM230 energy meter, using these codes: https://github.com/peninquen/Modbus-Energy-Monitor-Arduino/tree/master/Old_versions/Modbus-Energy-Monitor-Arduino

The energy meter is connected via a RS458-TTL-converter.

The only change I made so far, was to edit one line in the Modbus-Energy-Monitor-Arduino.ino file
#define MB_SERIAL_PORT &Serial1
to
#define MB_SERIAL_PORT &Serial
since Arduino Nano has just one serial port.
With that, the whole mess at least compiles.
But I get no activity on the TX/RX pins, and therefore only gibberish (as far as the data goes) on the serial port , the header is fine.



I compared the data-addresses from the SDM120 to my SDM230, and they are the same.

Could it be, that this code is not compatible with Arduino Nano?

Best regards,
Mathias

In theory, there is no difference between theory and practice. But, in practice, there is.
 

Offline fchk

  • Regular Contributor
  • *
  • Posts: 244
  • Country: de
Re: Arduino Nano Modbus energy meter SDM230
« Reply #1 on: January 25, 2022, 07:45:27 pm »
Did you check the TX, RX, and DE (Transmitter Enable) signal with a logic analyzer? If yes, please post a screendump of a transaction.

If you don't have a logic analyzer: there are plenty of these cheap 24 Mhz/8 channel Saleae clones on Amazon and ebay for about 10€. Well invested money!

fchk
 

Offline PSR B1257Topic starter

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: de
Re: Arduino Nano Modbus energy meter SDM230
« Reply #2 on: January 25, 2022, 08:15:43 pm »
Quote
Did you check the TX, RX, and DE (Transmitter Enable) signal with a logic analyzer?
No, but with my DSO  ;)
The only activity is on the 'TxEnablePin'.1391927-0
In theory, there is no difference between theory and practice. But, in practice, there is.
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3036
  • Country: us
Re: Arduino Nano Modbus energy meter SDM230
« Reply #3 on: January 26, 2022, 05:13:21 am »
Have a look at these lines in the Arduino library:

Code: [Select]
#define MODBUS_SERIAL_OUTPUT  //Verbose MODBUS messages and timing

#ifdef MODBUS_SERIAL_OUTPUT
#define MODBUS_SERIAL_BEGIN(...) Serial.begin(__VA_ARGS__)
#define MODBUS_SERIAL_PRINT(...) Serial.print(__VA_ARGS__)
#define MODBUS_SERIAL_PRINTLN(...) Serial.println(__VA_ARGS__)
#else
#define MODBUS_SERIAL_BEGIN(...)
#define MODBUS_SERIAL_PRINT(...)
#define MODBUS_SERIAL_PRINTLN(...)
#endif

The library is printing debugging messages with the Serial object. This is verified by the screenshot of your output -- the "MASTER:" stuff is part of a debug message. The garbage following "MASTER:" is the actual MODBUS packet.

Try undefining MODBUS_SERIAL_OUTPUT and see what happens.
 

Offline PSR B1257Topic starter

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: de
Re: Arduino Nano Modbus energy meter SDM230
« Reply #4 on: January 26, 2022, 09:21:21 am »
Quote
Try undefining MODBUS_SERIAL_OUTPUT and see what happens.
Unfortunately nothing. I have changed these lines to comment and get the same on the serial monitor  ???

 
In theory, there is no difference between theory and practice. But, in practice, there is.
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3036
  • Country: us
Re: Arduino Nano Modbus energy meter SDM230
« Reply #5 on: January 26, 2022, 12:22:31 pm »
Unfortunately nothing. I have changed these lines to comment and get the same on the serial monitor  ???

What exact lines did you change?

A sure-fire way to disable the debugging output is to replace these lines in the library file:

Code: [Select]
#define MODBUS_SERIAL_OUTPUT  //Verbose MODBUS messages and timing

#ifdef MODBUS_SERIAL_OUTPUT
#define MODBUS_SERIAL_BEGIN(...) Serial.begin(__VA_ARGS__)
#define MODBUS_SERIAL_PRINT(...) Serial.print(__VA_ARGS__)
#define MODBUS_SERIAL_PRINTLN(...) Serial.println(__VA_ARGS__)
#else
#define MODBUS_SERIAL_BEGIN(...)
#define MODBUS_SERIAL_PRINT(...)
#define MODBUS_SERIAL_PRINTLN(...)
#endif

with:

Code: [Select]
#define MODBUS_SERIAL_BEGIN(...)
#define MODBUS_SERIAL_PRINT(...)
#define MODBUS_SERIAL_PRINTLN(...)

i.e. delete a bunch of lines
 

Offline PSR B1257Topic starter

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: de
Re: Arduino Nano Modbus energy meter SDM230
« Reply #6 on: January 26, 2022, 12:53:12 pm »
Quote
What exact lines did you change?
All lines you selected above.

Quote
with:

Code: [Select]

#define MODBUS_SERIAL_BEGIN(...)
#define MODBUS_SERIAL_PRINT(...)
#define MODBUS_SERIAL_PRINTLN(...)


i.e. delete a bunch of lines
Still no change.

But now I have at least some activity on TX pin.
In theory, there is no difference between theory and practice. But, in practice, there is.
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3036
  • Country: us
Re: Arduino Nano Modbus energy meter SDM230
« Reply #7 on: January 26, 2022, 02:11:53 pm »
What does your serial monitor look like?
 

Offline PSR B1257Topic starter

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: de
Re: Arduino Nano Modbus energy meter SDM230
« Reply #8 on: January 26, 2022, 04:13:17 pm »
Look's still kinda crazy...

In theory, there is no difference between theory and practice. But, in practice, there is.
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3036
  • Country: us
Re: Arduino Nano Modbus energy meter SDM230
« Reply #9 on: January 26, 2022, 06:15:03 pm »
Quote
The energy meter is connected via a RS458-TTL-converter.

Is it one of these converters? How are the DE and RE pins wired?

1392695-0
 

Offline PSR B1257Topic starter

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: de
Re: Arduino Nano Modbus energy meter SDM230
« Reply #10 on: January 27, 2022, 06:31:39 am »
That's the one.
DE and RE are shorted and connected to the TxEnablePin.


The unit is working. I have measured the RS458 port both with the energy meter connected and disconnected (to make sure the interface of the energy meter does not cause any funny business).

Later this day, I will try a different code and ditch this one - can't be worse. 
In theory, there is no difference between theory and practice. But, in practice, there is.
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3036
  • Country: us
Re: Arduino Nano Modbus energy meter SDM230
« Reply #11 on: January 27, 2022, 07:51:53 am »
You might look at this one:

https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino

It has an example which uses a software serial interface to the 485 module -- then you won't see the MODBUS packets on your terminal.
 

Offline fchk

  • Regular Contributor
  • *
  • Posts: 244
  • Country: de
Re: Arduino Nano Modbus energy meter SDM230
« Reply #12 on: January 27, 2022, 07:59:14 am »
That's the one.
DE and RE are shorted and connected to the TxEnablePin.


This board has a serious problem. You need three Terminals: RS485 A, RS485 B, and Ground. The Ground terminal is missing. You MUST connect Ground between the meter and the RS485 interface. Otherwise the common mode range might be exceeded.

For the future, just avoid this board and look for this one:



fchk
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3036
  • Country: us
Re: Arduino Nano Modbus energy meter SDM230
« Reply #13 on: January 27, 2022, 08:24:17 am »
@fchk, the image didn't come through.
 

Offline PSR B1257Topic starter

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: de
Re: Arduino Nano Modbus energy meter SDM230
« Reply #14 on: January 27, 2022, 08:36:56 am »
Quote
You need three Terminals: RS485 A, RS485 B, and Ground.
Is already connected  :-+

Quote
You might look at this one:
Yeah...well...did I mention, that I have basically no idea what I'm doing? Copying some code, try it it and hope for the best is my premise  :-DD
I can't even figure out, where to define the 'addresses of interest' (measurement values of the energy meter).
In theory, there is no difference between theory and practice. But, in practice, there is.
 

Offline PSR B1257Topic starter

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: de
Re: Arduino Nano Modbus energy meter SDM230
« Reply #15 on: January 27, 2022, 04:37:12 pm »
Found a much simpler (and promising) code: https://web-relays.com/en/blog/arduino-code-read-voltage-from-eastron-sdm230-modbus-smart-energy-meter-with-modbus-protocol/
But of course, it doesn't work on the Arduino Nano. It only generates one single data-package on the TX pin and does not run though the main loop...
It seems it's much depended of the "special Arduino board".
In theory, there is no difference between theory and practice. But, in practice, there is.
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3036
  • Country: us
Re: Arduino Nano Modbus energy meter SDM230
« Reply #16 on: January 27, 2022, 05:27:15 pm »
Did you change RS485_control to your TxEnablePin?

What do you mean it "doesn't run through the main loop"?

This is a pretty good explanation of how MODBUS messages are created:

https://ipc2u.com/articles/knowledge-base/modbus-rtu-made-simple-with-detailed-descriptions-and-examples/
 

Offline PSR B1257Topic starter

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: de
Re: Arduino Nano Modbus energy meter SDM230
« Reply #17 on: January 27, 2022, 06:02:29 pm »
Quote
Did you change RS485_control to your TxEnablePin?
Yes.

Quote
What do you mean it "doesn't run through the main loop"?
The whole code is only executed one time.
In theory, there is no difference between theory and practice. But, in practice, there is.
 

Offline PSR B1257Topic starter

  • Frequent Contributor
  • **
  • Posts: 330
  • Country: de
Re: Arduino Nano Modbus energy meter SDM230
« Reply #18 on: February 06, 2022, 06:19:41 pm »
The original code was just fine. Turns out, the RS485-converter was dodgy for crying out loud  :rant: A possibility which I should have been checking a bit earlier, duh  :palm:
In theory, there is no difference between theory and practice. But, in practice, there is.
 
The following users thanked this post: ledtester


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf