I'm trying to read the data from a solar charge controller using an Arduino. The charge controller has a modbus interface, but for some reason it stops communicating with my Python script running on a Raspberry Pi periodically, making it useless.
I opened up its remote monitor box and found some UART pins, so I thought a good workaround would be to read the data directly from those pins if possible.
Attached is a picture of the remote monitoring box happily communicating with my charge controller, and of the UART pins I'm connecting to.
When I connect the TX pin from the remote monitoring box to the RX pin (pin 0) on my Arduino (and ground to ground) and run the following script, I get pulses of gibberish characters, which I believe is progress:
#include <SoftwareSerial.h>
// software serial : TX, RX
SoftwareSerial portOne(0, 1);
void setup()
{
// Start the hardware serial port
Serial.begin(9600);
// Start the software serial port
portOne.begin(9600);
}
void loop()
{
portOne.listen();
while (portOne.available() > 0) {
char inByte = portOne.read();
Serial.write(inByte);
}
}
But so far I haven't found a buad rate that turns that gibberish into anything that I can make sense of.
Does anyone have any tips?
And I'm new to UART, does it sound like I'm barking up the right tree? When I connect the RX pin of the box to the Arduino's TX pin, the box says "connecting", meaning (I think) that its trying to communicate exclusively over the UART pins. So I'm not completely sure that it's sending its data over the UART pins when there's no connection.
Incidentally the charge controller I'm trying to read the data from is an Epsolar 4210a. If anyone's interested, I've been writing about my issues connecting to it here:
Here's a stripped down version of my Python code. It works beautifully for awhile and then the controller will stop responding for hours, before seemingly randomly coming back. I haven't figured out any pattern.
#!/usr/bin/python
from pymodbus.client.sync import ModbusSerialClient as ModbusClient
import time
port = "/dev/ttyUSB0"
client = ModbusClient(method = 'rtu', port = port, baudrate = 115200)
client.connect()
while True:
# read 6 registers starting at 0x3000
result = client.read_input_registers(0x3000, 1, unit=1)
pvVolts = float(result.registers[0] / 100.0)
pvAmps = float(result.registers[1] / 100.0)
batteryVolts = float(result.registers[4] / 100.0)
batteryAmps = float(result.registers[5] / 100.0)
print "pvvolts=", pvVolts
print "pvamps=", pvAmps
print "batteryvolts=", batteryVolts
print "pvcurrent=", batteryAmps
print
time.sleep(1) # pause before reading the next register
# read the battery SOC
result = client.read_input_registers(0x311A, 1, unit=1)
batterySOC = result.registers[0]
print "batterySOC=", batterySOC
The odd thing is that the MT50 box always communicates just fine. And sometimes connecting that box for a moment will make it so my Python script works again, so I'm wondering if I'm missing something.
Sorry. I was not clear. I wanted to know what is the hardware connection - is it a serial connection or USB or something else?
From looking at the User Manual it seems to be RS485. You can get an RS485 - TTL serial converter and that may be the simplest way to connect the Arduino to it.