cole8888/SRNE-Solar-Charge-Controller-Monitor

1 Arduino only

Closed this issue · 75 comments

As a newbie, I would like to ask how to use only 1 arduino to read the battery voltage and the charging state status of the SRNE? How will I connect it to arduino? Thank you very much for your help.

Hi, sorry about not thinking about that, I'll make a schematic / code for a single arduino and charge controller.
Will you have access to an esp8266? I'm thinking i can get it to work with just one esp8266. That way you don't have to deal with the RF24 stuff.

Thank you very much for your response.. I do have an esp8266. I'll just wait for your update. God Bless You always.

You are also going to need a MAX3232 breakout board since the voltage level the charge controller uses to talk over rs232 isn't compatible with the Arduino and needs to be converted.

I found this on amazon and it should work.

I'm not sure where you are from but try searching for "MAX3232 breakout" and see if you can find something simmilar to that, feel free to send links to the ones you find and I can try to tell you if they will work.

If you can only find ones which look like this that's ok, you'll need to find a way to connect to the DB9 connector using something like this.

Also the charge controller uses a RJ12 (6P6C) jack for the modbus connector so you are going to need a cable like this which you will need to splice in half and strip the wires. This may look like a phone cable or Ethernet cable, but it isn't, it has 6 contacts.

I managed to get a ESP8266 to talk to the charge controller, will upload code, schematic and pictures shortly.

I do have one of this and I already have a RJ12 (6P6C). Thank you very much

Nice, that should work!

I uploaded some examples and much more detailed instructions, have a look at them here.

Also this particular example is the one you are interested in, just make sure you replace the MAX3232_RX and MAX3232_TX values to whatever pins you are using. (Most of that file is spent writing the data to the serial monitor so it isn't as scary as it looks at first.)

Let me know if you run into any problems :)

Thank you very much. I'm so excited to start my project. May God Bless You always.

I tried to the upload code on my esp8266 but there is an error ("'class Modbus' has no member named 'start'") on master.start(); I've already installed the modbus-esp8266 library.

I'm not using that modbus library, I used https://github.com/smarmengol/Modbus-Master-Slave-for-Arduino
There are instructions in that repoitory for how to install it, I don't think it is in the Arduino IDE.

thanks for the link of the library.. error has been solved.

Sad to say no luck for me.. I have already tried with arduino.
Untitled

Maybe I should purchase a different type of MAX3232 breakout board.

How do you have it wired up? You may have RX and TX backwards on either the arduino side or the charge controller side.
Please send a picture of the wiring you are using.

Here is how I wired up.
Untitled

On the arduino side the you have the VCC and GND reversed. Also I'm not sure what roles you have assigned to D2 and D3. For getting it started for the first time, can you stick to D1 and D2 since those are the only pins I tested.
image
Your RX and TX lines seem correct though.

I'm pretty sure D3 cannot be used for software serial according to some stuff I found online. Just use D1 and D2 for now since I know those work.

Thank you very much.

btw, can I apply this on arduino uno? What pins should I use? Thank you

Were you able to get it to work?

I have Arduino nano wiring examples here.
So, if you follow those examples use:
#define MAX3232_RX 2
#define MAX3232_TX 3

still no luck. I will just purchase other type of MAX3232 breakout.

Also which charge controller are you using?

I'm using SRNE ML2420

Yeah that should work, appears to be nearly identical to the ML2440 which is one of the ones I use and the manual says it supports modbus and the bluetooth module which means we should be able to talk to it since the bluetooth module is pretty much doing the same thing.

If you do get one of the ones with the DB9 connector (like the one I used) make sure you get a DB9 breakout adapter like this.

ok. thanks for the suggestion, I'll do get that one.

I know I maybe a little late on saying this. But to the serial board, I just found a USB cable for it. It is USB-A to RS232 Serial 6P6C on Amazon. I use a Raspberry PI for mine so USB works for me, and my work for others.

https://www.amazon.com/dp/B07JGRJR4V?psc=1&ref=ppx_yo2ov_dt_b_product_details

Good day, I would like to ask if my connections are correct.
try
and I changed the arduino code with this..
try2

Thank you very much

Your connections are correct, but for the code you need to have a D in front of the number, so use D1 and D2.

The colour of the wires you chose going from the 6P6C jack to the DB9 connector in your diagram aren't the actual colours right? 1 should be white, 2 should be black and 3 should be red. Maybe just compare your connector with mine to make sure our connectors are the same:
image

Here's mine..
www

changed the code
#define MAX3232_RX D1 // RX pin. If following my ESP8266 instructions use D1.
#define MAX3232_TX D2 // TX pin. If following my ESP8266 instructions use D2.

but there is an error:
'D1' was not declared in this scope

Interesting, seems like some ESP8266 do not support the D labels. Lets just use the pin numbers directly.

#define MAX3232_RX 5 // RX pin. If following my ESP8266 instructions use D1.
#define MAX3232_TX 4 // TX pin. If following my ESP8266 instructions use D2.

Here is your diagram with the colors from your cable.
204792605-950e4af8-6e9c-462c-abb8-7c00d7b9d247

Still no luck even with new arduino nano... I followed your given pictures..
#define MAX3232_RX 2
#define MAX3232_TX 3

How are you going from the RJ12/6P6C cable to the DB9 connector?

I know that when building mine I had some trouble making good contact at first. Could you check with a multimeter to see if you are getting continuity on those three lines by putting one end on the RJ12 contact and the other on the corresponding solder connection of the DB9 connector on the underside of the MAX3232 connector board?

Also I know sometimes I've had to reboot some of my charge controllers after they stop reporting data, but it's quite rare. Try disconnecting one cable from both the battery and the solar panels and leaving it for like 10 seconds then plugging it back in.

Also check all your other connections to see if they are loose or have intermittent contact. In my experience DuPont connectors are loose alot so investigate those especially.

Also do you have a link to the exact MAX3232 board you bought, I'm curious if the pinout might be different for some reason.

The MAX3232 board has the same pinout as mine and the breakout should eliminate contact issues.

For the ground (Green on RJ12) are you using the GND terminal block on the breakout connector? If so can you switch to using pin 5 instead? It looks like some of these breakouts don't actually connect that terminal to pin 5.

Also just to clarify BLUE->3, YELLOW->2, GREEN->5

I'm using pin 5 as ground on breakout connector. also blue to pin 3, yellow to pin 2 and green to 5. I will try reboot my charge controller

Error when trying to communicate with the charge controller. Here is my connections
IMG_20221206_112753_714

IMG_20221206_113757_887

RJ12 CONNECTIONS
RJ12 pin 1 to db9 pin 3
RJ12 pin 2 to db9 pin 2
RJ12 pin 3 to db9 pin 5

  • charge controller rebooted
  • all wire connections checked using multimer
  • Charge controller Rj12 pin has been tested using renogy Bluetooth module to check if the RJ12 pin of functioning properly

Your connections look good. Let's try changing the ESP8266 pins, maybe those pins are reserved on your variant?

Move your Blue one (D1) over to D5 and Purple one (D2) over to D6 and then change the code to

#define MAX3232_RX 14
#define MAX3232_TX 12

As a sanity check I just went and did a fresh clone of the repo, changed only those two lines and using this configuration I was able to get data from my ML2440.
So I'm not really sure what's going on here. My money is on the MAX3232 not working correctly since the capacitors on that thing look way smaller than the ones on mine.

PXL_20221206_040444458~2

Thank you.. I will replace my MAX3232 module

Hold on! I think I thought your connector was upside down, can you send another picture of your RJ12 jack?

One with the full connector please so I can see the wire colors through the clear plastic and see which way the wire exits the connector.

Like this:
image

Yeah it's the way I thought it was, darn. I'm going to try the wiring diagram the renogy guides use where RX and TX are flipped relative to what I'm doing.
image

That didn't work, even if I flipped the ones on the ESP8266 side. Seems like the way I have it is the only way it works. I wonder if the renogy ones use a different pinout.

I will try this
#define MAX3232_RX 14
#define MAX3232_TX 12

Good luck, I'm really sorry this is giving you so much trouble.

Thats always part of learning.

Good day, I've successfully read values from my charge controller and an ESP32 but using this code...
#define RXD2 16
#define TXD2 17

int num_data_registers = 30;
int num_info_registers = 17;

#include <ModbusMaster.h>
ModbusMaster node;

void setup()
{
Serial.begin(115200);
Serial.println("Started!");

// create a second serial interface for modbus
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2); // is SERIAL_8N1 correct?

int modbus_address = 255; // my Renogy Wanderer has an (slave) address of 255! Not in docs???
node.begin(modbus_address, Serial2);
}

void loop()
{
static uint32_t i;
uint8_t j, result;
uint16_t data_registers[num_data_registers];
uint16_t info_registers[num_info_registers];

i++;

// set word 0 of TX buffer to least-significant word of counter (bits 15..0)
node.setTransmitBuffer(0, lowWord(i));
// set word 1 of TX buffer to most-significant word of counter (bits 31..16)
node.setTransmitBuffer(1, highWord(i));

// Read the 30 data registers
result = node.readHoldingRegisters(0x100, num_data_registers);
if (result == node.ku8MBSuccess)
{
Serial.println("Successfully read the data registers!");
for (j = 0; j < num_data_registers; j++)
{
data_registers[j] = node.getResponseBuffer(j);
Serial.println(data_registers[j]);
}
Serial.println("---");
}
else {
Serial.print("Failed to read the data registers... ");
Serial.println(result, HEX); // E2 is timeout
}

// Read the 17 info registers
result = node.readHoldingRegisters(0x00A, num_info_registers);
if (result == node.ku8MBSuccess)
{
Serial.println("Successfully read the info registers!");
for (j = 0; j < num_info_registers; j++)
{
info_registers[j] = node.getResponseBuffer(j);
Serial.println(info_registers[j]);
}
Serial.println("---");
Serial.println();
}
else {
Serial.print("Failed to read the info registers... ");
Serial.println(result, HEX); // E2 is timeout
}
delay(1000);
}

Can I ask your help how to modify this code to read only the battery voltage and the charging state status? Thank you & God Bless

Awesome!
This is very interesting, can you tell me what modbus library you are using, also can you send a copy of the data you are receiving from the charge controller?
I do not have an ESP32 on hand so I won't be able to test it.
The modbus slave address is different than it is for all of my charge controllers, which is interesting. This could explain why you were not able to talk to it with my code.

Also if you could send a picture of the charge controller display so I know which charging mode and voltage it has at the moment that would be helpful.

Library used is https://github.com/syvic/ModbusMaster.
Here is my serial output..
qq
and the charge controller display..
IMG_20221208_130952_838

Hey can you include the data registers too? That's where the information you want is.

Sorry, cant understand what data register is, I just copied the code from here https://forum.arduino.cc/t/trying-to-read-registers-from-a-solar-charge-controller-over-rs232-solved/1039864/11 and upload it to esp32

In the console output that script prints out two sets of data, one of them is called info registers and one is data registers. The data registers are the ones we want. There should be a header with the text "Successfully read the data registers!" printed above them.
Also could you send a picture of how you wired up the the ESP32? I'm trying to see if changing the modbus address will make my code work.

console output for first set..
hhh

I just followed this..
6af2468ee0561ca003c88879786ce155a797a8ea

Their TX and RX in the diagram seem to be opposite to mine so I just wanted to see how you physically hooked it up so I could assign the correct pin numbers in my code for you to try out.

An updated picture like this would be awesome: #10 (comment)

This data seems to be in the exact same format as what my program is expecting.

In the program we were working with previously can you try these settings?

#define MAX3232_RX 17
#define MAX3232_TX 16

and
#define MODBUS_SLAVE_ADDR 255
(got it backwards, see later message)

Shoot I got it backwards 😛, try:

#define MAX3232_RX 16
#define MAX3232_TX 17

instead please.

using an esp32 there is an error SoftwareSerial.h: No such file or directory

damnit, looks like that's going to be a problem, lets not use the ESP32 for now.

Could you pull out your ESP8266 and wire it up like we had it before?
D1 -> MAX3232 RX pin
D2 -> MAX3232 TX pin
VCC and ground like before.

Then use

#define MAX3232_RX 5
#define MAX3232_TX 4

Also make sure to change this line:
#define MODBUS_SLAVE_ADDR 255

Damnit, I'll jerry rig something quick which should let you access the information on your ESP32, just give me a minute.

WAIT, you have D1 and D2 cables backwards!

Green should be D1, purple D2

green to D!, purple to D2 is still no luck.. and with this connection the COM icon in charge controller does not appear but if purple to D1 and green to D2 the COM icon in charge controller appears but still no luck..

That is bizarre. If the COM icon appears it is making a connection though.
It's too late for me to keep going but let me know if this displays the stuff you want. Tomorrow I can try and get the rest of the information out of it.
I couldn't compile this because I don't know what ESP32 you are using and I kept getting library issues so let me know if there is a problem.
solar.zip

ok.. Thank you

I've dug into it a bit more and I'm pretty sure I found what is causing the problem.

The reason address 255 is working for you on that one program is because that is a special address which all controllers will respond to regardless of what their actual address is. For some reason your charge controller has an address that is not 1 unlike every other controller I've seen so far.
The library in that example you provided accepts address 255 and I am able to get my controllers to respond, but using the modbus library I chose for my program it seems to not accept address 255.

I dug into the source code of the library and sure enough:
image
image
By manually changing both of those from 247 to 255 and restarting the Arduino IDE then re-uploading to the esp8266 I was able to get address 255 working on my program.

If you don't mind, in your Arduino libraries folder can you swap the library source code file (Modbus-Master-Slave-for-Arduino -> ModbusRtu.h) with this one https://github.com/cole8888/SRNE-Solar-Charge-Controller-Monitor/blob/test-address-fix/Arduino-Version/Single-Charge-Controller/ModbusRtu.h, then wire up your esp8266 and program it with this:
https://github.com/cole8888/SRNE-Solar-Charge-Controller-Monitor/blob/test-address-fix/Arduino-Version/Single-Charge-Controller/SOLAR_SINGLE_CC/SOLAR_SINGLE_CC.ino (I indicated which connections to make in the comments).

Thank you very much! I've already got it! God Bless & Merry Christmas!

Hello, I have a srne 2420 and I have messed up the internal software by mistake with an app. Could someone tell me how to put the original software back??