Arduino Nano Modbus energy meter SDM230 - Page 1
Forum section: electronics / general

author: PSR B1257
author_rank: Frequent Contributor
timestamp: January 25, 2022, 06:26:38 pm
content: 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-ArduinoThe 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 &Serial1to#define MB_SERIAL_PORT &Serialsince 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

author: fchk
author_rank: Frequent Contributor
timestamp: January 25, 2022, 07:45:27 pm
content: 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

author: PSR B1257
author_rank: Frequent Contributor
timestamp: January 25, 2022, 08:15:43 pm
content: QuoteNo, but with my DSOThe only activity is on the 'TxEnablePin'.

author: ledtester
author_rank: Super Contributor
timestamp: January 26, 2022, 05:13:21 am
content: Have a look at these lines in the Arduino library:Code:#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(...)#endifThe 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.

author: PSR B1257
author_rank: Frequent Contributor
timestamp: January 26, 2022, 09:21:21 am
content: QuoteUnfortunately nothing. I have changed these lines to comment and get the same on the serial monitor

author: ledtester
author_rank: Super Contributor
timestamp: January 26, 2022, 12:22:31 pm
content: Quote from: PSR B1257 on January 26, 2022, 09:21:21 amWhat exact lines did you change?A sure-fire way to disable the debugging output is to replace these lines in the library file:Code:#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(...)#endifwith:Code:#define MODBUS_SERIAL_BEGIN(...)#define MODBUS_SERIAL_PRINT(...)#define MODBUS_SERIAL_PRINTLN(...)i.e. delete a bunch of lines

author: PSR B1257
author_rank: Frequent Contributor
timestamp: January 26, 2022, 12:53:12 pm
content: QuoteAll lines you selected above.QuoteStill no change.But now I have at least some activity on TX pin.

author: ledtester
author_rank: Super Contributor
timestamp: January 26, 2022, 02:11:53 pm
content: What does your serial monitor look like?

author: PSR B1257
author_rank: Frequent Contributor
timestamp: January 26, 2022, 04:13:17 pm
content: Look's still kinda crazy...

author: ledtester
author_rank: Super Contributor
timestamp: January 26, 2022, 06:15:03 pm
content: QuoteIs it one of these converters? How are the DE and RE pins wired?

author: PSR B1257
author_rank: Frequent Contributor
timestamp: January 27, 2022, 06:31:39 am
content: 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.

author: ledtester
author_rank: Super Contributor
timestamp: January 27, 2022, 07:51:53 am
content: You might look at this one:https://github.com/smarmengol/Modbus-Master-Slave-for-ArduinoIt has an example which uses a software serial interface to the 485 module -- then you won't see the MODBUS packets on your terminal.

author: fchk
author_rank: Frequent Contributor
timestamp: January 27, 2022, 07:59:14 am
content: Quote from: PSR B1257 on January 27, 2022, 06:31:39 amThis 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

author: ledtester
author_rank: Super Contributor
timestamp: January 27, 2022, 08:24:17 am
content: @fchk, the image didn't come through.

author: PSR B1257
author_rank: Frequent Contributor
timestamp: January 27, 2022, 08:36:56 am
content: QuoteIs already connectedQuoteYeah...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 premiseI can't even figure out, where to define the 'addresses of interest' (measurement values of the energy meter).

author: PSR B1257
author_rank: Frequent Contributor
timestamp: January 27, 2022, 04:37:12 pm
content: 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".

author: ledtester
author_rank: Super Contributor
timestamp: January 27, 2022, 05:27:15 pm
content: 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/

author: PSR B1257
author_rank: Frequent Contributor
timestamp: January 27, 2022, 06:02:29 pm
content: QuoteYes.QuoteThe whole code is only executed one time.

author: PSR B1257
author_rank: Frequent Contributor
timestamp: February 06, 2022, 06:19:41 pm
content: The original code was just fine. Turns out, the RS485-converter was dodgy for crying out loudA possibility which I should have been checking a bit earlier, duh