It is relatively easy to write software to read data from a Morningstar product that supports the MODBUS protocol. I have tested the software below with two SunSaver MPPT and a SureSine-300 using their MODBUS connections, a MeterHub, and a Meterbus to Serial Converter (MSC). The programming principles in the software below should also work with the SunSaver Duo, the TriStar PWM, the TriStar MPPT, and the Relay Driver.
Example Hardware Required:
- Morningstar SunSaver MPPT with Switch 4 ON (MODBUS Protocol)
- Morningstar Meterbus to Serial Converter (MSC)
- Computer running Linux or Mac OS X
- Serial port (either built-in or via USB-Serial adaptor)
Software Required:
- Software development environment: Linux – install build-essential (sudo apt install build-essential), Mac OS X – install X Code
- Modbus library for Linux and OSX – libmodbus (http://www.libmodbus.org/)
(on Debian-based Linux: sudo apt install libmodbus-dev pkg-config)
I have an off-grid solar power system with two Morningstar SunSaver MPPT, a Kyocera KD205GX-LP 205 watt photovoltaic (PV) panel, a Grape Solar GS-S-250-Fab5 250 watt PV panel, and a Morningstar SureSine-300 Inverter for AC loads. When I installed the system originally, I built a serial port-attached digital voltmeter to track the charge status of the batteries. This device was attached to a solar-powered Linksys NSLU2 running Debian Lenny. While this setup worked fine, the only information it could provide was the voltage of the batteries. I wanted to be able to also track the array voltage and charging current and the load voltage and current. The SunSaver MPPT provides this information via its MODBUS connection, so I bought a Morningstar Meterbus to Serial Converter (MSC) and started looking for examples of Linux software to communicate with the SunSaver MPPT. There is not much out there. The only information I could find was someone successfully using the MODBUS connection with Linux. At least it could be done. I also found libmodbus – a MODBUS library for Linux and Mac OS X. It compiles and works well on both my Mac and my Linux computers and has some example software that helped point me in the right direction. I also replaced my Linksys NSLU2 with a much faster Sheevaplug running Debian Squeeze. Currently, my system is using a Raspberry Pi 4 running the latest Raspberry Pi OS Lite (a variant of Debian).
Simple Software to Read Data from the SunSaver MPPT
/*
* sunsavertest.c
*
Copyright 2012 Tom Rinehart.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
/* Compile with: cc `pkg-config --cflags --libs libmodbus` sunsavertest.c -o sunsavertest */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <modbus.h>
#define SUNSAVERMPPT 0x01 /* Default address of the SunSaver MPPT */
int main(void)
{
modbus_t *ctx;
int rc;
float adc_vb_f,adc_va_f,adc_vl_f,adc_ic_f,adc_il_f;
uint16_t data[10];
/* Set up a new MODBUS context */
ctx = modbus_new_rtu("/dev/ttyUSB0", 9600, 'N', 8, 2);
if (ctx == NULL) {
fprintf(stderr, "Unable to create the libmodbus context\n");
return -1;
}
/* Set the slave id to the SunSaver MPPT MODBUS id */
modbus_set_slave(ctx, SUNSAVERMPPT);
/* Open the MODBUS connection to the SunSaver MPPT */
if (modbus_connect(ctx) == -1) {
fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
modbus_free(ctx);
return -1;
}
/* Read the first five RAM Registers */
rc = modbus_read_registers(ctx, 0x0008, 5, data);
if (rc == -1) {
fprintf(stderr, "%s\n", modbus_strerror(errno));
return -1;
}
/* Convert the results to their proper floating point values */
adc_vb_f=data[0]*100.0/32768.0;
printf("adc_vb_f=%.2f\n",adc_vb_f);
adc_va_f=data[1]*100.0/32768.0;
printf("adc_va_f=%.2f\n",adc_va_f);
adc_vl_f=data[2]*100.0/32768.0;
printf("adc_vl_f=%.2f\n",adc_vl_f);
adc_ic_f=data[3]*79.16/32768.0;
printf("adc_ic_f=%.2f\n",adc_ic_f);
adc_il_f=data[4]*79.16/32768.0;
printf("adc_il_f=%.2f\n",adc_il_f);
/* Close the MODBUS connection */
modbus_close(ctx);
modbus_free(ctx);
return(0);
}
Complete Examples of Accessing All of the RAM, EEPROM, and Log Registers in a Morningstar SunSaver MPPT
Building from the basic example above, these programs read and process all of the RAM, EEPROM, and Log Registers and print out the results.
Download The Code
https://github.com/westyd1982/morningstar-modbus/tree/main/sunsaver
A Complete Example of Accessing All of the RAM and EEPROM Registers in a Morningstar SureSine-300
This program reads and processes all of the RAM and EEPROM Log Registers and prints out the results.
Download The Code
https://github.com/westyd1982/morningstar-modbus/tree/main/suresine