GithubHelp home page GithubHelp logo

wrybread / esp32arduinorenogy Goto Github PK

View Code? Open in Web Editor NEW
26.0 3.0 7.0 669 KB

Reads data from a Renogy solar charge controller's RS232 port with an ESP32 or Arduino

License: MIT License

C++ 100.00%
arduino esp32 modbus renogy solar esp8266

esp32arduinorenogy's Introduction

ESP32ArduinoRenogy

This lets you read data from Renogy charge controllers via their RS232 port using an ESP32 or Arduino.

Wanderer

The inspiration came when I needed to power a pump at a remote pond whenever there was sufficient power from a solar panel, and I was surprised to learn that the load switch on the Renogy controllers can't do that natively. The load switch is only designed to control lights at night. Silly. This lets me use the load switch to power whatever I want, but see the "Notes on the Load Switch" below for some notes on its limitations. And of course it lets me do whatever else I want with the data from the Renogy charge controller including using a relay, and gives me a dirt cheap way to read the battery voltage, panel voltage and load wattage from an ESP32 or Arduino.

So far I've only tested this with Renogy Wanderer 30A (CTRL-WND30-LI) and Wanderer 10A charge controllers, please post to the Issues section if you test on more and I'll add it to the list below. It should work with any Renogy charge controller that has an RS232 port, which I think is all of them since they want to sell their bluetooth module that works with the RS232 port.

Here's a pic of my installation:

installation

Making the Cable

Here's an overall wiring diagram:

wiring diagram

You'll need make a cable to connect the controller to your ESP32 or Arduino. Start with an RJ12 cable, which is an old phone cable with 6 wires. Make sure it doesn't have only 4 wires, which is an RJ11 cable.

Here's the RJ12 jack on my cable, note how there's 6 wires (white, black, red, green, yellow, blue):

rj12 cable jack

I don't know how standard the wire colors are but those are the colors on mine. You need the first 3 wires from the left, which on mine are the white, black and red wire.

You'll also need a TTL to RS232 level adjuster. I used this one but there are lots of other options (google "max3232"):

level adjuster

If the listing goes away, it's the "NOYITO TTL to RS232 Module TTL RS232 Mutual Conversion Module", costs $7. See the wiring diagram above for instructions on connecting to it.

Use

After connecting the cable and flashing your ESP or Arduino you should be seeing data from your charge controller in Serial Monitor:

serial monitor

Feel free to post to Issues if not.

Notes on the Code

There's a struct that holds all the data from the charge controller. A look at the struct shows what data that is:

struct Controller_data {
  
  uint8_t battery_soc;               // percent
  float battery_voltage;             // volts
  float battery_charging_amps;       // amps
  uint8_t battery_temperature;       // celcius
  uint8_t controller_temperature;    // celcius
  float load_voltage;                // volts
  float load_amps;                   // amps
  uint8_t load_watts;                // watts
  float solar_panel_voltage;         // volts
  float solar_panel_amps;            // amps
  uint8_t solar_panel_watts;         // watts
  float min_battery_voltage_today;   // volts
  float max_battery_voltage_today;   // volts
  float max_charging_amps_today;     // amps
  float max_discharging_amps_today;  // amps
  uint8_t max_charge_watts_today;    // watts
  uint8_t max_discharge_watts_today; // watts
  uint8_t charge_amphours_today;     // amp hours
  uint8_t discharge_amphours_today;  // amp hours
  uint8_t charge_watthours_today;    // watt hours
  uint8_t discharge_watthours_today; // watt hours
  uint8_t controller_uptime_days;    // days
  uint8_t total_battery_overcharges; // count
  uint8_t total_battery_fullcharges; // count

  // convenience values
  float battery_temperatureF;        // fahrenheit
  float controller_temperatureF;     // fahrenheit
  float battery_charging_watts;      // watts. necessary? Does it ever differ from solar_panel_watts?
  long last_update_time;             // millis() of last update time
};
Controller_data renogy_data;

For example there's battery_soc (battery state of charge), the battery_voltage, the battery_charging_amps, etc. There's examples in the code of how to access them, but for example you get the battery voltage like this:

Serial.println( renogy_data.battery_voltage );

There's another struct that holds the info about the charge controller (it's voltage rating, amp rating, serial number, etc). I don't think all those are working yet. For example the serial number it reports is different than the one printed on my charge controller, which I think is just because of how my code processes the serial number data, but I don't need that functionality so I haven't fixed that yet.

And note the commented out section in the code that turns the load switch on and off. For example this would turn the load on for 10 seconds:

renogy_control_load(1)
delay(10000);
renogy_control_load(0)

Notes on the Load Switch

I think the load switch uses a MOSFET, which means anything with an inductive kickback (like a brush motor) might damage the switch or the unit itself. But I've been powering a bilge pump on it, which I think is an inductive load, for months without an issue. I'm willing to risk my cheapie PWM charge controller for that, but be careful what you power from the load switch directly. And of course you can connect a relay to the load switch to control anything else, or just connect a relay directly to your Arduino or ESP32.

Renogy is oddly uncommunicative about the limits of the load switch, and my theory is that that's because it's a bit complicated. My theory is that the capacity is shared between the battery input and the switch output. So for example if the 10 amp charge controller is pulling 8 amps of power from the solar panels, that leaves only 2 amps for the load switch. That would explain both why they don't mention the actual load limit, and why they only let us control the load at night (when the solar panels aren't competing for the capacity). But still, if that's the case, it would be nice for Renogy to mention that. And furthermore having options to control the load switch in the day would allow for someone to either have a larger controller than their panel so daytime power wouldn't be an issue, or to just use a relay connected to the load switch. Furthermore the manual says the controller will shut off the load switch and show an error code if the capacity reaches 105%, so maybe exceeding the load limit by a bit isn't catastrophic.

Anyway you can of course bypass all these issues by just controlling a relay directly from your ESP or Arduino.

For the record here's a screenshot from the Renogy Wanderer 10a manual showing the modes of the load switch:

load modes

Such an odd limitation to design them only to handle lights. Oh well, nothing an ESP32 or Arduino can't fix.

General Notes

  • as of now this is untested on an Arduino, I've only used it with ESP32's (both a Rover and a Wroom). It should work fine with an Arduino, the only thing I'm uncertain about is whether you can have two Serial interfaces with all Arduinos (and this script uses one Serial interface for communication with the Renogy controller and one to print status to the console). It should work fine though. If you test with an Arduino please post to this project's Issues section.

  • I couldn't power the ESP32 directly from the charge controller, my theory is that it's so low power that the charge controller thinks nothing is connected and shuts off the USB port. Oh well, I used one of these 12v to 5v adaptors:

12v to 5v

See Also

There's a couple of other projects that get data from the Renogy charge controllers. Oddly I couldn't find anything that uses an ESP32 or Arduino though.

Much thanks to them! They made this much easier.

Those are all for Raspberry Pi's or similar though. For my use case a Raspberry Pi is vastly overkill and has a lot of drawbacks: it needs to be shutdown properly, has a corruptible SD card, uses about 10 times the power of an Arduino or ESP (and an ESP32 can use deep sleep mode, which uses almost no power at all), has a super slow bootup time as opposed to instantly on, has an OS which needs to be kept up to date and is subject to lock ups, etc. ESP32's are in general much more robust in my experience. Once you get it working it just works, I'm betting for decades. That's not to say there aren't times where a Pi or similar makes more sense of course, but a remote solar installation probably isn't one of them.

I also attached Renogy's RS232/modbus manual, it's somewhat occaisonally helpful if you squint at it long enough.

Tested On

So far it's been tested and confirmed working well on these controllers:

  • Wanderer 30A (CTRL-WND30-LI)
  • Wanderer 10A

It should work on any Renogy charge controller with an RS232 port. And most if not all of them have that port since Renogy wants to sell their bluetooth module, which uses that port to get its data. This should also be pretty easy to adapt to other charge controllers that make their data available via modbus.

Please post to the Issues section if you test on other Renogy charge controllers, or email me ([email protected]).

To Do

  • I don't think it's correctly reading the serial number register, and possibly some of the other registers having to do with the model number. Please let me know if you figure out any fixes. ([email protected] or post to Issues).

  • would be nice to add Bluetooth support for monitoring from a phone, posting to MQTT brokers and pvwatts, etc.

esp32arduinorenogy's People

Contributors

wrybread avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

esp32arduinorenogy's Issues

Works on Arduino MKR1010

I used your info to successfully connect an Arduino MKR1010 to a Renogy Wanderer 10A (model # RNG-CTRL-WND10) charge controller. The MKR1010 natively has Serial1 on pins 13 (RX) and 14 (TX).

In the renogy_rs232.ino program:
Not required:
#define RXD2 13
#define TXD2 14

Substitute:
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
node.begin(modbus_address, Serial2);

with:
Serial1.begin(9600); //On mkr1010, pins 13 (RX) & 14 (TX) are Serial1
node.begin(modbus_address, Serial1);

Additional comments:
• The RJ12 cable I purchased on Amazon has a wire color sequence opposite of yours – pin 1 is blue. As you allude to, it’s the pins and not the wire colors that are important.
• The NOYITO TTL-to-RS232 level adjuster is excellent. I was using Sparkfun RS232 shifters with no success.
• As you mention, the “info” registers don’t have relatable information, except for amp_rating=10, which is correct for a 10A controller.
• The multiplier for battery_charging_amps = data_registers[2] is .01, not .1. (Page 9 of the Rover 20A/40A Charge Controller—MODBUS Protocol documentation.)
• The internal temperature sensor is for the controller itself, and not ambient temperature. Expect it to change as the controller receives electricity from the panel. The Wanderer 10A does not have remote battery temperature sensor capabilities, therefore, battery_temperature usage can be commented out.
• The controller’s uptime counter seems inaccurate as my controller has been connected to a new battery for three weeks, yet the controller’s uptime is three days. In addition, because it doesn’t have a method to set the date and time, a new day doesn’t begin at 12:00am. It is possible the firmware estimates 12:00am based on solar day length. Other counters based on a day also are questionable.
• One reason I only use the MKR1010 (vs other Adriano boards) is that it has web server (and client) capabilities. My sketch publishes a simple webpage with the Renogy controller’s info.

Thank you for publishing the detailed information on GitHub! I was struggling with the many variables involved – pinouts, pin functions, RS232, Modbus, C++ - but your information got me on track.

image

Renogy Wanderer 10A Load Amps

Hi,
I read different stories about the load amps via Modbus. Some mention it is not possible to get it for the Wanderer 10A but in your library you mention it.
Could you please confirm if you can get non-zero values for load amps from the Wanderer 10A and if yes could you please send the model number for comparison?
Thanks a lot
Markus

possible to use USB vs. serial?

i'm working on setting up an ntp server using a gps hat that using the serial port.
Im hoping to leverage a usb port to connect to the rs232 port.
have you tried doing this and will you library work with USB port?

thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.